04-06-2018 05:57 AM
Hello,
I'm having a trouble with data handleing so, I need some help.
I connected a NOx analyzer (nCLD63) with PC by usb-rs232 converter.
according to the instrument's displat, I should receive a data start with \06@\02* and end with \03n (n is some number).
But instrument send data constantly (cannot change this), my program read the data start with middle of it.
for example, data should be
\06@\02*,-0.8020,-0.7834,*,*,*,*,*,AmB,B@@@,GE@,0000,0000,@@@@\03G
but program read it like
@,0000,0000,@@@@\03G\06@\02*,-0.8020,-0.7834,*,*,*,*,*,AmB,B@@@,GE@,0000,0000,@@@@\03K\06@\02*,-0.8(untill bytes are full)
As one data packet have constant length, I think "Search spllit/string" would be possible with about twice length of read byte setting.
And here is the question
but I'm wonder that in case of read data was
@@@@\03K
\06@\02*,-0.8010,-0.7778,*,*,*,*,*,AmB,B@@@,GE@,0000,0000,@@@@\03@
\06@\02*,-0.8020,-0.7851,*,*,*,*,*,AmB,B@@@,GE@,0000,0000,
and I put "\06@\02*" as a "Search string/char" , where is the split point? is it in front of -0.8010 or in front of -0.8020?
and is there are any other, better solution?
Thanks.
Solved! Go to Solution.
04-06-2018 06:30 AM - edited 04-06-2018 06:31 AM
@blacktea wrote:
and is there are any other, better solution?
@what I would do is have a loop that does nothing but read data from the serial port and it should have multiple cases based on what part of the message you are at. The first stage should read 1 byte until \06 is read. It should then read 3 bytes and verify it is @\02*. Then you can just read the rest of the message using a constant since you stated the packet is always the same length. Then use a queue to send that message to another loop where the data can be parsed and acted upon.
04-06-2018 06:42 AM
Oh, thanks.
Ans if I only need two number value,(at \06@\02*,-0.8020,-0.7834,*,*,*,*,*,AmB,B@@@,GE@,0000,0000,@@@@\03G, I need -0.8020 and -0.7834 only) than I need to read 15byte right?
04-06-2018 08:24 AM
@blacktea wrote:
Ans if I only need two number value, than I need to read 15byte right?
No. You still need to read the entire message. Let the parser handle finding those two values.