01-19-2018 09:37 AM
Hello all,
I am currently writing a basic program to read in results from an oxygen sensor that communicates via serial connection. In my current code, I keep getting an overrun error after a few times of running the program. Any suggestions as to how I can fix it? Thank you!
Solved! Go to Solution.
01-19-2018 09:46 AM
How fast is the device sending data?
Why are you using a timed while loop?
It is set to run once every second. If your device is sending data faster than once were second, then eventually the buffer will fill up. Use a regular while loop and don't put any timing functions in it as the communicating device will control the speed of the loop based on how fast it is sending data.
01-19-2018 10:04 AM
Baud Rate: 38400
Data Bits: 8
Parity: None
Stop Bits: 1
Flow Control: None
The device sends an update every 10 seconds, I used a timed loop with a case structure so that it calls the Read vi every 11 loops (11 seconds, 1 extra second just to be safe), also, I have the timed loop set to 1 second so that it updates the counter gauge every seconds indicating how much longer until the next measurement.
01-19-2018 10:05 AM
Also, replacing the timed loop with a while loop does nothing to help:
01-19-2018 10:59 AM
Have you tried changing the structure of your program to a Producer/Consumer design? If not, check out Application Design Patterns: Producer/Consumer.
01-19-2018 11:34 AM - edited 01-19-2018 11:36 AM
Your whole concept of VISA read is incorrect. The VISA read will just sit there doing nothing until it either gets data or times out. Don't try to control the timing of the while loop; just let the VISA read do it for you. (Increase the timeout because I think it defaults to 10 seconds.)
Do you know what to expect from your equipment? Do you know if the data ends with a termination character? Knowing this will definitely influence the design choices that you make, and possibly even cause the error.
01-19-2018 12:15 PM
How much data is it sending?
How long does it run before the error pops up?
Put a Bytes at Port Property node in there with an indicator to see if the port is filling up. Wire it up to a waveform chart to make it more obvious if it is growing in time.
Also, be sure you aren't using execution highlighting which artificially slows down the loop
I don't see how you would be getting a problem in the latest VI you posted a screenshot of unless that device is not communicating the way you think it is.
01-19-2018 12:36 PM
@Gryffin wrote:
Also, replacing the timed loop with a while loop does nothing to help:
1) What do you see in the "read Buffer" string indicator?
2) my money is on either wrong baud rate OR garbage on the line.
Ben
01-19-2018 12:42 PM
Just needed a Flush Buffer at the beginning, everything works fine now, thanks for the quick replies
01-19-2018 12:47 PM
I think the real problem is that you never close the serial port.
If the serial port was closed, you wouldn't need a flush buffer because you are starting to read from it right after you configure and open it.
HOWEVER, you never close the port in your VI. So if you stop the VI and restart it, the port will have remained open and the buffer accumulating bytes until it overflowed which you'll find out once you restart the VI.
You can leave the flush buffer in, but be sure to wire a VISA Close in before the VI ends.