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
Go to Device Manager > Ports (COM & LPT) > mbed Serial Port, then right-click and select "properties". Choose "Port Settings" Tab, and click "Advanced" Under "COM Port Number", try selecting a different COM port. Unplug and replug the mbed to reload the driver - if the problem persists, try another COM port.
Linux names its serial ports in the UNIX tradition. The first serial port has the file name /dev/ttyS0, the second serial port has the file name /dev/ttyS1, and so on. This differs from the IBM PC tradition. The first serial port is named COM1:, the second serial port is named COM2:, and so on.
Linux uses ttySx for a serial port device name. For example, COM1 (DOS/Windows name) is ttyS0, COM2 is ttyS1, and so on.
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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With