Opening virtual serial port created by SOCAT with Qt

I am developing a Qt5 application on MacOS.

I would like to test communication with the serial port port.

I would like to use socat , but I cannot open the port created using socat: QSerialPortInfo :: availablePorts () lists only the ports / dev / cu-XXXXXX ...

+4
source share
3 answers

An example of creating a Socat port:

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

After that you will get your pseudo-port /dev/mytty

Now you can refer to this port through QSerialPort

serial = new QSerialPort("/dev/mytty");
+2
source

You may have problems due to the symbolic link.

You can 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);

QSerialPortInfo .

+1

Perhaps this is just a resolution issue. Verify that the user running the application has permission to access the virtual port.

0
source

Source: https://habr.com/ru/post/1527607/


All Articles