From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa Serial port read problem from microcontroller device.

serialport.png

Hi

i,m trying to communicate with a microcontroller based device.However i'm facing problems.

by default when i send the string "5N" to microcntoller from any serial terminal(like hypertrminal), the microcontroller based device responds with the
following string.
"1111111111111111111111111E"

this works fine while using hyper terminal.now i want to parse the data from device using Labview.so i created a vi to send 5N and to read out the data from device.But the problem is that it works only sometimes.i have noted that when the vi is executed 1st time in a row, it writes the data, but fails to read the data.the program never exists the loop. then i press abort and run vi again,this time it writes as well read successfully. id dont know what is the problem. check the attached vi. please help. sometimes it shows time out error (but time out set is enough). by the way is it neccessary to send \n\r after each string from the device to labview and viceversa. is there any problem with my loop & open and close visa functions

Electronics and Instrumentation Engineer
Freelance LabVIEW and Arduino programmer.
For projects contact me ; djac791@gmail.com
0 Kudos
Message 1 of 4
(4,426 Views)

One thing I can't figure out is why you open, delay, write and wait for the first character to be available then read just the number of characters that showed up in the most recent 20mSec.  Especially when you have what appears to be a deterministic means of identifying end of message (\r)

 

First get rid of the Open VISA (Its not needed an may be clearing the serial port configuration settings)

Next, Enable the term char (\r) and read until term char is seen.

fianally, stop reinitiallizing the session every time you want to do a query (this clears the buffers and you lose data)

 

 

Search the shipping examples for basic serial write and read.vi


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 4
(4,415 Views)

Please check with following

 

https://decibel.ni.com/content/docs/DOC-16283

https://decibel.ni.com/content/docs/DOC-16642

 

Regards,

Prabhakant

Regards
Prabhakant Patil
0 Kudos
Message 3 of 4
(4,413 Views)

Please keep your questions in one thread.  Having the same question in multiple places results in fragmented responses because not everyone watches all the boards.

 

1. It is generally better to configure the serial port, then read and write many times in a loop, followed by closing the port after all communication is finished. Repeatedly configuring and closing the port is asking for trouble.

2. Learn about dataflow. Only the frames of the seqeunce structure containing the Waits are required.

3. The Bytes at Port loop is not doing what you expect. It appears that your response string has 26 characters. Does it also include carriage return and line feed like the transmit string? At 9600 baud, 1 start bit, 8 data bits, and 1 stop bit it takes >27 ms to transmit the message. So almost always the while loop will exit with less than a complete message available.

4. With Byte Count set to 1000 the Read VI will wait until it has 1000 characters or until timeout occurs. It seems likely that timeout will win.

5. You suggest that the microcontroller is also sending carriage return line feed at the end of its messages. If so, then get rid of Bytes at Port completely and use line feed as termination character. If carriage return can ever occur in the data not followed immediately by line feed, then some additional testing is required.

6. Bytes at Port and a large Byte Count value are inconsistent and will cause problems. See 3, 4, and 5. If you use Bytes at Port, the byte output should be wired to the Byte Count input of Read. If you use a termination character, then wiring a large value to Byte Count is appropriate.

 

Are you using Continuous Run to operate your VI? STOP! Continuous Run is only for limited testing during development. Use the Run button and have a while loop which contains all the code to be repeated. Include a Stop button on the Front Panel. Stopping with the Abort button in the toolbar will not close the port.

 

Lynn

Message 4 of 4
(4,409 Views)