Can low-level control RS232 (Com-Port) RTS / CTS / DTR / DSR?

It is interesting how and how to manage RS-232 communication lines directly with win32 (old C-API).

I would like to interact with external hardware, and for my needs two simple data lines would be enough.

So, is there an API for win32 that allows me to read and write the status of four status bars? In a normal serial connection, handshaking lines automatically start UART (if hardware handshaking is enabled).

I remember that it was trivial in DOS. You just need to program UART directly. Was this function preserved in win32 somehow?

+6
winapi embedded serial-port handshaking
source share
5 answers

You can control RTS and DTR with SetCommState() . You can also configure hardware or hardware flow control for hardware (CTS and / or DSR), or you can configure it using SetCommMask() so that you receive events when these signals change.

A nice review here: http://msdn.microsoft.com/en-us/library/ms810467.aspx

Please note that the Win32 Serial Comm API and / or driver can be quite sophisticated, so be prepared for some debugging of what is happening on the wire.

+5
source share

I came across this tutorial when I had to do a project to communicate with the RS232 port. This is a complete example of how to open a port, set some properties, including timeouts, read / write, and close a port. Although your project has probably already been completed, I hope this remains useful as it remains in the SO archives.

+2
source share

You can still do these types of programming only to access the protected equipment that you will need to implement the device driver. I guess it got easier since the 1980s when I was doing the same type of work.

0
source share

Is microsoft actually a hardware handshake now? Over the years, NT, win2000, and XP did not acknowledge hardware. Instead, when fifo reaches a certain point, the device driver will manually change the cts line. This means that it was incredibly simple to make the device driver lose data, capture the window with the mouse and, for example, make circles around the screen (make sure you remove this window on the left side of the screen in all or some passes). Alt-enter to enter the command line to / from full screen mode was an easy way to cause data loss. Or anything else that causes a sufficient interrupt delay. Basically, Microsoft's hardware flow control is not hardware, but software flow control, even if the hardware has hardware flow control capabilities, the microprocessor drivers did not set this bit. SeaLevel, after all, supported this bit, well, please, you had to set the correct unrelated settings in SetCommState () to enable it.

For your signal control program, use SetCommState ().

0
source share

There are several USB adapters for the serial interface that do not support DTR / DSR / DCD flow control. So maybe this is your case.

http://www.digi.com/support/kbase/kbaseresultdetl?id=588

0
source share

All Articles