QextSerialPort与Arduino的连接问题
我正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
libserial 是一个令人难以置信的库,我将其用于 Arduino Duemilanove 的独立串行应用程序。
libserial is an incredible library I use for stand-alone serial applications for my Arduino Duemilanove.
q串口设备使用!
示例:
http://robocraft.ru/blog/544.html
qserialdevice use!
Example:
http://robocraft.ru/blog/544.html
您可以只使用没有 DTR、RTS 线的 3 线串行电缆 (tx/rx/gnd) 吗?
Can you just use a 3wire serial cable (tx/rx/gnd) with no DTR,RTS lines?
我有类似的问题。
就我而言,QExtSerial 将打开端口,我会看到板上的 RX/TX 灯闪烁,但不会收到任何数据。如果我使用另一个终端程序打开端口,首先 QExtSerial 将按预期工作。
对我来说解决这个问题的方法是打开端口,配置端口设置,然后在短时间内将 DTR 和 RTS 设置为高电平。
这是在 Windows 7 上使用 ATMega32u4 (SFE Pro Micro)。
<代码>
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).