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. 0
Comments
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" } } }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:
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![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.
Thanks.
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 valuesSome 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
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.
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?
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.