windows - 在Windows平台上的C中获取串行端口的DTR和RTS引脚

标签 windows serial-port windev

如何在Windows平台上获取串口的DTR和RTS状态?我想读取这两个引脚的当前状态(ON或OFF)。

我可以用设置销钉:

EscapeCommFunction(hSerial,SETRTS);

但是我不知道如何读取引脚状态。

由于在Linux上可以通过以下代码完成,因此我认为这在技术上是可行的:
int status=0;
ioctl(fd, TIOCMGET, &status);
return status & TIOCM_RTS;

最佳答案

使用 inc\api\ntddser.h API和winioctl.h,您可以访问DTR和RTS状态。调用DeviceIoControl,将第二个参数设置为IOCTL_SERIAL_GET_DTRRTS:

称呼:

DeviceIoControl(
    handle, // handle returned by CreateFile
    IOCTL_SERIAL_GET_DTRRTS,
    NULL,
    0,
    &Status, // pointer to a DWORD variable 1
    sizeof(Status),
    &unused, // pointer to a DWORD variable
    pOverlapped // optional pointer to overlapped buffer (may be NULL)
);

有关DeviceIoControl here的文档。

关于windows - 在Windows平台上的C中获取串行端口的DTR和RTS引脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59408368/

相关文章:

c++ - 如何在 C++ 中调用::CreateProcess 来启动 Windows 可执行文件?

C++、Windows 服务和 msvcp140.dll

macos - 强制使用特定驱动程序的无代码 kext (CDC-ACM)

api - Trello 如何添加附件

database - 如何打开 Windev HFSQL Fic 文件

windows - 关于进程访问权限的问题

windows - 环境变量 'ORACLE_UNQNAME' 的 Oracle 问题

python - 属性错误: module 'serial' has no attribute 'Serial'

c# - 用于串口数据处理的线程抛出 "This BackgroundWorker is currently busy and cannot run multiple tasks concurrently"

http - oauth2 错误 AADSTS90014 : The request body must contain the following parameter: 'grant_type'