04-24-2017 12:40 PM - edited 04-24-2017 12:44 PM
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
Solved! Go to Solution.
04-24-2017 12:47 PM
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.
04-24-2017 12:52 PM
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.
04-24-2017 12:55 PM
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.
04-24-2017 01:41 PM
@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.
04-24-2017 01:49 PM - edited 04-24-2017 01:51 PM
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
04-24-2017 03:04 PM
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.
04-24-2017 03:14 PM
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.
04-25-2017 10:32 AM
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!
04-25-2017 10:36 AM
What is the longest message you ever expect to get?
Do a VISA read with a number of bytes greater than that.