开发者

Libserial Open() freezes in my C++ program

开发者 https://www.devze.com 2023-01-28 12:19 出处:网络
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 err

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

}


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....


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号