07-24-2019 10:53 AM
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
Solved! Go to Solution.
07-24-2019 11:19 AM
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?
07-24-2019 11:58 AM
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).
07-24-2019 02:20 PM
yes it does terminate the line after \n always.
07-24-2019 02:22 PM
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.
07-24-2019 02:31 PM - edited 07-24-2019 02:31 PM
@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?
07-24-2019 02:44 PM
No it is not the actual read buffer for the serial.
No the breaks do not occur every 80 char.
07-24-2019 03:34 PM
You have your timeout set to 10ms. Try increasing it so it does not stop the read function early.
07-24-2019 03:56 PM
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 ?
07-24-2019 04:16 PM
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.