Home AMX User Forum NetLinx Studio

I need to remove characters from answer of device

My problem is, sometimes what I need is in the start of the answer .... sometimes in the end.

Like that:

NB07□□ID01,F02,ST0001111□ID02,F02,ST0000000□ID05,F02,ST1110110□

The size of the answers are variable, so I need to identify the start with ID02 and put in a variable the complete feedback.

Example: VARIABLE = ID02,F02,ST0000000

I don't know what instruction I hace to use in this case.

Thanks!

Comments

  • TrikinCurtTrikinCurt Posts: 158
    2Fast wrote: »
    My problem is, sometimes what I need is in the start of the answer .... sometimes in the end.

    Like that:

    NB07□□ID01,F02,ST0001111□ID02,F02,ST0000000□ID05,F02,ST1110110□

    The size of the answers are variable, so I need to identify the start with ID02 and put in a variable the complete feedback.

    Example: VARIABLE = ID02,F02,ST0000000

    I don't know what instruction I hace to use in this case.

    Thanks!

    I imagine that □ is a return character? If so, you would probably need to nest a loop, pull off everything line by line
    myCmd = remove_string(thatstring,13,1) // assuming it is a carriage return?
    

    Then parse out myCmd
    myWhatever = remove_string(myCmd,',',1) 
    

    Obviously this would be in loops, you would have ID02 in one pass, F02 in the next, etc...
  • AMXJeffAMXJeff Posts: 450
    2Fast wrote: »
    My problem is, sometimes what I need is in the start of the answer .... sometimes in the end.

    Like that:

    NB07□□ID01,F02,ST0001111□ID02,F02,ST0000000□ID05,F02,ST1110110□

    The size of the answers are variable, so I need to identify the start with ID02 and put in a variable the complete feedback.

    Example: VARIABLE = ID02,F02,ST0000000

    I don't know what instruction I hace to use in this case.

    Thanks!

    2Fast,

    I know we have seen this string already in the forum, it may have been from you. The key to parsing this message is finding the delimiter or the "TAIL" of the message. I can only assume what the little "□" none-printable character is for this message. But it seems that is the delimiter or "TAIL" of each of these sections. For the code example I will assume that the none-printable character is a Carriage Return / $0D.
    DEFINE_VARIABLE
    
    CHAR TAIL[] = {$0D};
    
    DEFINE_EVENT
    
    DATA_EVENT[dvDevice]
    {
    	STRING:
    	{
    		WHILE (FIND_STRING(cBuffer,"TAIL",1))
    		{
    			cMsg = REMOVE_STRING(cBuffer,"TAIL",1);
    		
    			// Remove the Tail
    			SET_LENGTH_STRING(cMsg, LENGTH_STRING(cMsg) - 1);
    			
    			IF (FIND_STRING(cMsg,'ID',1))
    			{
    				// YOU SHOULD HAVE A COMPLETE ID MESSAGE HERE	
    				cANSWER = cMsg;
    			}
    		}	
    	}
    }
    
    
    
  • 2Fast2Fast Posts: 90
    Thanks guys. Now I think I understand ... Sorry for asking about it again!
  • 2Fast2Fast Posts: 90
    Hmm I'm here again :(

    I don't need only one feedback, I need to divide in answers from specific devices in the "network" and I really don't know how....

    feedback1=ID01,F02,ST1110016
    feedback2=ID02,F02,ST0110013
    feedback3=ID03,F02,ST0100014

    If the size of the answer was the same every time I would read for positions ...

    With theses examples I'm not understanting :(
  • jjamesjjames Posts: 2,908
    What device is this? Where can we find the protocol?
  • AMXJeffAMXJeff Posts: 450
    2Fast wrote: »
    Hmm I'm here again :(

    I don't need only one feedback, I need to divide in answers from specific devices in the "network" and I really don't know how....

    feedback1=ID01,F02,ST1110016
    feedback2=ID02,F02,ST0110013
    feedback3=ID03,F02,ST0100014

    If the size of the answer was the same every time I would read for positions ...

    With theses examples I'm not understanting :(
    DEFINE_VARIABLE
    
    CHAR TAIL[] = {$0D};
    
    CHAR cAnswer[100][25];
    
    DEFINE_EVENT
    
    DATA_EVENT[dvDevice]
    {
    	STRING:
    	{
    		STACK_VAR INTEGER nCurrentID;
    		
    		WHILE (FIND_STRING(cBuffer,"TAIL",1))
    		{
    			cMsg = REMOVE_STRING(cBuffer,"TAIL",1);
    		
    			// Remove the Tail
    			SET_LENGTH_STRING(cMsg, LENGTH_STRING(cMsg) - 1)
    			
    			IF (FIND_STRING(cMsg,'ID',1))
    			{
    				//ATOI Gets the '01' from the ID01,F02,ST1110016
    				nCurrentID = ATOI(cMsg);
    				
    				IF (nCurrentID <= MAX_LENGTH_ARRAY(cANSWER) && nCurrentID)
    				{
    					// YOU SHOULD HAVE A COMPLETE ID MESSAGE HERE	
    					cANSWER[nCurrentID] = cMsg;
    				}	
    			}
    		}	
    	}
    }
    
  • jjamesjjames Posts: 2,908
    Jeff - where is cBuffer?
  • AMXJeffAMXJeff Posts: 450
    jjames wrote: »
    Jeff - where is cBuffer?

    I did not provide ALL the code!!!!!!! I am hoping people know how to create a buffer and declare a buffer!!!!!
  • jjamesjjames Posts: 2,908
    AMXJeff wrote: »
    I am hoping people know how to create a buffer and declare a buffer!!!!!
    I sure hope so too.

    I just thought you wouldn't remove the stuff you're referencing - maybe that's just me.

    And please apologize - my ears hurt now. :p
  • 2Fast2Fast Posts: 90
    I know how to create a buffer, sorry for my questions ... I will not disturb again with my dumb questions.

    Sorry again and thanks
  • jjamesjjames Posts: 2,908
    2Fast wrote: »
    I know how to create a buffer, sorry for my questions ... I will not disturb again with my dumb questions.

    Sorry again and thanks

    No no - not dumb. No question is dumb and you're not disturbing us.

    As far as the buffer thing goes - I was just joking with Jeff and was actually curious whether or not it was supposed to be used in the CREATE_BUFFER or some other technique such as a LOCAL_VAR in the data event and populating it from the DATA.TEXT, etc. etc.

    I'll just assume it's done via CREATE_BUFFER.
  • AMXJeffAMXJeff Posts: 450
    jjames wrote: »
    No no - not dumb. No question is dumb and you're not disturbing us.

    James is right...
  • 2Fast2Fast Posts: 90
    :D

    Thanks!
Sign In or Register to comment.