LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW - Arduino execution delay through VISA

Greetings everyone.
I'm currently working on a VI that will function as an GUI for a dynamometer that uses an Arduino Mega 2560 board for its DAQ system. The Arduino is connected to a PC via an FT232RL module an interacts with LabVIEW through VISA.
 
However I have found a couple of problems regarding the execution on the program.  
 
The arduino is programmed to an overflow interrupt every 100ms to the send a string with the dyno data through the serial port, then the VI reads and decodes the data
 
Everything seems to work as intended, except for two reasons.
1) The VI progressively suffers a delay to show the data. At first it displays the change in values in real time, but as time passes it takes longer and longer to update to current values. I've tried tampering with the miliseconds to wait value, and 100ms appears to be the one the functions the best which is the same period on the arduino interrupts


 
2)Also it seems like that either the arduino or the VI lose the data every certain period of time (which I haven´t determined yet) and this is seen when the data displayed in the VI appears to be "reset" or an abrupt spike as shown in the images.

I would greatly appreciate if some could shed some light as to why these problems might happen. 
Thank you for your time.

0 Kudos
Message 1 of 5
(4,049 Views)

I don't know if this would explain all of this symptoms you are seeing, but one problem you have is that you've fallen victim to the "Bytes at Port" mistake.

 

What is it?  It is when you make the mistake of following a LabVIEW serial port example that uses it, then not implementing it properly.  You write a value out with VISA Write, then immediately check the Bytes at Port.  If the device you are communicating with, the Arduino in this case,  does not respond back with the full message immediately, you will read the wrong number of bytes.  The Arduino needs some milliseconds to read your request and write back a response, and then however long it takes for the Arduino to actuall transmit that many bytes.  If it needs to send 5 bytes, but you check Bytes at Port too quickly, perhaps only 1 or 2 have arrived.  You have an incomplete message.  And the remaining few bytes won't show up until the next time around.

 

The proper thing to do about 99% of the time is to rely on you termination character.  Have your arduino terminate every message with a line feed character.  Then do a VISA Read with a number of bytes greater than the longest message you ever expect to transmit.  You already have the VISA configure set up to use the termination character and for it to be the line feed character.  So take advantage of it.  Don't let your serial protocol fall apart because you can't synchronize the timing between the two systems.

0 Kudos
Message 2 of 5
(4,038 Views)

I've tried your suggestions and it seems they play a part in both issues. Modifying the Byte Count on the VISA Read function alters the behaviour of the VI. A low byte count value creates the data loss i've described in issue 2) and an excessive value for byte count creates a delay in the update interval on the display like in 1)

 

I'll try to modify my Arduino code in order to send the string with a fixed number of bytes and see how it turns out.

 

Thanks for your input, RavensFan.

0 Kudos
Message 3 of 5
(4,013 Views)

I got a similar issue trying to communicate with an arduino board.
Serial query.pngBasically I'm writing until I have available bytes to read at the port.

You can play with the 5ms delay, and you will see how many tries you need to do before actually reading something.

 

Greetings.

Guillermo O.

Certified-LabVIEW-Developer_rgb.jpg

Guillermo Oviedo
R&D Software Engineer
CLA | CTD
0 Kudos
Message 4 of 5
(3,593 Views)


@Cvar00 wrote:

I've tried your suggestions and it seems they play a part in both issues. Modifying the Byte Count on the VISA Read function alters the behaviour of the VI. A low byte count value creates the data loss i've described in issue 2) and an excessive value for byte count creates a delay in the update interval on the display like in 1)

 

I'll try to modify my Arduino code in order to send the string with a fixed number of bytes and see how it turns out.

 

Thanks for your input, RavensFan.


You dont necessarily need a fixed numebr of bytes from the arduino, you just always need to always append a character that wont appear within the standard data, for example you could use "Line feed" 0x0A. This character becomes the termination character.

 

You then set up your visa read so it knows the termination character. You can then set "Bytes to read" to some overly large number, but it will only ever return the complete packet including the term char.

 

Deceased

0 Kudos
Message 5 of 5
(3,587 Views)