serial port open resource



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


  • Lifetime Qt Champion

    Hi and welcome to devnet,

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



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



  • 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();
    

    }



  • 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()));
    


  • This post is deleted!


  • 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?



  • This post is deleted!

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.