I need to proccess a answer from device.
2Fast
Posts: 90
Hello, here I'm again making questions :$
The device sends for example:
ID01,F23,NB07□ID99,F14,NC06,ST01□□ID01,F02,ST00000010□ID02,F02,ST00110101□ etc etc
I need to divide this answer, like:
Device1 = ID01,F02,ST00000010
Device2 = ID02,F02,ST00110101
.
.
.
Device15=ID15,F02,ST01110101
Thanks!!
The device sends for example:
ID01,F23,NB07□ID99,F14,NC06,ST01□□ID01,F02,ST00000010□ID02,F02,ST00110101□ etc etc
I need to divide this answer, like:
Device1 = ID01,F02,ST00000010
Device2 = ID02,F02,ST00110101
.
.
.
Device15=ID15,F02,ST01110101
Thanks!!
0
Comments
something like that should work
Hope this helps!
http://amx.com/techsupport/techNote.asp?id=616
The STRING section of a physical device is not very reliable. It's fine for inter-system communications, like between main code and modules, or virtuals, or master-to-master. However, a real device might pause a few milliseconds too much mid-string, and the STRING handler will see that as the entire string. If it doesn't pause enough between strings (and you can't set this interval), it may lump more than a full string together in one event. For those reasons, I prefer to use a buffer for real devices.
If you take the code out of the handler you can almost always remove a while statement since the code wil be evaluated on every pass to see if a certain condiiton is true. On the down side since it is not event driven it will be evaluated and evaluated and evaluated on every pass of the mainline.
In the example below the code in the string handler needs a while loop to test for every possible complete parsable section of code otherwise you'll end up with un processed data and the data remaining in the buffer will get processed at a later time when the event is triggered again, second, minutes or days later. Not good! The code in the main program will check the buffer for a complete section on every pass. Now depending on how busy the system is the 2nd method will probably take longer to completely process.
If you do process strings in the event handler and test for completeness before processing I don't think there should be a problem since in the event if a complete string isn't received if won't be processed and when the remainder of the string does arrive another event will be triggered and you'll test for completeness again.
There appears to be pros & cons to either method and depending on where my head is at on any particular day I'll use one or the other.
this code works, i've tested it in the field.
I use a buffer because the string that came from the device was way long, and was sent at short intervals. So i first populated the buffer with the exact string i wanted (header + data + checksum + footer) and then processed the buffer.
When i didn't receive a correct string, i didn't do any buffer processing and just requested the data again.
Vining,
I aggree either method is fine. Just so you know the "if" is redundant in your code, when using the while loop. The while loop acts like an if....
Yep I knew that, I was hoping nobody noticed.
<- laughed out loud