Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

cutting serial(rs232) data streem

Solved!
Go to solution

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.

0 Kudos
Message 1 of 4
(2,744 Views)
Solution
Accepted by topic author blacktea

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 4
(2,738 Views)

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?

0 Kudos
Message 3 of 4
(2,728 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(2,718 Views)