I have a PCI card with a db25 port. This in turn connects to two devices with a de9 port. I need to talk to these devices using rs485. I'm working on a C++11 library that currently creates char arrays for the protocol commands.
I would like to put these arrays into an output stream and read the response from an input stream. I have a feeling that this is a possibility, but I'm not sure how. The current questions that I have are as follows:
- Should I use termios? How do I create a stream with termios?
- Should I use an fstream to open /dev/tty*? How would I set values like the baud rate with fstream?
- Is there another cleaner option?
I tried googling for a while but I didn't come up with any answers.
EDIT:
Someone in the office pointed me to boost asio: https://www.boost.org/doc/libs/1_69_0/doc/html/boost_asio/reference/serial_port.html
There are stream implementations possible with it: https://www.boost.org/doc/libs/1_69_0/doc/html/boost_asio/overview/serial_ports.html
https://github.com/fedetft/serial-port/blob/master/6_stream/serialstream.cpp
More detailed explanation: https://gist.github.com/kaliatech/427d57cb1a8e9a8815894413be337cf9
I got the settings that I need from: https://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html (the non canonical one seemd to work best). The termios version that I made worked and am currently converting it to boost/asio
I will try to report back if it works