LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Questions on RS-232 interrupt handling

Hi,

I recently developped a program that retrives data over a RS-232 connection. The issue is that the frames are 20 bytes long and sometimes the last four ones are missing : the bytes are not in the buffer.

20 frame bytes - 4 missing bytes = 16 = UART internal buffer size.
Which means (I think) that sometimes the data are not transferd from the hardware buffer to the software buffer, or not fast enough.

The speed is important beacause com port is handled as a callback so it is in the event queue, and has to wait for all interface related pending events (graphs, file storing), before being processed.
The port readings are made using installcomcallback, using the LWRS_RXFLAG event detecting the first byte of the frame.

Moreover there is another issue : sometimes the event is beeing triggered, and the event character is not in the buffer. This is the situation that is descibed in the installcomcallback function panel help.

But since things were still going wrong we checked the input buffer size after a delay and the buffer now containes the character :
if (GetInQLen(Comport) == 0)
{
Delay(0.1);
if (GetInQLen(Comport) == 0) return 0; // Fake interrupt
// REAL interrupt (!)
}
Sometimes, interrupt with empty buffer are triggered, but if we wait a little and check again the buffer, it isn't empty anymore (!)

Here are the questions :
why the buffer is empty while a real interrupt is triggered ?
Is it possible to handle com port interrupts in an own thread (like ibnotify for GPIB), for faster response to byte arrival event, and interface independant processing speed ?
Is it possible to use functions that will not miss events or send two interrupts for the same event (ie : to overcome windows com port managment), or require a 100 ms delay for transferring a byte from a buffer to another place that is not so far away ?

The computer is a celeron 500 with 128 Mb ram, configuration : win 98, CVI 7.0. running after a fresh reboot with no other lauchned applications.

Pierre
0 Kudos
Message 1 of 2
(3,582 Views)
Hey Pierre,

The first thing that I would suggest is switching to NI-VISA programming instead of using the windows functions. After installing NI-VISA if you don't already have it, you should be able to find some examples on your computer at C:\VXIpnp\WinNT\NIvisa\Examples\C.

VISA supports serial port events and one of the events that you can setup monitors whether there are any characters at the serial port. I have used VISA for a long time and I have never see it give false events.

I have modified one of the shipping examples to include the WaitOnEvent.

In addition, NI is now offering some new high-performance serial boards with 128 byte FIFOs, if you think your first problem is caused by the size of your UART buffer size. These new serial cards
are extremely fast and should never drop packets.

Here are some additional links that might help out. I would also suggest checking out the VISA help.
http://sine.ni.com/apps/we/nioc.vp?cid=13693〈=US
http://www.ni.com/support/visa/vevents.pdf
http://www.ni.com/support/visa/vintro.pdf
http://digital.ni.com/manuals.nsf/websearch/F7580FBF1510A3FB86256E8A006C967A?OpenDocument&node=132100_US


I hope this helps out.

JoshuaP
National Instruments
0 Kudos
Message 2 of 2
(3,582 Views)