c++ - USB2Serial 的 Linux IOCTL

标签 c++ linux serial-port linux-device-driver usbserial

我正在 Linux 上用 C++ 开发一个程序,它与 USB2Serial 适配器交互以从远程终端获取一些信息。我能够使用以下代码在 Windows 上将其设置为 IOCTL:

 #define IOCTL_SERIAL_XOFF_COUNTER       CTL_CODE(FILE_DEVICE_SERIAL_PORT,28,METHOD_BUFFERED,FILE_ANY_ACCESS)

unsigned char xoff_counter[] = {0xd0,0x07,0x00,0x00,0x05,0x00,0x00,0x00,0x13,0x00,0x00,0x00};

        bool result = DeviceIoControl(file,IOCTL_SERIAL_XOFF_COUNTER,
                                        &xoff_counter, sizeof(xoff_counter),
                                        NULL,0,
                                        &junk,
                                        &o);

我尝试使用以下代码在 Linux 上做同样的事情:

#define SERIAL_XOFF_COUNTER 28

unsigned char xoff_counter[] = {0xd0,0x07,0x00,0x00,0x05,0x00,0x00,0x00,0x13,0x00,0x00,0x00};

int retVal = ioctl(fd,SERIAL_XOFF_COUNTER,xoff_counter);
            if(retVal < 0){
                cout << "Error while setting ioctl:"<<strerror(errno)<<endl;
            }

当我运行该程序时出现错误:

Error while setting ioctl:Inappropriate ioctl for device

如果有人以前使用过这些 ioctl,请告诉我这个标志的 Linux 等效项是什么。
TIA!

最佳答案

在 Linux 中没有串行 ioctl。该 ioctl 特定于 Windows 串行驱动程序。 XON/XOFF 协议(protocol)没有定义计数器,所以我无法想象这是用来做什么的。 (也许 Windows 正在计算接收到的 XOFF 字符数,但这只是一个推测)

请参阅 linux 的 termios(3) 手册页以查看为 rs232 终端控制定义的 ioctl。

关于c++ - USB2Serial 的 Linux IOCTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31579620/

相关文章:

c++ - 如何将字符串解析为 ctime 结构?

mysql - 根据日期名称每天备份mysql数据库

c++ - 获取其他模块访问变量的路径

c++ - 如何以编程方式启动程序并在 Linux 上以 root 权限运行它?

linux - 在cshrc中执行别名

c++ - asio::read with timeout

linux - 命令行配置 TTY 设备

c# - 如何从串口读取和写入

.net - 先学什么——C++/STL/QT 或 .NET/C#——如果我的学习和工作时间有限?

c++ - #ifndef FILENAME....#endif 在头文件中的用途