07-13-2009 11:06 AM
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:
07-13-2009 11:12 AM
07-13-2009 11:20 AM
Hi maruthven,
do you need the "m" only ones or before every block of data?
Mike
07-13-2009 11:37 AM
07-13-2009 01:25 PM
07-13-2009 05:09 PM
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?
07-13-2009 06:48 PM
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.
07-13-2009 06:56 PM
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.
07-13-2009 06:59 PM
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.