LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

extract a whole line after termination character from serial port

Solved!
Go to solution

Hello,

I am working on a program where I get serial data from the device and based on that data I am sending some sensor values via a DAQ. I am using match regular expression with a \n but sometimes the line is getting spread across 2-3 lines making my parse difficult. Is there some way where I can get the whole line before my program parses the lines as it comes(even with breaks) I am attaching a sample of what I have done in smaller code not including the parse, if I can extract the whole line that would be much easier.

 

Regards

 

0 Kudos
Message 1 of 17
(2,909 Views)

I'm using LV 2016 so I couldn't view your program, but here are some hints.

You can set the termination character when you initialize the serial port. This means when you read you will read until (a) you hit the the max number of bytes (b) you hit the termination character (c) you time out. Does your serial device always terminate a response with new line?

0 Kudos
Message 2 of 17
(2,885 Views)

DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (not enough emphasis)

 

Your instrument sends out lines.  So use that to your advantage.  You already have everything else correct (termination character enabled and set correctly).  Your missing piece is how you are reading the data.  Just tell the VISA Read to read more bytes than you ever expect in a single line.  It will stop reading when it reads the termination character or it times out (whichever happens first).


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 3 of 17
(2,860 Views)

yes it does terminate the line after \n always.

0 Kudos
Message 4 of 17
(2,833 Views)

I removed the bytes at port and tried the same way, it is still simlar.

 

It is still sometimes breaking the log line across 2-3 lines even though there is no termination character.

0 Kudos
Message 5 of 17
(2,830 Views)

@LVPS28 wrote:

I removed the bytes at port and tried the same way, it is still simlar.

 

It is still sometimes breaking the log line across 2-3 lines even though there is no termination character.


The output isn't actually meant to be read by a terminal, is it?  What I mean is, do the breaks occur every 80 characters?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 17
(2,822 Views)

No it is not the actual read buffer for the serial.

No the breaks do not occur every 80 char.

 

 

0 Kudos
Message 7 of 17
(2,818 Views)
Solution
Accepted by LVPS28

You have your timeout set to 10ms. Try increasing it so it does not stop the read function early.

 

Capture.PNG

Message 8 of 17
(2,797 Views)

tried this as well, is there anyway we can serach the whole string using characters and when it finds \n then terminate it, do we have a property node or something for the visa read to that ?

0 Kudos
Message 9 of 17
(2,789 Views)

That is exactly what setting the termination character should do. Can you attach your code again (with the suggested changes) along with a string indicator that has typical data in the "TERMINAL" indicator? You can save the data by clicking edit >> make current values default.

0 Kudos
Message 10 of 17
(2,782 Views)