08-07-2017 11:16 AM
Hi,
I just want read the data from serial port of Arduino by using the NI VISA. When I read the data from the serial Monitor, the data is like this:
T
1022
1023
987
885
854
T
1022
1024
988
885
854
But when I read these data in LabVIEW, some data is lost, like the text file, which I attaches. Could someone explain the reason?
Best regard
08-07-2017 11:58 AM
If only I had a penny for every time this error came up on the forums...DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!! (enough emphasis?)
The Bytes At Port causes weird race conditions like what you are seeing. Since you have the termination character enabled, use it. Just tell the VISA Read to read more bytes than you ever expect in a message. The read will stop when it reads 1) the number of bytes you told it to or 2) the termination character. So by telling the VISA Read to read more bytes than a message should ever be, you are essentially ending your read with the termination character. This ensures you got a full message.
08-07-2017 01:04 PM - edited 08-07-2017 01:06 PM
Also besides what Crossrulz said you might find it easier to send your data all at once instead of one at a time.
Instead of sending
T
1022
1023
987
885
854
T
1022
1024
988
885
854
Just send it all in one line separated by commas;
T,1022,1023,987,885,854
T,1022,1024,988,885,854
Then you can use the "Spreadsheet String to Array" vi by setting the delimiter to a comma and Generate your Dataarray for every measurement in one simple step.
08-07-2017 01:31 PM
@RTSLVU wrote:
Also besides what Crossrulz said you might find it easier to send your data all at once instead of one at a time.
That advice sounds familiar...https://forums.ni.com/t5/LabVIEW/String-Comparison/m-p/3671469#M1031920