Parsing an Autopatch Response String?
vegastech
Posts: 369
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
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. 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.
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
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.