Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a virtual serial port created by SOCAT with Qt

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...

like image 542
Martin Delille Avatar asked Feb 18 '14 23:02

Martin Delille


2 Answers

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");
like image 170
yegorich Avatar answered Sep 28 '22 00:09

yegorich


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.

like image 29
photex Avatar answered Sep 28 '22 00:09

photex