Showing results for 
Search instead for 
Did you mean: 

Labview and arduino serial communication package losses

Go to solution

Hello people,

I am quite new in labview and I am experiencing some difficulties while trying to optimize my code to get high sample rate. I am using serial communication between arduino and labview and I read and write through serial. My baud-rate is 500k. Arduino sends some sensor values in the following form   "a11.11b11.11c11.11"  without the quotes and I am using termination character change line \n. (the numbers can be negative so no standard packet size). 


My problem is that when I have very fast sampling rate I am not receiving the complete packet. The most often case is that I have a censored packet with the first two characters missing i.e. "1.11b11.11c11.11". I am using "Wait until next ms =10ms" and arduino runs without delays and execution time of the loop is about 9.8ms. If I increase the time I get the complete packages without problem. But I would like to be close 100samples/sec. Any suggestions??? Thanks a lot in advance.


Best regards


Is any way that I can force the serial read from an initialization character to the termination character in a way that I can get all the packets complete?

0 Kudos
Message 1 of 9

Hi antpap13,


It sound like you are trying to do timing of a read to catch the exact amount of data that you require. This will be inherently difficult and perhaps a better method would be to read a specific amount of data from the serial buffer instead of using timing. 

I would suggest you have a look at the following example where you can specify the size of data to read:


C:\Program Files (x86)\National Instruments\LabVIEW 2017\examples\Instrument IO\Serial\Continuous Serial Write and Read


Hopefully this will provide a little more insight.


Kind Regards,


Matt Fergusson

Applications Engineer UK

0 Kudos
Message 2 of 9

If you're using a termination character and have configured VISA properly to recognize it, then there's no need for any waits at all in the loop that's performing the VISA Read, the read will take care of waiting until the termination character is received. Can you share your code so we can see what else might be going on?

0 Kudos
Message 3 of 9

Hello again, 

Sorry for my late response. I think I have configured them correctly but I am not 100% sure. I have attach my diagram and also a screenshot with the actual readings.  You can see that only a few packets are complete. Thanks for your time and for our help in advance.


Best Regards

Download All
0 Kudos
Message 4 of 9
Accepted by topic author antpap13

The VISA Flush is unnecessary and is probably truncating your received messages. As soon as you receive one transmission and the VISA Read completes you're flushing the receive buffer, but by that point another message may have already begun to be received, so you're throwing part of it away. Remove the flush, and the disconnected Bytes at Port property node.


The 10 ms wait is also unnecessary and could eventually cause a buffer overflow, depending on how frequently your device sends messages. If it's sending them more frequently than once every 10 ms, then your reception won't be able to keep up. The frequency of the loop should be entirely determined by the frequency that your device sends.


Also be aware that your Format Into String function is going to output just one pound sign and no numbers, because there's no format string wired to it.

0 Kudos
Message 5 of 9

Lose the flat sequence, you don't need it (why are you waiting 2 seconds anyway?)


Lose the "Bytes at Port", you don't need it if you are using a Termination Character.


Lose the 10mS wait, you don't need that either.


What is the purpose of the "Sync"?

=== Engineer Ambiguously ===
0 Kudos
Message 6 of 9

Thanks for the last advises arteitle and RTSLVU.


It seems that the problem caused by the serial flush. When I remove it I am receiving complete messages. I used the serial flush because I am using the "wait until next ms" at 10ms and the data on the port comes faster. So, if I plot the data I see it delayed, which is fixed if I flush the serial but, then I received censored messages.


I use the 10ms because I am trying to force 100samples/s. So if the data read takes less than 10 ms then the sync converges to  my wait time which is 10ms. If the messages are arriving at the port slower than my wait time then the "sync" will defer a lot from my wait time and I know that I do not have the sample/s that I want.  


Flat sequence 2 seconds it is used because I do some stuff in the arduino setup function and I want to be sure that these are completed when I go to the while loop otherwise it is useless.



0 Kudos
Message 7 of 9

There's no point trying adding delays and flushes to try to make it seem like your data is being received at a particular rate. The transmitter is going to send at some rate, and in this case there isn't anything the receiver can do to change that. The best approach is to receive all of the transmitted data as soon as it is sent, then if you want to decimate or interpolate the data, do that separately in your LabVIEW code.

0 Kudos
Message 8 of 9

I think that is true. I should receive all the data and I can decide later if I want to do any changes. At the end, that means that labview should run without delays to receive all the available information.

0 Kudos
Message 9 of 9