07-27-2017 03:09 AM
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
Solved! Go to Solution.
07-27-2017 03:17 AM
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.
07-27-2017 04:06 AM
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.
07-27-2017 04:42 AM
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.
07-27-2017 04:56 AM
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.
07-27-2017 05:17 AM
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.
07-27-2017 05:32 AM
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.
07-27-2017 09:50 AM - edited 07-27-2017 09:55 AM
@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.
07-27-2017 10:07 AM
@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.
07-27-2017 10:09 AM
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.