Processing Received Strings
chrisj82
Posts: 2
Hi all I am having trouble with a certain system below is an example of the string being received (in netlinx string format)
"02,85,'UNIT-5 ALARM',03"
After the above string there is a whole heap of other junk that I dont want, also the above string wont always be the same, there are other types of alarms ect so the char length will vary.
What I want to do is use 85h as my starting delimeter then store all char's to a variable until 03h is received, is it possible, im sure it is, im just not seeing it.
Any help would be much appreciated, thanks guys
"02,85,'UNIT-5 ALARM',03"
After the above string there is a whole heap of other junk that I dont want, also the above string wont always be the same, there are other types of alarms ect so the char length will vary.
What I want to do is use 85h as my starting delimeter then store all char's to a variable until 03h is received, is it possible, im sure it is, im just not seeing it.
Any help would be much appreciated, thanks guys
0
Comments
I love protocols that use a start and end character. First, tokenize your buffer by using something like
sToken=REMOVE_STRING(sBuffer, 3, 1) ;
This will give you a string ending with the 03, and remove it from the original buffer. Chances are more than likely that it's going to start with 02, but if it doesn't, simply do a FIND for the 02, and lop the extra off the token with something like this:
sToken = RIGHT_STRING(sToken, (LENGTH_STRING(sToken) - FIND_STRING(sToken, 2, 1))) ;
That will give you everything after the 02 and including the terminating 03. You can break it down further as necessary.
Just another way to skin the cat
Jeff
I would initially just look for ETX ( 3 ) and then once that's found I would check if a STX also preceded it. Otherwise I'd ignore the RX but dump the content if I don't receive the ETX after a specified time. I almost always use a while just in case more then 1 complete string is ever received and WTF even if it isn't possible there's no real difference between using the if or while in this case.
Plus if you're new to parsing or even if you aren't send_string 0's are your friend. So use them and comment them out when the bugs are worked out.