Home:ALL Converter>Getting DTR and RTS pin of serial port in C on Windows platform

Getting DTR and RTS pin of serial port in C on Windows platform

Ask Time:2019-12-19T19:02:14         Author:Fifi

Json Formatter

How to get DTR and RTS status of serial port on a windows platform? I want to read the current state (ON or OFF) of these two pins.

I can set pins with :

EscapeCommFunction(hSerial,SETRTS);

But I don't know how to read the pin status.

Since on Linux, it can be done with the following code, I assume it is technicaly feasable:

int status=0;
ioctl(fd, TIOCMGET, &status);
return status & TIOCM_RTS;

Author:Fifi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59408368/getting-dtr-and-rts-pin-of-serial-port-in-c-on-windows-platform
Mr Robot :

Using inc\\api\\ntddser.h API and winioctl.h, you can access DTR and RTS status. Call DeviceIoControl, set the second parameter to IOCTL_SERIAL_GET_DTRRTS:\n\nCall: \n\nDeviceIoControl(\n handle, // handle returned by CreateFile\n IOCTL_SERIAL_GET_DTRRTS,\n NULL,\n 0,\n &Status, // pointer to a DWORD variable 1\n sizeof(Status),\n &unused, // pointer to a DWORD variable\n pOverlapped // optional pointer to overlapped buffer (may be NULL)\n);\n\n\nDocumentation about DeviceIoControl here.",
2019-12-29T06:02:25
yy