Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. serial port open resource
Forum Updated to NodeBB v4.3 + New Features

serial port open resource

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 5.5k Views 3 Watching
  • 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.
  • A Offline
    A Offline
    algebra
    wrote on last edited by algebra
    #1

    Hi,

    i am a linux and raspberry Pi2 newbie, i have a device which uses FTDI chip, this device controls wave pumps in my aquarium.

    in windows7, i can connect to this controller with its original program tunze 7096
    http://www.tunze.com/fileadmin/gebrauchsanleitungen/x7096.8888.pdf
    via usb port, and can change pump settings.

    also i can change settings with c#, and qt5 in windows.

    in raspbian and ubuntu, i can open the port with mono c# and write new settings successfully, but not with qt5, in QT5 when i open the port the device led turns off and i can not write the settings string to device. ( devices led never turns off with c# mono, and qt5 in windows7 when successful open and write occurs)

    i debug the code with raspbian and ubuntu, it seems port opened ok, /dev/ttyUSB0 but i can't write data so i decide to trace if any error occurs after opening port.

    serial.open(QIODevice::ReadWrite)
    qDebug() << serial.errorString() , here it says

    in raspbian "no such file or directory"
    in ubuntu 14 -64bit , "resource temporarily unavailable"

    and after opening the port i try to write string with qbytearray no errors but nothing happened, when i close the port device led again turns on.

    But in mono c# code works perfect.. i can open and write in windows7 ubuntu14 and raspbian, nothing change with the led when i open the port.

    i also tried chmod 777 /dev/ttyUSB0 in ubuntu, raspbian but nothing changed

    i am very pleased if you have an idea how to open /dev/ttyUSB0 successfully, and write string in cross compiled QT5 C++.

    thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you share the code you use to setup your serial port ?

      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 last edited by
        #3

        in raspbian "no such file or directory"
        in ubuntu 14 -64bit , "resource temporarily unavailable"

        Try check existence of Lock files in /var/lock and ets.. and remove all lock files that related to ttyUSB0..

        1 Reply Last reply
        0
        • A Offline
          A Offline
          algebra
          wrote on last edited by algebra
          #4

          here is the code, is simple, i tried different baud rates and flowcontrol to none but nothing is changed, also i tried open the port first and then assigned port settings but no success :(

          also when i put waitForBytesWritten(1000) after write while debugging with F10 after processing waitForBytesWritten debugger changed to line again to serial.write command and again processed waitbyteswritten then exits.

          by the way no locks exists, i tried minicom before it succeeds , port opened fine.

          #include <QCoreApplication>
          #include <QSerialPort>
          #include <QDebug>

          int main(int argc, char *argv[])
          {
          QCoreApplication a(argc, argv);

          QSerialPort serial;
          
                         serial.setPortName("/dev/ttyUSB0");
                         serial.setBaudRate(QSerialPort::Baud19200);
                         serial.setStopBits(QSerialPort::OneStop);
                         serial.setDataBits(QSerialPort::Data8);
                         serial.setParity(QSerialPort::NoParity);
                         serial.setFlowControl(QSerialPort::SoftwareControl);//xonxoff*/
          

          if (serial.open(QIODevice::ReadWrite))
          //if (serial.open(QSerialPort::ReadWrite)) // both fails //writeonly fails
          {
          qDebug() << serial.errorString();

                     bool success = true;
                     qDebug() << "Connected to usb device: " << (success ? "OK" : "FAIL");
          
                     serial.Write("tunze settings string");
                     serial.Waitbyteswritten(1000);
          
          
                      }
          
          return a.exec();
          

          }

          1 Reply Last reply
          0
          • McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by McLion
            #5

            Is your USB device ready to be opened?
            Try this (with ttyS1 to test the code basically):

            serial = new QSerialPort(this);
            
            serial->setPortName("/dev/ttyUSB0");
            serial->setBaudRate(QSerialPort::Baud19200);
            serial->setDataBits(QSerialPort::Data8);
            serial->setParity(QSerialPort::NoParity);
            serial->setStopBits(QSerialPort::OneStop);
            serial->setFlowControl(QSerialPort::SoftwareControl);
            
            if (!serial->open(QIODevice::ReadWrite))
               qDebug() << "serial port could not be opened";
            

            Also connect errors to an error handler:

            connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(SerialError(QSerialPort::SerialPortError)));
            

            and I suggest to use the ReadyRead signal:

            connect(serial, SIGNAL(readyRead()), this, SLOT(onComReadyRead()));
            
            1 Reply Last reply
            0
            • JoeBermejalesJ Offline
              JoeBermejalesJ Offline
              JoeBermejales
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • A Offline
                A Offline
                algebra
                wrote on last edited by
                #7

                hi,
                i tried this, set debug point to first line, after stepover serial.open command
                debugger highlights the first statement here and debugger trace says

                Locals
                error QSerialPort::NoError (0) QSerialPort::SerialPortError
                this @0x2338740 ScenarioExecuter

                but if i add QTextStream(stdout) << m_serialPort->errorString() << endl;
                it says "no such file..."

                void ScenarioExecuter::handleError(QSerialPort::SerialPortError error)
                {
                if (error == QSerialPort::ResourceError) {
                QTextStream(stdout) << m_serialPort->errorString() << endl;
                }
                QTextStream(stdout) << m_serialPort->errorString() << endl;
                }
                btw , i install a clean ubuntu 14, 64 bit, not prepared for cross compile , and setup qt5
                after "sudo apt-get install g++"

                here the same code, same device again mono c# code works perfect with the device
                but qt5 open statement fail, it says again "NoError (0)" but it can not open

                if (!m_serialPort->open(QSerialPort::WriteOnly))
                { qDebug() << "serial port could not be opened";
                qDebug() << m_serialPort->errorString();
                }
                else
                qDebug() << m_serialPort->errorString();

                debugger doesnt highlights any of the if blocks, suddenly goes to errorhandler with NoError(0) but crazy "no such file or directory"

                any ideas?

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  algebra
                  wrote on last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0

                  • Login

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