简体   繁体   中英

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.

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;
    }

libserial是一个令人难以置信的库,我用于Arduino Duemilanove的独立串行应用程序。

qserialdevice use!

Example:

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

你能使用没有DTR,RTS线路的3线串口线(tx / rx / gnd)吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM