LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Writes to Arduino is too fast for arduino

Solved!
Go to solution

I want to send a serial write message to an arduino board, for it to do something on command. Is there a way I can get it to send the message multiple times for a specific length of time to ensure arduino receives the message?

 

Many thanks

0 Kudos
Message 1 of 15
(5,255 Views)

Put it in a while loop with a wait function to specify the delay, and an elapsed time function to stop after a certain time?

This seems like a workaround though, you may be better off solving the problem at the other end where the arduino doesn't receive the message.

Ian
LabVIEW since 2012
Message 2 of 15
(5,252 Views)

IanSh's solution should work for your original question of how to send it repeatedly

 

Do you have a sample of code you can share with us? How are you connected to the Arduino (USB, Ethernet, etc) Have you tested your code and the Arduino is not responding to the command?

 

One thing that I do when communicating is to use the VISA Clear function before sending a message to the Arduino if it is a high priority message.


Certified LabVIEW Architect, Certified Professional Instructor

CLA CPI

Message 3 of 15
(5,225 Views)

Thank you for your replies. I have tried your solution Ian, and I can see how this should work, but it does not seem to. I think the problem may be with arduino actually. I am connected to arduino via usb. Arduino responds to my commands when I type into the serial monitor, but not when i send from labview.

0 Kudos
Message 4 of 15
(5,210 Views)

It might be that your "configure serial port" function hasn't got any inputs wired, so it will set all the default settings for serial such as baud rate. Check what the settings are at the arduino end and make sure these match what you set up in LabVIEW.

Ian
LabVIEW since 2012
Message 5 of 15
(5,200 Views)
Solution
Accepted by topic author sw14928

Also make sure you close down the serial monitor before trying to access the port in LabVIEW. As the port will be busy if you have the serial monitor open.

 

When creating the VISA session make sure to open the visa session and then clear straight after Arduino sometimes wont respond to commands if there is data in the buffer left over.

 

How are you reading the data out from your Arduino? You can use Bytes at Port  function wired into the byte count of the VISA read function.


Certified LabVIEW Architect, Certified Professional Instructor

CLA CPI

Message 6 of 15
(5,194 Views)

Thank you everyone for your replies. The solution was adding in a clear vi immediately after the Serial setup vi, as well as at the end! Thank you very much.

0 Kudos
Message 7 of 15
(5,183 Views)

@nwxan90 wrote:

 

 

How are you reading the data out from your Arduino? You can use Bytes at Port  function wired into the byte count of the VISA read function.


DO NOT USE BYTES AT PORT (ever!)

 

I gather you are also writing the Ardunio code so ADD A TERMINATION CHARACTER TO YOUR SERIAL DATA.

 

ENABLE TERM CHAR in the VISA Configure Serial Port and set the Term Char to match the character you are using

 

Set the VISA READ byte count to a value way higher than the amount you expect to read.

 

Now when you do a VISA Read it will read until it receives a termination character or times out. 

 

Yes, you need to elegantly deal with a timeout error, like clear it and try again.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 15
(5,151 Views)

@RTSLVU wrote:

DO NOT USE BYTES AT PORT (ever!)


I would not say "ever".  I actually have 1 situation where it is useful (when messages randomly come it, I use it to determine if a message has started to come in).  But NEVER use the Bytes At Port to determine the number of bytes to read.  Been burned by that way too many times.



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 9 of 15
(5,139 Views)

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.

 

I use a combination of both. I scan the output of the Arduino for a termination expression as well as using bytes at port to enable it to always read all available information. In my code simple commands are sent to the Arduino from one loop 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. Additionally the NI shipping example for "Continuous VISA Read and Write.vi" uses bytes at port to read its information.


Certified LabVIEW Architect, Certified Professional Instructor

CLA CPI

0 Kudos
Message 10 of 15
(5,138 Views)