QextSerialPort与Arduino的连接问题

发布于 2024-09-07 16:16:13 字数 854 浏览 9 评论 0原文

我正在尝试使用 QextSerialPort 与 Arduino Diecimila 板建立串行连接。但每次我调用 port->open() 时,我的应用程序都会挂起。我认为发生这种情况的原因是每次与 Arduino 板建立串行连接时都会自行重置。有一种不重置主板的方法,如下所述此处,但我不知道如何让 QextSerialPort 来做到这一点。我只能在端口打开后将 DTR 设置为 false,这没有多大帮助,因为此时板已经自行重置。

连接的代码如下所示:

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

有关如何完成此操作的任何想法。如果有人知道另一个可以实现此目的的库,我不一定需要使用 QextSerialPort。

我是 C++ 和 Qt 的新手。

更新: 我注意到,如果我在运行上述代码之前运行连接到同一端口(使用 pySerial)的 python 脚本,则一切正常。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一身仙ぐ女味 2024-09-14 16:16:17

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

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

空‖城人不在 2024-09-14 16:16:17

q串口设备使用!

示例:

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

qserialdevice use!

Example:

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

∞琼窗梦回ˉ 2024-09-14 16:16:17

您可以只使用没有 DTR、RTS 线的 3 线串行电缆 (tx/rx/gnd) 吗?

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

静若繁花 2024-09-14 16:16:16

我有类似的问题。

就我而言,QExtSerial 将打开端口,我会看到板上的 RX/TX 灯闪烁,但不会收到任何数据。如果我使用另一个终端程序打开端口,首先 QExtSerial 将按预期工作。

对我来说解决这个问题的方法是打开端口,配置端口设置,然后在短时间内将 DTR 和 RTS 设置为高电平。

这是在 Windows 7 上使用 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;
    }

<代码>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文