[solved] QSerialPort error - "is a directory"



  • This code gives an error of "Is a directory" when open() is called. I assume it's permissions or something but I can't find a single instance ANYWHERE online of someone else getting this error?

    [code]
    #include <QCoreApplication>
    #include <QDebug>
    #include <QtSerialPort/QSerialPort>
    #include <QtSerialPort/QSerialPortInfo>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QSerialPortInfo serialPortInfo("/dev/ttyUSB0");
    QSerialPort serialPort(serialPortInfo);

    QByteArray byteArrayRequest;
    byteArrayRequest.resize(2);
    byteArrayRequest[0] = 0x01;
    byteArrayRequest[1] = 0x01;
    
    if (serialPort.open(QIODevice::ReadWrite))
    {
        serialPort.setBaudRate(QSerialPort::Baud38400);
        qDebug() << "Writing\n";
        serialPort.write(byteArrayRequest);
        serialPort.close();
    }
    else
    {
        qDebug() << serialPort.errorString();
        qDebug() << "Problem opening port\n";
    }
    
    return a.exec(&#41;;
    

    }

    [/code]

    Can anyone please advise?

    Thanks


  • Lifetime Qt Champion

    Hi,

    What does ls -la /dev/ttyUSB0 return ?



  • [quote author="SGaist" date="1393630095"]What does ls -la /dev/ttyUSB0 return ?[/quote]

    If the device IS NOT plugged in:
    ls: cannot access /dev/ttyUSB0: No such file or directory

    If the device IS plugged in:
    crw-rw---- 1 root uucp 188, 0 Mar 1 21:27 /dev/ttyUSB0


  • Lifetime Qt Champion

    Are you member of the uucp group ?



  • [quote author="SGaist" date="1393714479"]Are you member of the uucp group ?[/quote]

    I have run my code as root.



  • OK, so I figured I must be referencing the port incorrectly.

    This post was useful -> http://qt-project.org/forums/viewthread/28942

    I changed the hardcoded reference to /dev/ttyUSB0 in my code and loaded it in the same way as the posts do and it worked fine!

    Thanks :)


  • Lifetime Qt Champion

    You're welcome !

    Since you have your serial port talking now, please update your thread title prepending [solved] so other forum users may know a solution has been found :)


Log in to reply
 

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