OpenSRX 0.1.0
C++ library for interfacing with Keyence SR series barcode readers
Loading...
Searching...
No Matches
OpenSRX::SerialInterface Class Reference

Communication interface using an RS-232 serial port. More...

#include <SerialInterface.hpp>

Inheritance diagram for OpenSRX::SerialInterface:
OpenSRX::AsioInterface< asio::serial_port > OpenSRX::ICommInterface

Public Member Functions

 SerialInterface (std::string port="/dev/ttyUSB0", int baudRate=115200, DataBits dataBits=DataBits::EIGHT, Parity parity=Parity::EVEN, StopBits stopBits=StopBits::ONE, FlowControl flowControl=FlowControl::NONE)
 Open a serial port connection.
 
 ~SerialInterface () override
 
std::string describe () const override
 Return a human-readable description of this interface.
 
- Public Member Functions inherited from OpenSRX::AsioInterface< asio::serial_port >
 ~AsioInterface () override=default
 
std::string sendCommand (const std::string &command) override
 Sends a command over the Asio stream and reads the response.
 
std::string sendCommandUnlocked (const std::string &command) override
 Sends a command without acquiring the communication mutex.
 
- Public Member Functions inherited from OpenSRX::ICommInterface
virtual ~ICommInterface ()=default
 
void setCommFormat (CommFormat format)
 Set the communication framing format.
 
CommFormat getCommFormat ()
 Get the current communication framing format.
 

Private Attributes

std::string port
 Serial device path.
 

Additional Inherited Members

- Protected Member Functions inherited from OpenSRX::AsioInterface< asio::serial_port >
 AsioInterface (Args &&... args)
 Construct an AsioInterface, forwarding arguments to the stream.
 
- Protected Attributes inherited from OpenSRX::AsioInterface< asio::serial_port >
asio::io_context ioContext
 
asio::serial_port stream
 
- Protected Attributes inherited from OpenSRX::ICommInterface
std::mutex commMutex
 Mutex to ensure thread-safe access to the communixcation interface.
 

Detailed Description

Communication interface using an RS-232 serial port.

Wraps an Asio serial_port with configurable baud rate, data bits, parity, stop bits, and flow control.

Constructor & Destructor Documentation

◆ SerialInterface()

OpenSRX::SerialInterface::SerialInterface ( std::string port = "/dev/ttyUSB0",
int baudRate = 115200,
DataBits dataBits = DataBits::EIGHT,
Parity parity = Parity::EVEN,
StopBits stopBits = StopBits::ONE,
FlowControl flowControl = FlowControl::NONE )

Open a serial port connection.

Parameters
portSerial device path (e.g. "/dev/ttyUSB0").
baudRateBaud rate (e.g. 115200).
dataBitsNumber of data bits per character.
parityParity checking mode.
stopBitsNumber of stop bits.
flowControlFlow control mode.

◆ ~SerialInterface()

OpenSRX::SerialInterface::~SerialInterface ( )
override

Member Function Documentation

◆ describe()

std::string OpenSRX::SerialInterface::describe ( ) const
inlineoverridevirtual

Return a human-readable description of this interface.

Returns
e.g. "/dev/ttyUSB0" or "192.168.1.100:9004".

Implements OpenSRX::ICommInterface.

Member Data Documentation

◆ port

std::string OpenSRX::SerialInterface::port
private

Serial device path.


The documentation for this class was generated from the following file: