LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't initiate Serial communication most of the times with Arduino

 Hi guys, I'm having a problem most of the times when intiating a VI that  communicates with Arduino through Serial port and reads and sends data at a baud rate of 9600 kb/s.
Almost every ocasion I have to push the reset button until it starts communicatin at a normal continous rate, and sometimes the communication either stops or gives me a BSOD in windows  Smiley Frustrated
 Also heres the Arduino code I'm using:

http://codeviewer.org/view/code:4804

I
s this normal? or how can I deal with this serial communication erros I'm having.

0 Kudos
Message 1 of 7
(2,961 Views)

You are not handling any errors in the segment of LV code shown in your image.

 

You proceed with the VISA Write even if a read error occurred.

 

What kinds of errors do you get? Where in the code do the errors occur? 

 

Do you have any control over which program starts first? I did not look at the Arduino code - and probably would not understand it if I did. Does it start sending data after the reset? How long does it take to get started? Is the first message always complete? Does it send the termination character the LV code expects (line feed)?

 

Lynn

0 Kudos
Message 2 of 7
(2,928 Views)

The Arduino Program starts first, it sends data throught the Serial port when it starts and reads when theres anything available through it, I finish my lines with Serial.println(); in  Arduino, and when I reset the Arduino it starts sending data. Normally after to o r three resets it starts communicating continously.

0 Kudos
Message 3 of 7
(2,917 Views)
If it takes a couple of resets before the arduino starts to send data, you should be looking at your sketch code and not the LabVIEW part. The arduino has its own ide so do your basic debug there. In the LabVIEW program, added a delay at the beginning to make sure the reset is complete before trying a read. Lastly, get rid of all those local variables and sequence structures. Add some error handling as Lynn mentioned.
0 Kudos
Message 4 of 7
(2,906 Views)

Sorry for the late response, Why is it better to have sequence structures instead of local variables? , Furthermore how reliable is Serial communication if I want to build an automated system, because that's my main concern with my Labview and Arduino Code. 

0 Kudos
Message 5 of 7
(2,821 Views)
It's better to have no sequence structures or local variables at all. They complicate the code and on the case of locals, add resources and can cause race conditions.

In my experience, serial communication with LabVIEW is very reliable, or as reliable as it can be.
0 Kudos
Message 6 of 7
(2,811 Views)

Serial communication between Arduino and LabVIEW is very reliable.  You need to look at your sketch first and verify it's doing what you want.  As was mentioned above, Arduino's IDE has that Serial Monitor that allows you to receive and send as you please in order to verify Arduino code.  Now, in order to verify and debug the messages you think you are sending on the serial port to the Arduino, you should use NI Visa.  You can establish connection and send whatever it is you wish to send to verify your commands are being interpreted correctly.  From there, I'd also look into Arduino's serial library.  I wish I knew the answer to this for sure, but it's possible Arduino is look for an "End of Line" which I do not see being sent in your LabVIEW.  I'd definitely look into that.  And then of course, everything everyone else said about Local Variables and sequence structures.  Local Variables are not as big of deal as some are making it to be.  Your application is small and would not be negatively affected by the use of multiple local variables.  That being said, it isn't good practice due to potential race conditions and blah blah blah.  Your code could easily be re-written in a state machine format.

0 Kudos
Message 7 of 7
(2,802 Views)