01-20-2009 06:16 PM
Serial Port Woes
Hi all:
I have been playing with LV VISA VI since LV6.0 now with no problems. Well, that is until this week. I have to stream about 50kb of data via serial port. Through “Bytes at Port”, I see the data there (40000+bytes). But when I tried to read it using standard VISA Read, an error comes up (code -1073807252, explanation: An overrun error occurred during transfer. A character was not read from the hardware before the character arrived.)
Basic Info: 115200, 8, None, 2 (Baud, data bits, parity, stop bits). These numbers are not standard but they were provided by the factory.
I tried playing with various buffer settings (using different I/O buffer sizes), adding more time between writes and reads, enabling/disabling termination characters (it does not use it). Nothing works.
Please help,
Santiago
01-20-2009 07:53 PM
As it says, you have a buffer overrun error. Data is coming in faster than you can read it. 115,200 baud is a pretty high rate, as well as having 40,000+ bytes in the buffer at a time. At 115,200 baud, you would have approximately 10,473 bytes per second coming in. So 40,000+ bytes is about 4 seconds worth of data.
In the loop where you read the serial port, do you have anything else going on? Logging to data file, complicated data analysis?
What is the data and why do you need to transfer it so fast?
01-20-2009 08:22 PM
Raven:
I am working with a Interrogator for fiber optic applications. Baud Rate is standard for the device.
As for Logging to Data file/complicated Data analysis...no. I am basically trying to concatenate all incoming data in shift register to then sent it out to process on a separate VI. The DAQ format is Write (issue of command), Read (Read Command), and Process (Parsing), in that sequence. The next write and read is not issued until data parsing is finished.
I think the issue might be in Set I/O and Flush I/O Buffer. In your opinion, what should the size of my buffer be? Am I right to assume that I only need to set the bufffer once during initialization?
Best,
Santiago
01-21-2009 12:18 AM
Correct. You only set the buffer once. Doing it repeatedly will just slow down the loop.
So the data is not coming in continuously, you just send a command and then read the data, correct?
How much data is the device sending? You need to set the serial buffer to be larger than that. There should be no need to flush the buffer as long as you read in all the data. 40-50 thousand bytes is a lot. The question then is whether the size of the serial port buffer can be set large enough to handle it. Does the hardware offer handshaking to prevent the overrun of the buffer?
If it was a matter of continuous data or that you couldn't keep up with the data coming in, then I was going to suggest a producer/consumer architecture so that the time consuming part of the process could be passed off to a parallel loop.
01-21-2009 12:07 PM
Raven:
The device is sending about 45-48k of data at the time, upon request. Yes, the Data only comes after each command. Unfortunately no handshake/flow control is offered by the device. At this point I do not think the producer/consumer structure will help, because the overrun error occurs on the first read after the command is sent.
The flow is as follows:
Initialize Serial Port
Send command
While loop
{
Bytes at port
VISA Read (Number of Bytes at port)
Append string to previous if Bytes at port >0
Continue loop if Bytes at port >0
}
Anyway you bring up a good point. What determines “whether the size of the serial port buffer can be set large enough to handle it”. How can I verify this?01-21-2009 12:33 PM
01-21-2009 01:13 PM
FightOnSCTrojan wrote:Anyway you bring up a good point. What determines “whether the size of the serial port buffer can be set large enough to handle it”. How can I verify this?
I would just try to use the set buffer size function to set it to a large enough number and see if LabVIEW raises an error when you do it.