LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Writes to Arduino is too fast for arduino

Solved!
Go to solution

@nwxan90 wrote:

DO NOT USE BYTES AT PORT (ever!)


Is there a performance or stability reason not to use bytes at port? I am relatively new to using VISA to communicate with an Arduino.


The Bytes At Port causes a really weird race condition.  Say your Arduino just sent a message that is 10 bytes long.  During the transmission, your PC uses the Bytes At Port and gets the value of 3.  So instead of reading all 10 bytes, you are just reading 3.  That then causes all kinds of synchronization and data processing errors.  Instead, we need to use the structure of the message to read all of it.  If using the termination character, this becomes really simple: just tell the VISA Read to ream more bytes than you would ever expect in a message.  The VISA Read will then stop reading when it reads the desired number of bytes or the termination character is read.

 


@nwxan90 wrote:

 and then read using the bytes at port with termination expression in a different loop.

 

This is mainly because the amount of information that the Arduino produces could be a single value or it could be a large stream of information.


How is the "large stream" formatted?  Does it end with a termination character?  How large is the stream?



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 11 of 15
(1,142 Views)

@nwxan90 wrote:

DO NOT USE BYTES AT PORT (ever!)


 

This is mainly because the amount of information that the Arduino produces could be a single value or it could be a large stream of information. Additionally the NI shipping example for "Continuous VISA Read and Write.vi" uses bytes at port to read its information.


Yeah I suppose "ever" was rather strong language, but since I learned about using the "Termination Character and timeout method" I have NEVER had to use Bytes At Port again.

 

Like the Stacked Sequence structure I try to implore new users to just avoid using it.

 

BTW: That NI example is a BAD example of serial data reading and should have long since been deprecated. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 12 of 15
(1,142 Views)

@crossrulz wrote:

@nwxan90 wrote:

DO NOT USE BYTES AT PORT (ever!)


Is there a performance or stability reason not to use bytes at port? I am relatively new to using VISA to communicate with an Arduino.


The Bytes At Port causes a really weird race condition.  Say your Arduino just sent a message that is 10 bytes long.  During the transmission, your PC uses the Bytes At Port and gets the value of 3.  So instead of reading all 10 bytes, you are just reading 3.  That then causes all kinds of synchronization and data processing errors.  Instead, we need to use the structure of the message to read all of it.  If using the termination character, this becomes really simple: just tell the VISA Read to ream more bytes than you would ever expect in a message.  The VISA Read will then stop reading when it reads the desired number of bytes or the termination character is read.

 


How is the "large stream" formatted?  Does it end with a termination character?  How large is the stream?


Thanks for your explanation that makes a lot of sense. I will look into it for my next project.

 

Unfortunately the Arduino code is written by other people so I never know how big the stream will be or exactly how it will be formatted. I am working on trying to standardize the process and I will take this feedback onboard.

 

Thanks again


Certified LabVIEW Architect, Certified Professional Instructor

CLA CPI

0 Kudos
Message 13 of 15
(1,138 Views)

RTSLVU wrote:

BTW: That NI example is the WORST example of serial data reading and should have long since been deprecated. 


Agreed.  Though, in some newer version there is a comment added saying that the Bytes At Port is not likely the correct thing to do.  From the example in 2016:


Note that the "Bytes at Port" property is used to determine how much data to read. For a single read use case, this is acceptable. For a continuous serial read, a more general approach is recommended.


 Ok, it is still horrible.  But at least a step in the right direction from what it used to be.



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 14 of 15
(1,135 Views)

@nwxan90 wrote:

Unfortunately the Arduino code is written by other people so I never know how big the stream will be or exactly how it will be formatted. I am working on trying to standardize the process and I will take this feedback onboard.

 

Thanks again


Well you know since most Arduino code is written using "Wireing" or whatever the native Arduino language is called.

 

Anyway the Serial.Println command will put at carriage return at the end, there's your Termination Character.

 

Also if you start up the serial monitor and the data coming in is separated into lines then there is a carriage return on new line character being put in there. 

========================
=== Engineer Ambiguously ===
========================
Message 15 of 15
(1,131 Views)