LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to improve visa read accuracy?

Solved!
Go to solution

Hi,

 

I'm building a device testing tool. And I'm using an arduino to read serial data. I've build a VI but the output of VISA READ is a string witch has a precision of 2 decimals. I need at least 3 decimals. Does anyone have an idea on how to achieve that?

 

I've posted the VI's I use as well as the arduino control program.

 

 

Download All
0 Kudos
Message 1 of 11
(4,692 Views)

1. Only initialize the port once BEFORE the loop.

2. Do NOT use the Bytes At Port to tell the VISA Read how many bytes to read.  Instead, use a large number (larger than any message you would expect to recieve).  The termination character will stop the VISA Read and return the entire message.

 

Here is a cleaned up version of your code with a few additional optimizations.


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 11
(4,672 Views)
There is no precision associated with a VISA Read. The returned string will be exactly what the instrument sends. Your conversion to a numeric or the display of it does have a precision that you can set. I'm posting from my phone and can't look at your code so I'm guessing you are using one of the conversion functions incorrectly or you don't know how to change the precision of an indicator with a simple right click. The other possibility is that your arduino code is truncating the data. A simple probe on the VISA Read will show exactly what you are receiving.
0 Kudos
Message 3 of 11
(4,665 Views)

The Arduino code makes TO or TF (string) a 2 bytes package as far as I can tell. Reading in a longer message doesn't change the lenght that is read in at the VISA WRITE block.

 

Only thing is that after I changed the code to read in a char or even float its size doesn't increase either.

 

So truth be told I'm missing something or I do not know how to convert the data as said.

0 Kudos
Message 4 of 11
(4,634 Views)
For arduino problems, find an arduino forum to get help in writing your sketch. It's not a LabVIEW problem. Someone here might be able to help but you haven't attached the sketch so anyone would be just guessing. I don't know what you mean by TO or TF.
0 Kudos
Message 5 of 11
(4,628 Views)

The sketch is the zipfile included in the first post. But I doubt it's the sketch. I think it has something to do with the conversion.

 

0 Kudos
Message 6 of 11
(4,620 Views)
Why do you think that? The probe will tell you the exact string you receive. You don't need to guess. The use of I/O Trace will also tell you the exact string. These are troubleshooting fundamentals you need to do.
0 Kudos
Message 7 of 11
(4,615 Views)

Very true. Bad choise of words.

 

The return count of VISA WRITE is depandant on the number of characters used in the strings before it. Both the bytes at port and VISA READ are at 6 bytes. Wich I thought should be enough for a more accurate number.

fig1.JPG

0 Kudos
Message 8 of 11
(4,521 Views)
Solution
Accepted by Teun1988

Hi Teun,

 

your received string reads "4.58  " - with a linebreak included! So you probably receive something like those chars: "4" "." "5" "8" CR LF !

That are exactly 6 chars and you receive a float with two decimals (after the decimal separator). What else do you expect?

 

When you want more "precise" floats you need to change your Arduino sketch to actually send them!

(Using a format code like "%.5f" with an appropriate "printf"-command should do the trick…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 11
(4,513 Views)
The accuracy of your number starts with the instrument that is reading and sending. It's not the fault of LabVIEW if that doesn't meet your accuracy specifications. Since you have not specified what these six bytes actually are (the raw data), I'm going to assume you don't need further help and can solve the problem yourself. I've given as much as I can with do little information you are willing to share.
0 Kudos
Message 10 of 11
(4,508 Views)