LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple VISA Writes to Arduino SLOW communication

Solved!
Go to solution

Hi all, 

Firstly, about this project: it's my senior project (EET) and I've been working on this for about 2.5 months trying to get ahead for my last semester this Fall.  The concept is to run an ignition coil using LABVIEW as an interface that A) has user input that is sent to an Arduino MEGA 2560, B) sets up a Tektronix O'scope and sends a current reading to Arduino (the Arduino is also pulsing the coil) while graphing on the LABVIEW UI as well. I also have the Arduino controlling relays, monitoring battery voltage, controlling pulse, etc.

 

This original program works and it does everything I want it to, though I have to wait 1100ms before each VISA write for the Arduino to receive the variables correctly.  Doing this many delays makes the program take about 10 seconds to complete and I needed it ~5 for a full run.

 

This past week I've been experimenting, initially I had each VISA Write in it's own stacked sequence but now I've been trying to put each VISA Write in it's own while loop all in the same stacked sequence with the VISA resource lines controlling the sequence. This basically does the same and works with 1100ms in the loop with VISA Write or if I highlight execution with no delay.  I can't find anything on multiple consecutive VISA Writes on the web that is close to what I am doing. If anyone can give me direction I'd appreciate it.  

 

Note: These most recent programs I am posting are about half of the total program as these are the parts I'm having issues with.

 

Thanks in advance!

Download All
0 Kudos
Message 1 of 5
(4,228 Views)

You should not be having to wait for over a second just to send the next data point.  From what I can gather (not an Arduino ino expert), you are actually waiting for a timeout on the Arduino side since the read is expecting to see a termination character (0xA).  You should just tell VISA to append the termination character at the end of the write with a property node at the start of the application.  This should eliminate the need for all of those waits.


GCentral
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 2 of 5
(4,220 Views)

Okay, I set up that VISA property node and also changed the Arduino side to Serial.readString() without the 'Until(0xA)' part.  Now, the LabView program does a full run through and then sends the input, at least it's popping up on my LCD after the Start button and been pressed and then depressed after it runs through.

 

I set the termination setup to true on the serial setup and it made no difference, would I still need some small delay in there? 

 

EDIT:  it is sending the input and popping up on the LCD, but it's only the frequency the first time. If I run again, then the dwell gets sent and so on.

Download All
0 Kudos
Message 3 of 5
(4,203 Views)
Solution
Accepted by topic author buff_enjineir

Ok...crossrulz I think you put me on the track after a week of messing around with this. haha

Seems Arduino has a default Serial timeout that's like 1 second, so my delay had to be a little bit longer than that timeout I'm guessing. I set the Timeout to 250ms on that side and with a 150ms delay before a VISA Write paired with crossrulz's termination character bit, it seems to work pretty well. I hope this helps somebody! 🙂

 

Final solution to this below.  

 

Download All
Message 4 of 5
(4,187 Views)

@buff_enjineir wrote:

Okay, I set up that VISA property node and also changed the Arduino side to Serial.readString() without the 'Until(0xA)' part.


Actually, you want that 'Until(0xA)' on the Arduino side.  Without it, you cannot be sure you got the entire message.  It also makes the code run faster since you will not have to wait for the timeout.

 

In short, both sides of the communication should be using the termination character and you will not need the additional waits in your code.


GCentral
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 5 of 5
(4,141 Views)