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

Abstract interface for communicating with a scanner. More...

#include <ICommInterface.hpp>

Inheritance diagram for OpenSRX::ICommInterface:
OpenSRX::AsioInterface< asio::serial_port > OpenSRX::AsioInterface< asio::ip::tcp::socket > OpenSRX::AsioInterface< StreamT > OpenSRX::SerialInterface OpenSRX::SocketInterface

Public Member Functions

virtual ~ICommInterface ()=default
 
virtual std::string sendCommand (const std::string &command)=0
 Send a command and return the response (thread-safe).
 
virtual std::string sendCommandUnlocked (const std::string &command)=0
 Send a command and return the response without locking.
 
virtual std::string describe () const =0
 Return a human-readable description of this interface.
 
void setCommFormat (CommFormat format)
 Set the communication framing format.
 
CommFormat getCommFormat ()
 Get the current communication framing format.
 

Protected Attributes

std::mutex commMutex
 Mutex to ensure thread-safe access to the communixcation interface.
 

Private Member Functions

std::string stripEcho (const std::string &response, const std::string &command)
 Strip a command echo from the start of a response.
 
std::string addHeaderAndTerminator (const std::string &command)
 Wrap a command string with the appropriate header and terminator.
 

Private Attributes

CommFormat commFormat = CommFormat::NO_HEADER_CR_IN_CR_OUT
 Active framing format.
 
std::string inTermStr = "\r"
 Expected response terminator string.
 

Friends

template<typename StreamT>
class AsioInterface
 
class MockCommInterface
 

Detailed Description

Abstract interface for communicating with a scanner.

Provides send/receive primitives and framing configuration. Concrete implementations include SerialInterface, SocketInterface, and test mocks.

Constructor & Destructor Documentation

◆ ~ICommInterface()

virtual OpenSRX::ICommInterface::~ICommInterface ( )
virtualdefault

Member Function Documentation

◆ addHeaderAndTerminator()

std::string OpenSRX::ICommInterface::addHeaderAndTerminator ( const std::string & command)
private

Wrap a command string with the appropriate header and terminator.

Parameters
commandThe bare command string.
Returns
The framed command ready to send on the wire.

◆ describe()

virtual std::string OpenSRX::ICommInterface::describe ( ) const
pure virtual

Return a human-readable description of this interface.

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

Implemented in OpenSRX::SerialInterface, and OpenSRX::SocketInterface.

◆ getCommFormat()

CommFormat OpenSRX::ICommInterface::getCommFormat ( )
inline

Get the current communication framing format.

Returns
The active CommFormat.

◆ sendCommand()

virtual std::string OpenSRX::ICommInterface::sendCommand ( const std::string & command)
pure virtual

Send a command and return the response (thread-safe).

Acquires the communication mutex before sending.

Parameters
commandThe command string (without header/terminator).
Returns
The parsed response string.

Implemented in OpenSRX::AsioInterface< StreamT >, OpenSRX::AsioInterface< asio::ip::tcp::socket >, and OpenSRX::AsioInterface< asio::serial_port >.

◆ sendCommandUnlocked()

virtual std::string OpenSRX::ICommInterface::sendCommandUnlocked ( const std::string & command)
pure virtual

Send a command and return the response without locking.

Used by blocking commands (LON, TUNE, etc.) so that cancellation commands can be sent concurrently from another thread.

Parameters
commandThe command string (without header/terminator).
Returns
The parsed response string.

Implemented in OpenSRX::AsioInterface< StreamT >, OpenSRX::AsioInterface< asio::ip::tcp::socket >, and OpenSRX::AsioInterface< asio::serial_port >.

◆ setCommFormat()

void OpenSRX::ICommInterface::setCommFormat ( CommFormat format)

Set the communication framing format.

Parameters
formatThe CommFormat to use.

◆ stripEcho()

std::string OpenSRX::ICommInterface::stripEcho ( const std::string & response,
const std::string & command )
private

Strip a command echo from the start of a response.

Parameters
responseThe raw response string.
commandThe command that was sent.
Returns
The response with any leading echo removed.

Friends And Related Symbol Documentation

◆ AsioInterface

template<typename StreamT>
friend class AsioInterface
friend

◆ MockCommInterface

friend class MockCommInterface
friend

Member Data Documentation

◆ commFormat

CommFormat OpenSRX::ICommInterface::commFormat = CommFormat::NO_HEADER_CR_IN_CR_OUT
private

Active framing format.

◆ commMutex

std::mutex OpenSRX::ICommInterface::commMutex
protected

Mutex to ensure thread-safe access to the communixcation interface.

◆ inTermStr

std::string OpenSRX::ICommInterface::inTermStr = "\r"
private

Expected response terminator string.


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