Opening a virtual serial port created by SOCAT with Qt

浪尽此生 提交于 2019-12-23 09:29:12

问题


I'm developping a Qt5 application on MacOS.

I would like to test my application serial port communication.

I'd like to use socat but I'm unable to open the port created with socat: QSerialPortInfo::availablePorts() lists only the /dev/cu-XXXXXX ports...


回答1:


Socat port creation example:

socat  pty,link=/dev/mytty,raw  tcp:192.168.254.254:2001&

After this you get your pseudo port /dev/mytty

Now you can reference this port via QSerialPort

serial = new QSerialPort("/dev/mytty");



回答2:


You might be having troubles because of the symlink.

You could try something like this:

QFileInfo file_info("/dev/mytty");
QSerialPort* serial = nullptr;
if (file_info.isSymLink()) {
  serial = new QSerialPort(file_info.symLinkTarget());
} else {
  serial = new QSerialPort(file_info.path());
}
serial->open(QIODevice::ReadWrite);

You could also construct a QSerialPortInfo class with those paths instead of creating a port directly.




回答3:


Maybe it's just a permission issue. Make sure the user running your application has permition to access the virtual port.



来源:https://stackoverflow.com/questions/21867628/opening-a-virtual-serial-port-created-by-socat-with-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!