简体   繁体   English

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

[英]Libserial Open() freezes in my C++ program

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(). 基本上,我有一个非常简单的C ++程序,试图打开一个串行端口(实际上是USB-> RS232转换器,应该由libserial支持),但是代码会冻结在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). 串行端口也可以与cutecom和其他终端一起使用(并且任何其他程序都不保留)。 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. 在libserial的(相当糟糕的)文档或标头中,我也看不到任何有关握手的信息,也许它正在等待握手之类的东西,我不知道... Libserial0版本0.6.0和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++? 是否有其他建议的库/方式将串行端口与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");

}

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. 几年前,当我不得不将控制接口写入调制解调器以允许通过RS-232进行远程控制时,我看着libserial。 I ended up going with the Boost's ASIO implementation for utilizing the serialport. 最后,我使用了Boost的ASIO实现来利用串行端口。

Not sure if Boost.ASIO will work for you or not. 不知道Boost.ASIO是否会为您工作。 but in my experience I haven't had it hang on me.... 但是根据我的经验,我还没有挂在我身上。

I also found this issue using a USB-serial converter (pl2303). 我还使用USB串行转换器(pl2303)发现了此问题。 It appears that setting VTime solves the problem. 看来设置VTime可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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