LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino board+Labview, serial port communication problem

Hey guys, I met a problem in using VISA serial port communication module. I use arduino board to simply generate a number 350:

 

int value=350;

 

void setup(){


Serial.begin(9600);
}

 

void loop(){


Serial.println(value);
delay(250);

}

 

If you can watch the video, you can find that if I highlight execution and run the system, labview can receive data correctly. But if I don't highlight exection, labview goes wrong, sometimes it receives 350, sometimes it receives 50, sometimes it cannot receive anything.

And sometimes an overrun error occurred.

 

Could you please help me check where I made mistakes?Smiley Sad

 

video

0 Kudos
Message 1 of 11
(4,294 Views)
Your mistake is on the arduino end. Append a termination character and in the LabVIEW code, get rid of that bytes at serial port. Request some high byte count. Before the loop starts, do a read and discard. After that, your reads will be synchronized to the arduino writes.
0 Kudos
Message 2 of 11
(4,281 Views)

Hey Dennis, thank you for you reply! 

 

You mean I should add a termination character in the arduino code, and deal with that character in the labview?

 

And I can't exactly understand  what does "Request some high byte count. Before the loop starts, do a read and discard." mean. Can you figure it out?

0 Kudos
Message 3 of 11
(4,234 Views)
When the VISA Configure Serial Port has the Enable Termination Character set to true, a VISA Read will automatically terminate when the termination character is read. That means you can just set some byte count that is arbitrarily high. You don't need s query of the number of bytes available or any sort of a wait to make sure data is actually in the receive buffer.

The serial communication is asynchronous so you have no idea if you have a complete packet in the buffer. With the termination character there, you do a dummy read and the next one will be a complete packet.
0 Kudos
Message 4 of 11
(4,228 Views)

The arduino Serial.println() function is automatically followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'), in this case, how can I setup in the labview?

 

I know the problem is the termination character and the while loop, but I don't know how to fix itSmiley Sad

0 Kudos
Message 5 of 11
(4,219 Views)
Enable Termination Character, do a read outside the loop, do not use bytes at serial port, and read 100 bytes.
0 Kudos
Message 6 of 11
(4,201 Views)

OK I'll try this method! Thank you very much!

And a little confusing, if read data outside the loop, how can labview continuously collect data?

0 Kudos
Message 7 of 11
(4,192 Views)
The read outside the loop is the dummy read. You would still have a read inside.
0 Kudos
Message 8 of 11
(4,180 Views)

Oh! It works now!! Thank you very much Dennis! 

 

And a small question, here I use both "waveform graph" and "waveform chart", the chart works well, but there's nothing displayed on the "waveform graph", and I notice that the time(X-axis) doesn't change while running the system, can you tell me why?

Message 9 of 11
(4,152 Views)

A graph takes an array of data and plots it all at once. A chart has an internal buffer which accumulates the data fed to it one point at a time. Your graph probalby has one point but you may not see it unless you change the plot style to one which will make a single point visible. If you want to use a graph you will need to accumulate the points in an array, probably via a shift register of autoindexing.

 

You have X-axis autoscaling turned off on the graph. The first point is at x=0, which is off scale.

 

Lynn

0 Kudos
Message 10 of 11
(4,147 Views)