简体   繁体   English

在Qt / C ++中创建虚拟串行端口

[英]Create virtual serial port in Qt/C++

I would like to create a linux app which appears as a serial port (eg /dev/ttyTEST). 我想创建一个显示为串行端口的Linux应用程序(例如/ dev / ttyTEST)。 This app will listen for commands sent to the port, and respond back. 此应用程序将侦听发送到端口的命令,然后进行响应。

Is this possible using Qt/C++ ? 使用Qt / C ++可以吗? I haven't done kernel programming so I'm hoping this is possible in user space. 我还没有完成内核编程,所以我希望在用户空间中做到这一点。

Everything depends on what the application using such device expects. 一切都取决于使用这种设备的应用程序的期望。

If /dev/ttyTEST is to behave like a real serial device and respond properly to all ioctl's that set its speed etc., then this can't be done from userspace. 如果/dev/ttyTEST的行为类似于真实的串行设备,并且对设置其速度等的所有ioctl做出正确的响应,则无法从用户空间完成此操作。 It wouldn't be too hard to implement in the kernel space, though. 不过,在内核空间中实现它并不难。

If /dev/ttyTEST only needs to be a tty, then provide a pseudo tty . 如果/dev/ttyTEST仅需要是tty,则提供一个伪tty

If /dev/ttyTEST is merely to be something another application can write to and read from then socketpair() does it . 如果/dev/ttyTEST仅是另一个应用程序可以写入和读取的内容,则socketpair()可以做到

If you have control over the application's code, then you can have it check whether the device is a socket pair or a real character device, and ignore the failures of the serial-port-specific APIs on a socket. 如果您可以控制应用程序的代码,则可以让它检查设备是套接字对还是实字符设备,并忽略套接字上特定于串行端口的API的故障。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM