Discussion Locked

Detecting an Empty UART

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is there a way; through the Win32 API to detect that the UART has finished transmitting? I know there are bits in the UART line status register, and I could read them directly. This would work great for Win 95/98 but not on NT or 2000. Any help would be greatly appreciated.

9 replies

by peter ritchie

Silly question, by why aren't you simply using the WIN32 system functions to read/write from the serial port(s)? If done properly, you don't have issues when running 9X and NT/2000 like this.

by gheard

Which system functions? The API uses CreateFile, ReadFile, & WriteFile to talk to the ports with some random CommGet functions. But I can't see were I can get the UART status. I need to know when the UART finishes so that I can toggle the RTS line in an RS485 2-wire system.

by peter ritchie

Have you tried using the SetCommMask()/WaitCommEvent() functions to tell when data is finished being received?

There's also the GetCommState() function that will give you (en masse) the state of a serial device (or at least the ability to; whether or not the entire status is retrieved depends on the hardware/driver).

It's been a while since I've done any low-level serial I/O; but, when I was doing it, I recall having to wait for the events to tell whether data was complete or not. The events are sent when the status bits get toggled.

Generally, on a half-duplex port, CTS should be set if nothing is coming in. Theoretically; this should also be true for a full-duplex port--but, if it's full-duplex you an send data any time you want.

by gheard

Yes, I have looked at the Event functions, but the only event that comes close is the TXEMPTY event that fires when the last byte has been sent to the UART. It does not take into account how many bytes are left in the UART's FIFO or its shift register. Is there any references on using the interface to the serial device driver VxD VCOMM?

This discussion is closed to new replies.