Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

RS-232 Serial communication problems at higher baud rates. HELP!

First off, I am VERY new to LabVIEW. Im am writing a VI which communicates with an arduino microcontroller system. The system contains 2 microcontrollers which read sensors for LabVIEW indicators and control stepper motors based on the user input. This means that the VI reads and writes to the COM port that is opened. I modeled the serial interface from the "Basic Serial Read and Write" VI. Initially, the serial communication used was only 9600bps and everything worked great! However, i discovered that the delay in writing serial information from the microcontroller to LabVIEW at 9600bps causes the stepper motors (controlled by the controller) to spin extremely slowly. This was solved by increasing the baud rate, as then the time between serial output was much shorter causing less delay between stepper motor steps and increasing the motor speed. GREAT! Right? NO...LabVIEW can still read everything, however it lags greatly at the higher baud rates. All the serial information is delayed and tries to "catch up" but is never consistent with sensor value as they are changing. Whats up? I tried to add a serial buffer, but that seemed to make it worse, even at low baud speeds. The received string was broken up, and only parts of it were received at a time, causing my parser to output intermittent and eradic results.

 

I have the serial setup to terminate on the "\n" character. The sensor formatting is:

"SA:[integer value];SB:[integer value];SC:[integer value];SD:[integer value];DX:[integer value];DY:[integer value];\n"

I have the Com port configuration set to terminate on the "\n" character.

 

I did see examples that showed the COM configuration, a property node (which i do not understand very well) and the Buffer outside the main loop, but when i tried this i received garbage! ...Like the baud rates were different between the arduino and LabVIEW. See example i tried below:

 

 

 

So now im at a loss. I included my VI. Please be gentle as some parts my seem silly. It was made in version 8.5. Any help would be GREATLY APPRECIATED!

THANKS!

-Ryan

0 Kudos
Message 1 of 5
(5,405 Views)

DigitalMagZ,

 

The code you attached configures the serial port inside the while loop.  This means that each time your while loop executes it reconfigures the serial port.  Please instead try moving this portion of the code outside the while loop.  The code you attached seems to be different than the screen shot that you posted.  Let us know if I missed something or if the attached code is not the code in question.

 

Regards,

 

Sam K

Applications Engineer

National Instruments

0 Kudos
Message 2 of 5
(5,353 Views)

The screen shot was what i was using to modle the code that i am writing. I did move the port configuration, property node and buffer outside the main loop (like the screenshot) and am get consistant readings. I do notice that when i increase the baud rate (to 115200bps) there is lag if the transmission is delayed slightly. I thought that the buffer would take care of this.  

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

Are you just streaming data from the Arduino to LabVIEW?  Or are you trying to transmit and receive data as it is being sent?

Zach C.
Field Engineer
Greater Los Angeles

0 Kudos
Message 4 of 5
(5,318 Views)

No, i am first transmitting information (if needed, otherwise there is not transmission), then recieving data from the arduino. If ther is no transmission to the arduino, it just keeps reading from the port. The problem is when i increase the baud above 115200 and change the frequency of the transmission, I get a great deal of lag. I thought the buffer would solve this issue.

0 Kudos
Message 5 of 5
(5,312 Views)