Home AMX Forum AMXForums Archive Threads AMX Hardware AutoPatch Forum
Options

Parsing an Autopatch Response String?

I have the need to parse the string response from an Autopatch Matrix. My problem is that I am having a difficult time with the nature of how to run my string searches, since the outputs can be multiple, whereas the input is single. Here is what I have:
DATA_EVENT[dvAUTOPATCH]
{
	
	STRING:
	{
		
		LOCAL_VAR CHAR cInputRx[16]
		LOCAL_VAR CHAR cOutputRx[16]
		IF (FIND_STRING(DATA.TEXT,'T',1))  //If the T is found, a response was sent.
		{
			cInputRx = REMOVE_STRING(DATA.TEXT,'O',1)  //remove everything up to & icluding O
			cInputRx = REMOVE_STRING(cInputRx,'I',1)  //remove all but the input # and the O, which are at the end
			cInputRx = REMOVE_STRING(cInputRx, 'O',2)  //remove the O, leave the input #
			
			cOutputRx = LEFT_STRING(DATA.TEXT,(LENGTH_ARRAY(DATA.TEXT)))
			
			SEND_COMMAND dvTP,"'^TXT-59,0,Input ,',cInputRx,',to Output(s),',cOutputRx"
		}
	}
}
I was thinking about a FOR loop to populate an Array where each position in the array is an output position:
for(i=1;i<(LENGTH_ARRAY(cOutputRx));i++)
		{
			nOutputArray[i] = //I'm not sure where to go from here
		}
help. please. it's almost friday...somewhere.

Comments

  • vegastechvegastech Junior Member
    I ended up changing a few names around, but I found that my string arguments are my friends...although it would be nice if I could clean it up a bit!
    DATA_EVENT[dvAUTOPATCH]
    {
    	ONLINE:
    	{
    	//set to 
    	}
    	STRING:
    	{
    		
    		LOCAL_VAR CHAR cTemp[22]
    		LOCAL_VAR CHAR cInput[16]
    		LOCAL_VAR CHAR cOutput[16]
    		LOCAL_VAR CHAR cSwitcherString[22]
    		cSwitcherString = DATA.TEXT
    		IF (FIND_STRING(cSwitcherString,'T',1))
    		{
    			
    			cTemp = REMOVE_STRING(cSwitcherString,'I',1)  //remove all but the input # and the O
    			cInput = LEFT_STRING(cSwitcherString,1) 
    			cTemp = REMOVE_STRING(cSwitcherString,'O',1)
    			//send the cSwitcherString to the panel
    			cOutput = LEFT_STRING(cSwitcherString,1)
    			//cOutput = LEFT_STRING(cSwitcherString,(LENGTH_ARRAY(cSwitcherString)))
    			
    			
    			SEND_COMMAND dvTP,"'^TXT-59,0,Input ',cInput,' to Output ',cOutput"
    		}
    
    	}
    }
    
  • jjamesjjames AMX Sustaining Engineer
    String arguments are your friend indeed! String manipulation is probably one of my favorite things to do. (Smiling is also my favorite . . . ok - j/k)

    Let's say the incoming string is CL2I3O5T, in theory (I just woke up because I couldn't sleep, so my brain is a bit fuzzy . . . and this completely untested) this could be accomplished in just a few commands.

    I prefer to chip away at strings and avoid using LEFT, RIGHT and MID_STRINGS as they leave the original string intact, and it's just not as flexible since you're telling it to looking for only 'X' number of characters - I prefer that to instead look for things that are always present - in this case and 'I' and an 'O'. Let's pretend you have an 8x8 - your code would work fine. However, if you had an 18x18 - Autopatch does not return padded values (i.e. 01), so using LEFT/RIGHT/MID_STRING the way you have on an input value of 12 would return a '1' - definitely not what you're looking for.

    There's no rule or anything that says you can't use string functions within string functions, and if fact I find it quite helpful. For instance if you want to remove just one word or group of words, you could do this:
    // cXML = <somewhere><something>hello!</something><somewhere>
    // cNODE = 'something'
    cXML_TEMP = 
    	REMOVE_STRING(cXML,"'</',cNODE,'>'",FIND_STRING(cXML,"'<',cNODE,'>'",1))
    // cXML_TEMP = <something>hello!</something>
    


    Removing portions of the string is helpful in getting where you need to go. Here's what I'd do with a returning string (which is "CL2I3O5T") from the Autopatch.
    STRING:
    {
    	// FIND END OF ROUTE DATA
    	IF (FIND_STRING(DATA.TEXT,'T',1)) // T = TAKE
    	{
    		STACK_VAR INTEGER nLEVEL;
    		STACK_VAR INTEGER nINPUT;
    		STACK_VAR INTEGER nOUTPUT;
    		STACK_VAR CHAR    cBUFFER[12]
    		
    		// Remove string grabs data ENDING IN "T" starting at the position of "C"
    		// I've never tried this before, and it's all theory, but I'd assume this would
    		// ensure the first and full & proper string you are looking for in DATA.TEXT is grabbed
    		cBUFFER = REMOVE_STRING(DATA.TEXT,'T',FIND_STRING(DATA.TEXT,'C',1));
    		
    		// cBUFFER = CL2I3O5T
    		REMOVE_STRING(cBUFFER,'CL',1);
    		
    		// cBUFFER = 2I3O5T
    		// Removed portion will be '2I', so ATOI will grab the 2
    		nLEVEL = ATOI(REMOVE_STRING(cBUFFER,'I',1));
    		
    		// cBUFFER = 3O5T
    		// Removed portion will be '3O', so ATOI will grab the 3
    		nINPUT = ATOI(REMOVE_STRING(cBUFFER,'O',1));
    		
    		// cBUFFER = 5T
    		// ATOI will grab the 5
    		nOUTPUT= ATOI(cBUFFER);
    
    		// Do whatever you want with your values now.
    }		
    
    Hope this helps! And if I'm totally wrong - it'd be nice if someone showed me where I am in error . . . okay - back to bed!
  • kbeattyAMXkbeattyAMX Junior Member
    I think part of your question is how to store and use the information you've gathered. Create a 2 dimensional array, APswitcher[level][output]. Now that you have the LEVEL and OUTPUT, assign the current INPUT to it. APswitcher[level][output] = input. Now you can feedback something like this...

    [dvTP,Video_inputBTN1] = (APswitcher[1][currOUTputBTN] = 1)

    So now if you press an output button, the input button will light up according to what is actually at that output.
  • vegastechvegastech Junior Member
    Both replies are great - thanks! But what about the additional outputs portion of the string? Each output after the first one returns the output number followed by a space - would I continue with remove_string and look for the $20(space), and continue on my way?
    //Example: Input 1 to Outputs 1,3,5,7
    CL1I6O1 2 3 4 5 6 7 8T
    
    The outputs will constantly change...I suppose remove_string could continue to work as long as it finds a space, but how to I search for a space?
    Thanks.
  • jjamesjjames AMX Sustaining Engineer
    How about using AMX's SPLIT_STRING function (technote 662)?

    Also, i changed nINPUT to cINPUT.
    STACK_VAR CHAR    cLEVEL[2];
    STACK_VAR CHAR    cINPUT[2];
    STACK_VAR CHAR    cOUTPUT[18][2];	// Maximum number of outputs
    STACK_VAR CHAR    cBUFFER[12]
    
    // Remove string grabs data ENDING IN "T" starting at the position of "C"
    // I've never tried this before, and it's all theory, but I'd assume this would
    // ensure the first and full & proper string you are looking for in DATA.TEXT is grabbed
    cBUFFER = REMOVE_STRING(DATA.TEXT,'T',FIND_STRING(DATA.TEXT,'C',1));
    
    // cBUFFER = CL2I3O5 6 7 8 9T
    REMOVE_STRING(cBUFFER,'CL',1);
    
    // cBUFFER = 2I3O5 6 7 8 9T
    // Removed portion will be '2I', so ATOI will grab the 2
    cLEVEL = ITOA(ATOI(REMOVE_STRING(cBUFFER,'I',1)));
    
    // cBUFFER = 3O5 6 7 8 9T
    // Removed portion will be '3O', so ATOI will grab the 3
    cINPUT = ITOA(ATOI(REMOVE_STRING(cBUFFER,'O',1)));
    
    // cBUFFER = 5 6 7 8 9T
    // Look for spaces
    IF(FIND_STRING(cBUFFER,' ',1))
    {
    	// ATOI will grab the 5
    	SPLIT_STRING(cBUFFER,' ',cOUTPUT);
    	// cOUTPUT now holds all outputs 
    }
    ELSE
    {
    	// cBUFFER = 5T
    	cOUTPUT[1] = ITOA(ATOI(cBUFFER));
    }
    
    // Do what you want with your values
    

    Some other good functions from AMX:
    TN 659 - TRIM_STRING - a way to remove the spaces before or after characters in a string
    TN 660 - FIND_STRING_REV - a way to search for characters in a string starting at the end
    TN 661 - REPLACE_STRING - a way to replace specific characters, or remove specific characters, from a string
    TN 662 - SPLIT_STRING - a way to assign sub-strings separated by delimiters from a string to an array
    TN 933 - COUNT_STRING - a way to count the number of times a pattern of characters occurs in a string
  • kbeattyAMXkbeattyAMX Junior Member
    That function , SPLIT_STRING doesn't seem to be supported in the NetLinx.AXI. You'd have to copy the function out of the Tech Note and paste it into your program.
  • jjamesjjames AMX Sustaining Engineer
    kbeattyAMX wrote: »
    That function , SPLIT_STRING doesn't seem to be supported in the NetLinx.AXI. You'd have to copy the function out of the Tech Note and paste it into your program.

    Right. That is why I paste those functions into the Netlinx.axi - and then it's supported! ;)

    That is also why I included the TN number.
  • a_riot42a_riot42 AMX Wizard
    jjames wrote: »
    How about using AMX's SPLIT_STRING function (technote 662)?

    Just a warning, I found a bug in split_string that I found hard to believe wasn't tested for so I am not sure how heavily these functions were tested when they were conceived.
    Paul
  • jjamesjjames AMX Sustaining Engineer
    a_riot42 wrote: »
    Just a warning, I found a bug in split_string that I found hard to believe wasn't tested for so I am not sure how heavily these functions were tested when they were conceived.
    Paul

    Would you mind sharing that bug? :D
  • Joe HebertJoe Hebert Junior Member
    a_riot42 wrote: »
    Just a warning, I found a bug in split_string that I found hard to believe wasn't tested for so I am not sure how heavily these functions were tested when they were conceived.
    Paul
    What bug is that?

    I know that REPLACE_STRING (TN661) will spin you into an infinite loop if you try to replace one character with two or more of the same character. Oops.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file