LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Read size problem

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. 

govindsankar_0-1745333471906.png

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:

govindsankar_1-1745333639500.png

So how can I do this without hard-coding the bytes to read in VISA read. 

 

 

 

 

 

0 Kudos
Message 1 of 12
(418 Views)

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

govindsankar_0-1745333471906.png

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:

govindsankar_1-1745333639500.png

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.

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 2 of 12
(403 Views)

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.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 12
(397 Views)

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

0 Kudos
Message 4 of 12
(391 Views)

@govindsankar wrote:

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

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 12
(382 Views)

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

0 Kudos
Message 6 of 12
(378 Views)

@govindsankar wrote:

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

trimCapture.PNG

I turned on the "\' codes display" so you can see the CR+LF characters have been removed from the end of the string. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 12
(372 Views)

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

0 Kudos
Message 8 of 12
(368 Views)

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.

 

trim2Capture.PNG

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 12
(347 Views)

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.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 10 of 12
(292 Views)