Results 1 to 4 of 4

Thread: QSerialPortInfo get all available port in Linux and Mac

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QSerialPortInfo get all available port in Linux and Mac

    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 :

    Qt Code:
    1. QStringList SerialPortChannel::availablePorts()
    2. {
    3. QStringList ports;
    4.  
    5. for (QSerialPortInfo port : QSerialPortInfo::availablePorts())
    6. {
    7. //Their is some sorting to do for just list the port I want, with vendor Id & product Id
    8. qDebug() << port.portName() << port.vendorIdentifier() << port.productIdentifier()
    9. << port.hasProductIdentifier() << port.hasVendorIdentifier() << port.isBusy();
    10. ports += port.portName();
    11. }
    12. return ports;
    13. }
    To copy to clipboard, switch view to plain text mode 
    This is the my class constructor where I open the port :

    Qt Code:
    1. SerialPortChannel::SerialPortChannel(QString port)
    2. : QObject()
    3. , m_port(port)
    4. {
    5. online = m_port.open(QIODevice::WriteOnly);
    6. if(online)
    7. qDebug() << "Connected to : " << port;
    8.  
    9. //Configure the port
    10. m_port.setBaudRate(QSerialPort::Baud115200);
    11. m_port.setDataBits(QSerialPort::Data8);
    12. m_port.setStopBits(QSerialPort::OneStop);
    13. m_port.setParity(QSerialPort::NoParity);
    14. m_port.setFlowControl(QSerialPort::NoFlowControl);
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 
    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 ?

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPortInfo get all available port in Linux and Mac

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

  3. The following user says thank you to kuzulis for this useful post:

    Nekyz (7th October 2013)

  4. #3
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSerialPortInfo get all available port in Linux and Mac

    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.

  5. #4
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPortInfo get all available port in Linux and Mac

    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!
    Last edited by kuzulis; 7th October 2013 at 16:02.

Similar Threads

  1. QSerialPortInfo Broken
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 21st June 2013, 16:23
  2. How to port windows app to linux
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2009, 09:39
  3. port linux app to win (runtime error)
    By agostain in forum Qwt
    Replies: 3
    Last Post: 9th September 2009, 13:45
  4. Replies: 0
    Last Post: 22nd June 2008, 16:18
  5. MFC DLL port to Linux
    By steg90 in forum General Programming
    Replies: 1
    Last Post: 12th July 2007, 19:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.