Libserial Open() 在我的 C++ 中冻结程序

发布于 2024-10-04 23:11:48 字数 824 浏览 0 评论 0原文

基本上我有一个非常简单的 C++ 程序,我试图打开一个串行端口(实际上是一个 USB->RS232 转换器,应该由 libserial 支持),但代码在 Open() 上冻结。没有错误,没有异常,什么也没有,它只是什么也不做。除了这个特定的串行端口之外,它似乎可以在其他串行端口上工作。串行端口还可以与cutecom和其他终端一起使用(并且它不被任何其他程序保留)。我尝试在打开端口之前和之后进行配置,但似乎并不重要。我在 libserial 的(相当糟糕的)文档或标题中也看不到任何有关握手的信息,也许它正在等待握手或其他什么,我不知道...... Libserial0 版本 0.6.0 和 Ubuntu 10.10。出了什么问题或者我该如何尝试调试这个...?还有其他建议的库/方法来使用 C++ 串行端口吗?

#include <SerialStream.h>
#include <iostream>

int main() {

 LibSerial::SerialStream device_;

 device_.SetBaudRate(LibSerial::SerialStreamBuf::BAUD_9600);
 device_.SetCharSize(LibSerial::SerialStreamBuf::CHAR_SIZE_8);
 device_.SetNumOfStopBits(1);
 device_.SetParity(LibSerial::SerialStreamBuf::PARITY_NONE);
 device_.SetFlowControl(LibSerial::SerialStreamBuf::FLOW_CONTROL_NONE);

 device_.Open("/dev/ttyUSB1");

}

Basically I have a really simple C++ program where I'm trying to open a serial port (which is actually a USB->RS232 converter, should be supported by libserial) but the code freezes on Open(). No errors no exceptions, nothing, it just does nothing. It seems to work on other serial ports except this specific one. The serial port also does work with cutecom and other terminals (and it is not reserved by any other program). I've tried configuring before and after opening the port but it does not seem to matter. I also can't see anything about handshaking in the (quite poor) documentation of libserial or in the headers, maybe its waiting for a handshake or something, I don't know... Libserial0 version 0.6.0 and Ubuntu 10.10. Whats wrong or how can I try to debug this...? Any other suggested libraries/ways to use the serial port with C++?

#include <SerialStream.h>
#include <iostream>

int main() {

 LibSerial::SerialStream device_;

 device_.SetBaudRate(LibSerial::SerialStreamBuf::BAUD_9600);
 device_.SetCharSize(LibSerial::SerialStreamBuf::CHAR_SIZE_8);
 device_.SetNumOfStopBits(1);
 device_.SetParity(LibSerial::SerialStreamBuf::PARITY_NONE);
 device_.SetFlowControl(LibSerial::SerialStreamBuf::FLOW_CONTROL_NONE);

 device_.Open("/dev/ttyUSB1");

}

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

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

发布评论

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

评论(2

雪落纷纷 2024-10-11 23:11:48

几年前,当我不得不为调制解调器编写一个控制接口以允许通过 RS-232 进行远程控制时,我研究了 libserial。我最终选择了 Boost 的 ASIO 实现来利用串行端口。

不确定 Boost.ASIO 是否适合您。但根据我的经验,我并没有把它挂在我身上......

I looked at libserial a couple of years ago when I was having to write a control interface to a modem that allowed remote control via RS-232. I ended up going with the Boost's ASIO implementation for utilizing the serialport.

Not sure if Boost.ASIO will work for you or not. but in my experience I haven't had it hang on me....

不忘初心 2024-10-11 23:11:48

我在使用 USB 串行转换器 (pl2303) 时也发现了这个问题。看来设置VTime可以解决问题。

I also found this issue using a USB-serial converter (pl2303). It appears that setting VTime solves the problem.

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