Pergunta

I'm looking for a easy to use C++ librairie to dialog with Serial Port under Linux.

I looked at Boost::Asio but it look like very complicated for my little usage. I just want to received some information on the Serial Port and record them in a database.

Do you know a simple Serial Port librairie (with a example it would be the best)

Thanks

Foi útil?

Solução

Boost.Asio is really a good one. The problem is that its documentation is too complex and arranged erratically. If you just need to do the simplest serial port programming, you don't need to use all the advanced features.

Example usage of blocking I/O on serial port.

static boost::asio::io_service ios;
boost::asio::serial_port sp(ios, "/dev/ttyS2");
sp.set_option(boost::asio::serial_port::baud_rate(115200));
// You can set other options using similar syntax
char tmp[64];
auto length = sp.read_some(boost::asio::buffer(tmp));
// process the info received
std::string message = "hello, world";
sp.write_some(boost::asio::buffer(message));
sp.close();

Outras dicas

RS232 is used for serial communication. You may refer this link or you can try Boost Asio's serial ports and compile that into a library to be linked with your C application. It claims to be POSIX compatible, and OSX is POSIX.

Most of what you need will be in the termios.h header. Take a look here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top