04-22-2025 09:55 AM
Hi, I have a program that i written to read out from a serial device. I use VISA read. But the problem is end termination is both CR/LF. So I just hardcoded the bytes to read to VISA read. But my boss just told me that wont work, because tomorrow the amount of data to read maybe even more. So how can I fix this. I will attach the program.
You can also see the screenshot of the program here with the two VISA reads. The first VISA read is ok i guess, but the problem is the second VISA read that happens in a loop, and every loop a certain amount of data comes, and the size of that is what I have hardcoded. The expected output is this:
So how can I do this without hard-coding the bytes to read in VISA read.
04-22-2025 10:29 AM
@govindsankar wrote:
Hi, I have a program that i written to read out from a serial device. I use VISA read. But the problem is end termination is both CR/LF. So I just hardcoded the bytes to read to VISA read. But my boss just told me that wont work, because tomorrow the amount of data to read maybe even more. So how can I fix this. I will attach the program.
You can also see the screenshot of the program here with the two VISA reads. The first VISA read is ok i guess, but the problem is the second VISA read that happens in a loop, and every loop a certain amount of data comes, and the size of that is what I have hardcoded. The expected output is this:
So how can I do this without hard-coding the bytes to read in VISA read.
Use the LF as the termination character and just drop the CR by using the trim whitespace primitive. I can't look at the actual code ATM, but it seems confusing at best.
04-22-2025 10:45 AM - edited 04-22-2025 10:48 AM
I recommend you watch this video: VIWeek 2020/Proper way to communicate over serial
In general if you have a termination character (CR+LF) then set that as the termination character in the VISA Serial setup.
Set your VISA Read to read way more bytes than you ever expect to receive.
VISA read will read until it receives the termination character or times out.
No need to know exactly how much data you are expecting and it can be a different amount every time.
04-22-2025 10:49 AM
@RTSLVU, but correct me if I am wrong, but from what I know there is no (CR+LF) termination character in labview. That is my problem
04-22-2025 10:55 AM
@govindsankar wrote:
@RTSLVU, but correct me if I am wrong, but from what I know there is no (CR+LF) termination character in labview. That is my problem
Well you could use either CR or LF since they are both there and parse the extra character out.
Or
Your code is named "Arduino.vi" so I am assuming that you are communicating with an Arduino. If you have access to the Arduino code then change it to use one or the other instead of both CR+LF
04-22-2025 10:59 AM
@RTSLVU, I dont have access to the arduino code. And sorry but here is some parts of labview or data communication that i dont much about. So what does parse the extra character out mean. Thank you.
04-22-2025 11:11 AM - edited 04-22-2025 11:16 AM
@govindsankar wrote:
@RTSLVU, I dont have access to the arduino code. And sorry but here is some parts of labview or data communication that i dont much about. So what does parse the extra character out mean. Thank you.
Well parsing is the computer programming term for analyzing text.
It's this simple
I turned on the "\' codes display" so you can see the CR+LF characters have been removed from the end of the string.
04-22-2025 11:13 AM
I agree with the above poster- if you ALWAYS get CR/LF, use LF for your termchar. That will mean your data comes back with an extra "CR" at the end. Since you KNOW there will be an extra CR at the end, you can trim it off. Assuming your text is human readable, using "Trim Whitespace.vi" will chop off any extra CR (or spaces, tabs, etc) at the end of your serial read.
(I also wish you could use CR/LF as a termchar "pair" but it's not available, unfortunately. It would help for devices that need to receive the CR/LF.)
04-22-2025 11:37 AM - edited 04-22-2025 11:38 AM
Trim Whitespace works both ways, so in reality it does not matter if you choose CR or LF as your termination character in VISA Serial Configure. As it will trim space, CR, LF characters off both ends of the string.
04-22-2025 12:30 PM - edited 04-22-2025 12:31 PM
My recommendation also follows others, use LF as termchar. Only downside is if your device has any scenario where it sends LF elsewhere in the middle of a response and end it with CR/LF.