Matti Lyra
Matti Lyra

Reputation: 13078

QextSerialPort connection problem to Arduino

I'm trying to make a serial connection to an Arduino Diecimila board with QextSerialPort. My application hangs though everytime I call port->open(). The reason I think this is happening is because the Arduino board resets itself everytime a serial connection to it is made. There's a way of not making the board reset described here, but I can't figure out how to get QextSerialPort to do that. I can only set the DTR to false after the port has been opened that's not much help since the board has already reset itself by that time.

The code for the connection looks like this:

 port = new QextSerialPort("/dev/tty.usbserial-A4001uwj");
 port->open(QIODevice::ReadWrite);
 port->setBaudRate(BAUD9600);   
 port->setFlowControl(FLOW_OFF);
 port->setParity(PAR_NONE);    
 port->setDataBits(DATA_8);   
 port->setStopBits(STOP_1);
 port->setDtr(false);
 port->setRts(false);

Any ideas on how to get this done. I don't necessarily need to use QextSerialPort should someone know of another library that does the trick.

I'm new to C++ and Qt.

UPDATE: I noticed that if I run a python script that connects to the same port (using pySerial) before running the above code, everything works just fine.

Upvotes: 1

Views: 2104

Answers (4)

user1456861
user1456861

Reputation: 36

I had a similar problem.

In my case QExtSerial would open the port, I'd see the RX/TX lights on the board flash, but no data would be received. If I opened the port with another terminal program first QExtSerial would work as expected.

What solved it for me was opening the port, configuring the port settings, and then making DTR and RTS high for a short period of time.

This was on Windows 7 w/ an ATMega32u4 (SFE Pro Micro).




    bool serialController::openPort(QString portName) {
        QString selectPort = QString("\\\\.\\%1").arg(portName);
        this->port = new QextSerialPort(selectPort,QextSerialPort::EventDriven);
        if (port->open(QIODevice::ReadWrite | QIODevice::Unbuffered) == true) {
            port->setBaudRate(BAUD38400);
            port->setFlowControl(FLOW_OFF);
            port->setParity(PAR_NONE);
            port->setDataBits(DATA_8);
            port->setStopBits(STOP_1);
            port->setTimeout(500);

            port->setDtr(true);
            port->setRts(true);
            Sleep(100);
            port->setDtr(false);
            port->setRts(false);

            connect(port,SIGNAL(readyRead()), this, SLOT(onReadyRead()));

            return true;
        } else {
            // Device failed to open: port->errorString();
        }
        return false;
    }

Upvotes: 2

universeroot
universeroot

Reputation: 11

qserialdevice use!

Example:

http://robocraft.ru/blog/544.html

Upvotes: 1

Martin Beckett
Martin Beckett

Reputation: 96119

Can you just use a 3wire serial cable (tx/rx/gnd) with no DTR,RTS lines?

Upvotes: 0

nickp
nickp

Reputation: 11

libserial is an incredible library I use for stand-alone serial applications for my Arduino Duemilanove.

Upvotes: 1

Related Questions