LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial overrun error -1073807252 even after a flush and bytes at port less than buffer limit

I have a device that continuously sends data over the serial port and a VI that records that data for a period then stops when commanded. When i start a new data collection run i want to clear whatever is in the read buffer before collecting the new data.

However, I can't find a way to avoid the buffer overrun error other than to watch for it and clear it, which seems like a work around not a clean way to do things. This must be a fairly common usage of serial communication so i'm hoping there is a technique i'm missing.

I've tried several things but among them is using flush at the start of each data collection run which seems to work fine itself, but then the read will throw an overrun anyway even though there is nowhere near a buffer overrun and no error from previous blocks. It's also odd that there is still several hundred bytes available immediately following a flush.

I'm attaching the the VI which is actually much bigger and more complicated than what i'm positing but i pulled out all the stuff that isn't serial related. You won't be able to run it because you won't have the right serial device with the right packets, but perhaps someone will see something obvious in my serial setup or read that might solve this problem.

the Bytes at Port Start is what was seen at the port before the flush

the Bytes at Port for Read is then what is available for the data i want to keep.

Untitled picture.pngUntitled picture2.png

0 Kudos
Message 1 of 11
(5,269 Views)

I would recommend an architecture where the serial communications are in a separate loop and it sends data as needed to the other part of your code.  That way it is always ready to grab the messages that come in and doesn't get delayed and have serial buffer overruns.

 

What IS causing the delays in your code that keep the serial port from being processed in a timely manner?  Why not make sure that the serial port is being processed frequently?

 

Why not shut down the serial port when you don't want to read it, then reopen it when you are ready to read from it again?

0 Kudos
Message 2 of 11
(5,245 Views)

Yes, from when you checked the Bytes At Port to the Flush Buffer, your port received enough data to overrun the buffer.

 

1. Move your reading of the port to another loop that runs in parallel with your main loop.  This way the port can be constantly read without interfering with your main loop.

2. You really should not use the Bytes At Port.  Use the protocol of the serial data.  It looks like you are dealing with binary data (not ASCII), so do make sure you have the termination character turned off.  Now the next question is "What is the structure of the data being sent?"  Binary data typically has a structure that includes a start byte, a command code and/or message length, data, and some kind of checksum.  So what is the exact protocol your device is sending data to you?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 11
(5,220 Views)

Thanks for the recommendations, sorry for the long delay in response, i've been travelling and not had a chance to follow this up. The reason the serial buffer is not always being processed is that I periodically stop the data collection in between test runs for indefinite times, but leave the serial port open so that i can still write commands to change setting of the device. I've since started to re-code the VI to open and close the port only when reading or sending data so the buffer will not overrun.

Initially i was afraid constant opening and closing of the port would have a significant time delay influence, but i'm suspecting now that may not be a concern in this application.

0 Kudos
Message 4 of 11
(5,180 Views)

Just another note on the buffer overrun after I've flushed it, I've counted the bytes and it does not exceed the buffer limit however it still gives an overrun error originating from the post flush read attempt. Maybe that error is still propagating from the original overrun, but seems odd. See in the picture below that the buffer was indeed overrun before the flush with 4065 bytes, but the next read only had 641 bytes, less than the max buffer size, and the error starts after that 2nd read. This is the behavior that didn't make sense and was the impetus for my original question. Though now is a bit moot as I've taken the suggestions to open and close the port. I will also look at using a separate loop to run serial in the future. 

Untitled picture.png

0 Kudos
Message 5 of 11
(5,176 Views)

Hi,

Have you managed to resolve your issue? It seams that I am getting same one and cant get rid off it...

Thanks

Franjo

 

0 Kudos
Message 6 of 11
(5,134 Views)

Don't use shift registers on error wires.  If you aren't handling errors properly, the error will get passed back to the beginning of the loop and cause problems there ever after.  Serial communications are likely to have spurious errors,  timeout here,  buffer overrun there.  Stuff you don't want to have happen, but certainly not unexpected.

 

Get rid of the shift register, or do something to clear specific errors before you send them to the shift regiter.

0 Kudos
Message 7 of 11
(5,129 Views)

My problem is very intermittent, sometimes my serial communication works for hours without any problem and sometimes it does not start at all.

If it doesnt start I am getting errors -1073807252,1073807253 or 1073807232 and whatever I do (open-close connection, flush-clear buffers, VISA Unmap address) errors are all the time coming back and instead of reading 200 bytes, VISA read gives me only 16 bytes.

I also tried setting RXFIFO = 1 (as per https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019M1hSAE).

 

My initial CPU usage was 80%  and error was happening in about 40% of cases, but after I prepared test application and reduced CPU to less than 50% I am still getting an error but little bit less often, something like 20%.

I am using cRIO-9024 with chassis 9118 and LabVIEW 2011 SP1.

 

Regards

Franjo 

 

0 Kudos
Message 8 of 11
(5,126 Views)

You should start your own thread and attach your VI so we can see if their are any program errors.

0 Kudos
Message 9 of 11
(5,121 Views)

It is quite a big and spread code and I already tried many different things so it got very ugly.

I will try to make it a bit nicer and post in separate thread. I have no idea what causes errors after startup and why is it not possible to clear them!

Thanks 

Regrads

0 Kudos
Message 10 of 11
(5,112 Views)