PDA

View Full Version : QSerialPortInfo get all available port in Linux and Mac



Nekyz
7th October 2013, 14:59
Hello,

I have a FTDI, USB to Serial connected to my own device, I try to list all port (as I can have multiple device connected), open a communication port & send data to my device.

I have no problem for communicating on Windows, but on Linux & Mac I can’t get the informations on my serial port.

This is the code I used to show port :


QStringList SerialPortChannel::availablePorts()
{
QStringList ports;

for (QSerialPortInfo port : QSerialPortInfo::availablePorts())
{
//Their is some sorting to do for just list the port I want, with vendor Id & product Id
qDebug() << port.portName() << port.vendorIdentifier() << port.productIdentifier()
<< port.hasProductIdentifier() << port.hasVendorIdentifier() << port.isBusy();
ports += port.portName();
}
return ports;
}
This is the my class constructor where I open the port :


SerialPortChannel::SerialPortChannel(QString port)
: QObject()
, m_port(port)
{
online = m_port.open(QIODevice::WriteOnly);
if(online)
qDebug() << "Connected to : " << port;

//Configure the port
m_port.setBaudRate(QSerialPort::Baud115200);
m_port.setDataBits(QSerialPort::Data8);
m_port.setStopBits(QSerialPort::OneStop);
m_port.setParity(QSerialPort::NoParity);
m_port.setFlowControl(QSerialPort::NoFlowControl);

}
This work well on Windows, I can see my port.

On Linux (Tested on Ubuntu 13.04 & Mint 15 Olivia ) : I can see my device with some name like : ttysUSB0, but any other informations like vendor id and product id are null. I can’t open a communication, open return false. I have all informations listed on my OS, so it’s a bug in my application.

On Mac (10.8.5) , I can’t even see the name and all others informations, but the device is connected to my Os as I can see him in the system info panel.

What did I do wrong ? Is it something to configure on Linux or Mac ?

kuzulis
7th October 2013, 15:15
Hi.


On Linux (Tested on Ubuntu 13.04 & Mint 15 Olivia ) : I can see my device with some name like : ttysUSB0, but any other informations like vendor id and product id are null.

Most likely your QtSerialPort is built without libudev. In this case will be enumerated all tty devices from an /dev directory without any additional info (exclude port name and location string).

So, you should build with the libudev support. Besides, in the current Git repository of QtSerialPort (will be present in Qt5.2) this problem is corrected and the additional information will be derived from the sysfs if libudev isn't present. But in any case - use of libudev is more preferable.


I can’t open a communication, open return false.

It is strange, because you have an port name, so no any problem is expected... Hmmm..

Please provide a more info: what error code returns the open() method? maybe you have no rights to open device?



On Mac (10.8.5) , I can’t even see the name and all others informations, but the device is connected to my Os as I can see him in the system info panel.


Hmm.. It will be a problem.. Because we (developers of QtSerialPort) has no MacOSX.. To fix it.. :(
Seems, it is a QSerialPortInfo bug.

You can create a bug in a bug-tracker...
Or help to us for resolve this problem by try debugging of QSerialPortInfo, then we can quickly fix it.. :)

Nekyz
7th October 2013, 15:29
Thanks for the fast reply.

How can I know if my Qt is build with libudev ? Because I have libudev installed on my Ubuntu when I installed the Qt package.

For the opening it was actually a permission problem, I try as root and all worked fine. Thanks !

I'll try to find more informations about the MacOSX bug, and give you all informations.

kuzulis
7th October 2013, 15:58
How can I know if my Qt is build with libudev ? Because I have libudev installed on my Ubuntu when I installed the Qt package.

1. You can download QtSerialPort sources, open it's project file qtserialport.pro from an QtCreator. And then you can see highlighting for the macro HAVE_LIBUDEV in qserialportinfo_unix.cpp file.

2. If this macro block will be active, then QtSerialPort sources now will be compiled with an libudev support. So, you need re-build QtSerialPort and re-install it.

3. If this macro block will be inactive, then you should install on your Ubuntu the libudev-devel packages (or something) and repeat from the step #2.


PS: If you use an QtSerialPort package from an Ubuntu's repo - then, seems, that Ubuntu's maintainers do a wrong package! :)