Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] QSerialPort fails opening with "File exists" error message

[SOLVED] QSerialPort fails opening with "File exists" error message

Scheduled Pinned Locked Moved Mobile and Embedded
embeddedserialportfile exists
4 Posts 3 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pschuster
    wrote on 30 Jun 2015, 14:53 last edited by pschuster 7 Jan 2015, 18:35
    #1

    Hi all,

    I am developing a custom embedded device. This device runs Buildroot linux with Qt 5.3. It features an AVR-MCU (Arduino 1284p) that is connected to the main processor (that runs Linux and Qt) via a serial connection (RX, TX). The Arduino-MCU simple reads the serial port for commands, executes them (i.e. read temperature sensor) and prints the result.

    In the linux shell I can run cat /dev/ttyS3 to read the data the Arduino has written and I can send bytes by calling echo 'Hello Arduino' >> /dev/ttyS3 for example. That works fine.

    If I want to use QSerialPort by calling:

    foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
        qDebug() << info.portName();
    
    m_serialPort = new QSerialPort("ttyS3");
    m_serialPort->setBaudRate(QSerialPort::Baud9600);
    m_serialPort->setFlowControl(QSerialPort::NoFlowControl);
    m_serialPort->setParity(QSerialPort::NoParity);
    m_serialPort->setDataBits(QSerialPort::Data8);
    m_serialPort->setStopBits(QSerialPort::OneStop);
    if (m_serialPort->open(QIODevice::ReadWrite))
    {
        qDebug() << "Serial Port opened ttyS3";
    
        this->connect(m_serialPort,SIGNAL(readyRead()),SLOT(serialDataReceived()));
    }
    else
    {
        qDebug() << "Failed to open ttyS3 serial port";
        qDebug() << m_serialPort->errorString();
        qDebug() << m_serialPort->error();
    }
    

    I receive the error message "File exists" (errorString) and the error-ID is 2. I am running the Qt application as root. http://superuser.com/questions/569255/how-to-quickly-determine-which-process-if-any-listens-to-a-serial-port lists a few linux commands that identify the process that has the serial port in use. Non of the examples (lsof /dev/ttyS3 nor fuser -n file /dev/ttyS3) lists a process. So I am pretty sure the serial port is not in use.

    If I try the source code with ttyS2 everything works fine (besides the fact that nothing useful is connected to ttyS2 of course ;-)).

    Anyone has an idea what's going wrong?

    Thanks a lot.
    Phillip

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 Jun 2015, 20:52 last edited by
      #2

      Hi and welcome to devnet,

      Just an idea: did you check the permissions on /dev/ttyS3 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on 1 Jul 2015, 08:32 last edited by
        #3

        Most likely that "File exists" goes from the tty-locker (from QLockFile), because the ttyS3-lock file exists. It is probable that this issue belongs to this bug: https://bugreports.qt.io/browse/QTBUG-36983

        So, you can:

        1. Try to use a latest version of QtSerialPort
        2. Just find out the lock-file and to remove it before opening.
        3. That is better - it is do not start the application with a root privileges. You should try to create an user, and to add his to "dialout" grop or similar (depends on your base distro).
        1 Reply Last reply
        1
        • P Offline
          P Offline
          pschuster
          wrote on 1 Jul 2015, 18:34 last edited by
          #4

          AWESEOME! Thank you very much. 2) did the trick. I found a file /var/lock/LCK..ttyS3. After removing it the code posted above works fine. I will now try 1) or implement a patch myself.

          Thanks a lot. You made my day.
          Phillip

          1 Reply Last reply
          0

          1/4

          30 Jun 2015, 14:53

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved