Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Low-Level control of RS232 (Com-Port) RTS/CTS/DTR/DSR possible?

I wonder if and how it's possible to control the RS-232 handshaking lines directly from win32 (the old C-API).

I'd like to interface with an external piece of hardware, and two simple data-lines would be sufficient for my needs.

So - is there a API for win32 that lets me read and write the state of the four status lines? In normal serial communication the handshaking lines are driven by the UART automatically (if hardware handshaking is enabled).

I remember that it was trivial under DOS. One just had to program the UART directly. Has this functionality survived in win32 somehow?

like image 601
Nils Pipenbrinck Avatar asked May 04 '09 16:05

Nils Pipenbrinck


1 Answers

You can control RTS and DTR using SetCommState(). You can also set things up to have hardware or the driver handle hardware flowcontrol (CTS and/or DSR), or you can set things up using SetCommMask() so you get events when those signals change.

A decent overview is here: http://msdn.microsoft.com/en-us/library/ms810467.aspx

Note that the Win32 Serial Comm API and/or driver can be finicky, so be prepared to have to do some debugging of what's going on on the wire.

like image 115
Michael Burr Avatar answered Oct 03 '22 12:10

Michael Burr