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;
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