LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Port Locking Problem

I am having problems with reading from the serial port. My program runs some times, but other times it has problems. It keeps on locking up.

 

What the program does is writes a 'b' to the serial port to start the program to send the information about all of the sensors. Then, it looks for 'm' which indicates the starting of the data coming in. If it doesn't read 'm', it doesn't do anything. After the done control is hit, the while loop closes, and continues onto closing the serial port. Any help would be appreciated. 🙂

The program:

MainVI.jpeg

0 Kudos
Message 1 of 9
(3,412 Views)
And which help you wish here?
0 Kudos
Message 2 of 9
(3,407 Views)

Hi maruthven,

do you need the "m" only ones or before every block of data?

 

Mike

0 Kudos
Message 3 of 9
(3,400 Views)
And does the 'b' require a termination character such as a CR or LF?
0 Kudos
Message 4 of 9
(3,394 Views)
I wrote the program for the microcontroller, and it only looks for a 'b', and no CR.
0 Kudos
Message 5 of 9
(3,373 Views)

Are you using an FTDI chip by any chance?  What does it do when it locks up (is the VI frozen, or still running), and how have you unlocked it?

0 Kudos
Message 6 of 9
(3,347 Views)

I'm using an Arduino chip, which is an FTDI chip

 

By locking up, I mean that the program doesn't return any values, and the stop button doesn't exit the while loop. But, the program still responds. And to close the program I have to hit the big stop button at the top. 

To check that the device was still outputting data, we used RealTerm to view the serial port, and it worked fine.

0 Kudos
Message 7 of 9
(3,338 Views)

I think it's a Request->Answer Protocoll, so you can exit the loop if you received your data (so if the case is true).

Much better is to request the data with "b" and parse the answer once (without a loop). Don't forget to flush the buffer before.

0 Kudos
Message 8 of 9
(3,334 Views)

How long are you waiting for the stop button to work?  In your code, the stop button will be read pretty much at the beginning of the loop.  So, if you don't get a response, you will get a timeout.  Since you didn't wire the value in your Serial init, thats 10 seconds.  And since the stop button was already pressed, the loop will run again and timeout again and take another 10 secs.  So, it could take up to 20 secs, depending on when you hit the stop button for it to respond.

 

WHen you send the b command, does the device return m and the bytes continuously, or do you need to send the b command again?  YOur code sends b once and assumes m and data comes back continuously.

 

Also, you should use a typecast on the string you read to cast it as U32's instead.

0 Kudos
Message 9 of 9
(3,333 Views)