LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Losing Data Using VISA

Solved!
Go to solution

Hi,

 

I've been studying Labview recently, and in the last 4 months I've been making a code to read some data from a arduino (and also write some data) and then execute calculations with this data, like math operations, plot graphics, save in a TDMS file, etc. 

The problem is, when I click in the button to turn on/off some of the plots (the green button on the side of the plot names), some of the data is lost, going to zero and then going back up. I don't know if there are other circumstances which this error would also occur.

Can you guys help me? 

I'm sorry if the VI attached is a little mess and in portuguese.

Any questions about the VI, ask me.

The round to decimal is just a subVI.

Thanks in advance

Download All
0 Kudos
Message 1 of 15
(3,620 Views)

You are opening and reconfiguring your serial port every time the timeout case runs.  If there is data in the buffer, it is going to be lost.

 

The serial port should only be opened and configured before the while loop, and closed when your program is done.

Message 2 of 15
(3,606 Views)
Solution
Accepted by topic author CastroPedro

1. Your Value Property Nodes are SLOW.  Use the terminals and/or wires to pass your data around.

2. Right-click on the plot legend and there is an option Visible Items->Plot Visibility Checkbox.  That will do all of the work for your LED buttons and will be A LOT more efficient.

3. Move your initialization code into a sequence structure to the left of your main loop and eliminate the case structure.  Less stacked structures will help the readability.

4. You really should just have 1 event structure in your VI.  You can cause weird things to happen when you have multiple event structures handling the same event inside of a VI.


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
Message 3 of 15
(3,594 Views)

Crossrulz,

 

How did you find that 2nd event structure?  It was small and buried deep.  Even after running block diagram cleanup on that oversized block diagram, it took me a while to find it.

0 Kudos
Message 4 of 15
(3,590 Views)

@RavensFan wrote:

How did you find that 2nd event structure?


Which one?  I found several event structures, at least one inside of another event structure.


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 5 of 15
(3,566 Views)

Timeout event and Esc, Value change inside the False / False case structures..  That was the only other one I saw.

 

Until now digging more, I found one more inside multiple case structures and while loops.

 

(EDIT: And yet another one).

 

For the OP:

It is a bad idea to have multiple event structures in a single VI.  Unless you really know what you are doing, you'll probably get it wrong.

Read Caveats and Recommendations when Using Events in LabVIEW - LabVIEW 2015 Help

Message 6 of 15
(3,563 Views)

Thank you both!!

So, I made the changes, but the problem still occurs.

I'm attaching again the VI, with the changes, and a photo of the error.

 

Download All
0 Kudos
Message 7 of 15
(3,545 Views)
Solution
Accepted by topic author CastroPedro

The next thing to look at is what does the data coming in actually look like?

 

I don't see where you do a VISA Write to request data.  So your device must be continuously sending data.

 

    You have the termination character enabled as the Line Feed character.  Does your device send that?  If so, why aren't you using it?  The Bytes at Port method is the wrong thing to use about 99% of the time if the data has a termination character.  If you have a 0 at the time you do the check, you don't bother doing the VISA read, but your case structure sends out default data of zeroes on all those outputs.

 

If you have some data and read it, but it is incomplete, then some of those Scan From Strings will fail and you'll get zeroes on some of them.

 

By the way, Index Array is expandable.  Drag down the bottom border.  You'll get index 0, 1, 2, 3 .... automatically without wiring up any constants.  No need to duplicate that function splitting the array wire and wiring up all those index constants.

Message 8 of 15
(3,540 Views)

Hello,

 

Yes, the device is sending data continuously.

The data comes, for exemple, like this : 23.30;23.11;23.37;23.32;0.00;0.00\n

Where the \n does not show up, and the numbers can vary from 0 to ~100.

I didn't know that about the Bytes at Port. How can I use the Line Feed character that way?

Didn't know that about the Index Array neither.

 

Thank you really much!

0 Kudos
Message 9 of 15
(3,510 Views)

What is the longest message you ever expect to get?

 

Do a VISA read with a number of bytes greater than that.

Message 10 of 15
(3,508 Views)