DynExp
Highly flexible laboratory automation for dynamically changing experiments.
DynExp::SerialCommunicationHardwareAdapter Class Referenceabstract

Defines a hardware adapter for serial communication. Logical const-ness: see declaration of class DynExp::Object. More...

+ Inheritance diagram for DynExp::SerialCommunicationHardwareAdapter:

Classes

struct  endl
 Type denoting the end of a line when piped to operator<<(endl) More...
 

Public Types

using ParamsType = SerialCommunicationHardwareAdapterParams
 Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object. More...
 
using ConfigType = SerialCommunicationHardwareAdapterConfigurator
 Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object. More...
 
- Public Types inherited from DynExp::HardwareAdapterBase
using ParamsType = HardwareAdapterParamsBase
 Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object. More...
 
using ConfigType = HardwareAdapterConfiguratorBase
 Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object. More...
 
- Public Types inherited from DynExp::Object
using ParamsType = ParamsBase
 Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object. More...
 
using ParamsTypeSyncPtrType = Util::SynchronizedPointer< ParamsType >
 Alias for the return type of Object::GetParams(). Parameters wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way. More...
 
using ParamsConstTypeSyncPtrType = Util::SynchronizedPointer< const ParamsType >
 Alias for the return type of Object::GetParams() const. Parameters wrapped into Util::SynchronizedPointer can be accessed in a thread-safe way. More...
 
using ConfigType = ConfiguratorBase
 Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object. More...
 
using ParamsGetterType = Util::CallableMemberWrapper< Object, decltype(&Object::GetParams)>
 Invoking an instance of this alias is supposed to call Object::GetParams() of the instance the Util::CallableMemberWrapper has been constructed with. More...
 

Public Member Functions

 SerialCommunicationHardwareAdapter (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
 Constructs a hardware adapter instance. More...
 
virtual ~SerialCommunicationHardwareAdapter ()=0
 
virtual std::string GetName () const override
 Returns the name of this Object type. More...
 
virtual std::string GetCategory () const override
 Returns the category of this Object type. More...
 
auto GetLineEnding () const
 Getter for LineEnding. Thread-safe since LineEnding only changes when Object::Reset() is called (itself calling ResetImpl(dispatch_tag<HardwareAdapterBase>) which calls Init()). LineEnding is still std::atomic since QSerialCommunicationHardwareAdapterWorker running in DynExpCore's worker thread might read it anytime - even if there is no Object instance which makes use of this hardware adapter instance. More...
 
std::string ReadLine () const
 Calls ReadIntoBuffer() before it extracts the first line from the read buffer. More...
 
std::string ReadAll () const
 Calls ReadIntoBuffer() before it extracts the entire content from the read buffer. More...
 
std::string WaitForLine (unsigned int NumTries=10, std::chrono::milliseconds DelayBetweenTries=std::chrono::milliseconds(10)) const
 Calls ReadLine() for NumTries times until a line is received. Makes the calling thread sleep for DelayBetweenTries in between the calls to ReadLine(). More...
 
void Clear () const
 Clears the content and state flags of the read buffer (ReadBuffer) as well as possible internal buffers of the underlying hardware interface. More...
 
void Flush () const
 Flushes the underlying hardware interface and calls ReadIntoBuffer(). More...
 
const SerialCommunicationHardwareAdapteroperator>> (std::stringstream &OutStream) const
 Writes the read buffer's content into OutStream calling ReadAll(). More...
 
const SerialCommunicationHardwareAdapteroperator<< (endl) const
 Writes a new line calling Write_endl(). More...
 
const SerialCommunicationHardwareAdapteroperator<< (const std::stringstream &InStream) const
 Writes the input parameter calling Write(). Also writes endl at the end automatically. More...
 
const SerialCommunicationHardwareAdapteroperator<< (const std::string &Text) const
 Writes the input parameter calling Write(). Also writes endl at the end automatically. More...
 
const SerialCommunicationHardwareAdapteroperator<< (const std::string_view Text) const
 Writes the input parameter calling Write(). Also writes endl at the end automatically. More...
 
const SerialCommunicationHardwareAdapteroperator<< (const char *Text) const
 Writes the input parameter calling Write(). Also writes endl at the end automatically. More...
 
const SerialCommunicationHardwareAdapteroperator<< (const char Char) const
 Writes the input parameter calling Write(). Also writes endl at the end automatically. More...
 
template<typename T >
auto & operator<< (const T &Value) const
 Writes the input parameter calling Write(). Also writes endl at the end automatically. More...
 
- Public Member Functions inherited from DynExp::HardwareAdapterBase
 HardwareAdapterBase (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
 Constructs a hardware adapter instance. More...
 
virtual ~HardwareAdapterBase ()=0
 
void ResetException () const
 Sets LastException to nullptr in a thread-safe way. More...
 
bool IsConnected () const noexcept
 Determines the connection status of the hardware interface. More...
 
- Public Member Functions inherited from Util::INonCopyable
 INonCopyable (const INonCopyable &)=delete
 
INonCopyableoperator= (const INonCopyable &)=delete
 
- Public Member Functions inherited from DynExp::Object
ItemIDType GetID () const noexcept
 Returns the ID of this Object instance. Thread-safe since ID is const. More...
 
std::string GetCategoryAndName () const
 Builds a string from an Object's category and name to allow the user to identify an Object's type. More...
 
void EnsureReadyState (bool IsAutomaticStartup)
 Ensures that this Object instance is ready by possibly starting its worker thread or by opening connections to hardware devices. More...
 
void CheckLinkedObjectStates () const
 Checks whether Object instances this instance uses are in a ready state. Override CheckLinkedObjectStatesChild() to implement this behavior. More...
 
void Reset ()
 Resets this Object instance (including all its derived classes) by calling ResetImpl(). A reset implies that the derived classes reload all their parameters from Params and that all LinkedObjectWrapper instances owned by this Object instance become invalidated. More...
 
void BlockIfUnused (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout)
 Blocks this Object instance setting Object::IsBlocked to true. Refer to Object::IsBlocked for the consequences. More...
 
ParamsConstTypeSyncPtrType GetParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Locks the mutex of the parameter class instance Params assigned to this Object instance and returns a pointer to the locked Params. More...
 
ParamsTypeSyncPtrType GetParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault)
 Locks the mutex of the parameter class instance Params assigned to this Object instance and returns a pointer to the locked Params. More...
 
auto GetObjectName (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Returns the name of this Object instance. More...
 
bool IsSharedUsageEnabled (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Returns whether shared usage has been enabled for this Object instance. Refer to ParamsBase::UsageType. More...
 
void SetWarning (std::string Description, int ErrorCode) const
 Setter for Object::Warning. Sets the warning by a description and an error code. More...
 
void SetWarning (const Util::Exception &e) const
 Setter for Object::Warning. Sets the warning by retrieving the warning data from an exception e. More...
 
void ClearWarning () const
 Resets Object::Warning. More...
 
auto GetWarning () const
 Returns Object::Warning in a thread-safe way by copying its internal data. More...
 
std::exception_ptr GetException (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns a pointer to the exception which has caused this Object instance to fail. More...
 
bool IsReady () const
 Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) and not blocked (refer to Object::IsBlocked). More...
 
auto GetUseCount (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Counts the registered useres in a thread-safe way. More...
 
bool IsUnused (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns whether this Object instance is used by other instances. More...
 
auto GetUserIDs (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Returns a list of the IDs of the registered users in a thread-safe way. More...
 
auto GetUserNamesString (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout) const
 Builds a string describing which users are registered containing their object names, categories and type names in a thread-safe way. More...
 

Static Public Member Functions

constexpr static auto Name () noexcept
 Every derived class has to redefine this function. More...
 
constexpr static auto Category () noexcept
 Every derived class has to redefine this function. More...
 
constexpr static std::array< char, 2 > LineEndingToChar (SerialCommunicationHardwareAdapterParams::LineEndingType LineEnding) noexcept
 Converts SerialCommunicationHardwareAdapterParams::LineEndingType to two characters being used as the respective line ending. More...
 
constexpr static unsigned int GetLineEndingLength (SerialCommunicationHardwareAdapterParams::LineEndingType LineEnding) noexcept
 Determines the amount of characters required to express a line ending type defined by SerialCommunicationHardwareAdapterParams::LineEndingType. More...
 
constexpr static auto GetMaxBufferSize () noexcept
 Defines the maximal size of the hardware adapter's (read) buffer. More...
 
- Static Public Member Functions inherited from DynExp::HardwareAdapterBase
constexpr static auto Category () noexcept
 Every derived class has to redefine this function. More...
 
- Static Public Member Functions inherited from DynExp::Object
static std::string CategoryAndNameToStr (const std::string &Category, const std::string &Name)
 Builds a string from an Object's category and name to allow the user to identify an Object's type. More...
 

Protected Member Functions

void InsertIntoBuffer (const std::string &String) const
 This method can be called from derived classes to manually insert data into the read buffer. This can be especially useful if there is some callback mechanism which notifies the derived object as soon as data is available. If this mechanism is used, it is fine to let the overridden Read() method just return en empty string. This function is thread-safe. More...
 
- Protected Member Functions inherited from DynExp::HardwareAdapterBase
void ThrowException (std::exception_ptr Exception) const
 Stores Exception in LastException, wraps it in a Util::ForwardedException and throws the wrapped excetion by calling Util::ForwardException(). More...
 
void ThrowExceptionUnsafe (std::exception_ptr Exception) const
 Stores Exception in LastException, wraps it in a Util::ForwardedException and throws the wrapped excetion by calling Util::ForwardException(). More...
 
void SetExceptionUnsafe (std::exception_ptr Exception) const
 Stores Exception in LastException. More...
 
auto GetExceptionUnsafe () const
 Getter for LastException. More...
 
- Protected Member Functions inherited from Util::ILockable
 ILockable ()=default
 
 ~ILockable ()=default
 
LockType AcquireLock (const std::chrono::milliseconds Timeout=DefaultTimeout) const
 Locks the internal mutex. Blocks until the mutex is locked or until the timeout duration is exceeded. More...
 
- Protected Member Functions inherited from Util::INonCopyable
constexpr INonCopyable ()=default
 
 ~INonCopyable ()=default
 
- Protected Member Functions inherited from DynExp::Object
 Object (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
 Constructs an Object instance. More...
 
virtual ~Object ()=0
 
void EnsureCallFromOwningThread () const
 Asserts that the call to this function is performed from the thread which constructed this Object instance (the thread with the id stored in Object::OwnerThreadID). More...
 
ParamsTypeSyncPtrType GetNonConstParams (const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
 Allows derived Objects to edit their own parameters - even in const task functions (for instruments) or event functions (for modules). More...
 
auto LockUserList (const std::chrono::milliseconds Timeout=Util::ILockable::DefaultTimeout)
 Locks the user list for thread-safe manipulation. More...
 
void DeregisterAllUnsafe ()
 Deregisters all users and notifies them that they need to check the states of their used linked objects. More...
 
auto GetUseCountUnsafe ()
 
auto GetUserNamesStringUnsafe () const
 
bool IsUnusedUnsafe ()
 Returns whether this Object instance is used by other instances (not thread-safe). More...
 

Private Member Functions

void Init ()
 Initializes the instance at construction or in case Object::Reset() is called. More...
 
void ResetImpl (dispatch_tag< HardwareAdapterBase >) override final
 Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy. More...
 
virtual void ResetImpl (dispatch_tag< SerialCommunicationHardwareAdapter >)
 Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy. More...
 
Not thread-safe

AcquireLock() has to be called manually before and returned LockType has to be still in scope.

void ReadIntoBuffer () const
 Calls Read() to retrieve data from the underlying hardware interface. Writes the retrieved data to the read buffer (ReadBuffer). More...
 
void ClearReadBuffer () const
 Clears the content and state flags of the read buffer (ReadBuffer) More...
 
bool CheckOverflow () const
 Checks whether the length of the read buffer (ReadBuffer) exceeds the maximal allowed length given by GetMaxBufferSize(). More...
 
Override, not thread-safe

Override by derived classes. AcquireLock() has to be called manually before and returned LockType has to be still in scope.

virtual void ClearChild () const
 Clears internal buffers of the underlying hardware interface. More...
 
virtual void FlushChild () const
 Flushes the underlying hardware interface. More...
 
virtual std::string Read () const =0
 Reads a string from the underlying hardware interface. More...
 
virtual void Write (const std::string &String) const =0
 Writes a string to the underlying hardware interface. More...
 
virtual void Write_endl () const =0
 Writes end of the line characters to the underlying hardware interface. More...
 

Private Attributes

std::atomic< SerialCommunicationHardwareAdapterParams::LineEndingTypeLineEnding = SerialCommunicationHardwareAdapterParams::LineEndingType::LF
 Copy of SerialCommunicationHardwareAdapterParams::LineEnding to avoid locking the corresponding SerialCommunicationHardwareAdapterParams instance every time data is read or sent. Refer to GetLineEnding(). More...
 
std::string LineEndingString
 String corresponding to LineEnding. Refer to LineEndingToChar() More...
 
std::stringstream ReadBuffer
 Buffer storing data read from the underlying physical hardware. More...
 

Additional Inherited Members

- Public Attributes inherited from DynExp::Object
LinkedObjectWrapperOnlyType LinkedObjectWrapperOnly
 Allow exclusive access to some of Object's private methods to any LinkedObjectWrapper<T>. More...
 
- Static Public Attributes inherited from DynExp::HardwareAdapterBase
static constexpr auto ShortTimeoutDefault = std::chrono::milliseconds(10)
 Default timeout e.g. used as a default for calls to Object::GetException(). More...
 
static constexpr auto HardwareOperationTimeout = std::chrono::milliseconds(100)
 Default timeout used to lock the mutex provided by the base class Util::ILockable to synchronize access to the hardware interface in between multiple instrument threads. More...
 
- Static Public Attributes inherited from Util::ILockable
static constexpr std::chrono::milliseconds DefaultTimeout = std::chrono::milliseconds(10)
 Duration which is used as a default timeout within all methods of this class if no different duration is passed to them. More...
 
- Static Public Attributes inherited from DynExp::Object
static constexpr std::chrono::milliseconds GetParamsTimeoutDefault = std::chrono::milliseconds(100)
 Default timeout used by Object::GetParams() to lock the mutex of the parameter instance assigned to this Object instance. More...
 
- Protected Types inherited from Util::ILockable
using MutexType = std::timed_mutex
 
using LockType = std::unique_lock< MutexType >
 

Detailed Description

Defines a hardware adapter for serial communication. Logical const-ness: see declaration of class DynExp::Object.

Definition at line 261 of file HardwareAdapter.h.


Class Documentation

◆ DynExp::SerialCommunicationHardwareAdapter::endl

struct DynExp::SerialCommunicationHardwareAdapter::endl

Type denoting the end of a line when piped to operator<<(endl)

Definition at line 270 of file HardwareAdapter.h.

Member Typedef Documentation

◆ ConfigType

Type of the configurator class belonging to this Object type. Declare this alias in every derived class with the respective configurator class accompanying the derived Object.

Definition at line 265 of file HardwareAdapter.h.

◆ ParamsType

Type of the parameter class belonging to this Object type. Declare this alias in every derived class with the respective parameter class accompanying the derived Object.

Definition at line 264 of file HardwareAdapter.h.

Constructor & Destructor Documentation

◆ SerialCommunicationHardwareAdapter()

DynExp::SerialCommunicationHardwareAdapter::SerialCommunicationHardwareAdapter ( const std::thread::id  OwnerThreadID,
ParamsBasePtrType &&  Params 
)

Constructs a hardware adapter instance.

Parameters
OwnerThreadIDThread id of the thread owning the Object instance to be constructed.
ParamsParameter class instance to be assigned to the Object instance to be constructed.
Exceptions
Util::InvalidArgExceptionis thrown if OwnerThreadID is an invalid thread id or if Params is nullptr.

Definition at line 140 of file HardwareAdapter.cpp.

◆ ~SerialCommunicationHardwareAdapter()

DynExp::SerialCommunicationHardwareAdapter::~SerialCommunicationHardwareAdapter ( )
pure virtual

Definition at line 136 of file HardwareAdapter.cpp.

Member Function Documentation

◆ Category()

constexpr static auto DynExp::SerialCommunicationHardwareAdapter::Category ( )
inlinestaticconstexprnoexcept

Every derived class has to redefine this function.

Returns
Returns the category of this hardware adapter type.

Definition at line 278 of file HardwareAdapter.h.

◆ CheckOverflow()

bool DynExp::SerialCommunicationHardwareAdapter::CheckOverflow ( ) const
private

Checks whether the length of the read buffer (ReadBuffer) exceeds the maximal allowed length given by GetMaxBufferSize().

Returns
Returns false in case of an overflow, true otherwise.

Definition at line 327 of file HardwareAdapter.cpp.

◆ Clear()

void DynExp::SerialCommunicationHardwareAdapter::Clear ( ) const

Clears the content and state flags of the read buffer (ReadBuffer) as well as possible internal buffers of the underlying hardware interface.

Definition at line 194 of file HardwareAdapter.cpp.

◆ ClearChild()

virtual void DynExp::SerialCommunicationHardwareAdapter::ClearChild ( ) const
inlineprivatevirtual

Clears internal buffers of the underlying hardware interface.

Reimplemented in DynExp::QSerialCommunicationHardwareAdapter.

Definition at line 467 of file HardwareAdapter.h.

◆ ClearReadBuffer()

void DynExp::SerialCommunicationHardwareAdapter::ClearReadBuffer ( ) const
private

Clears the content and state flags of the read buffer (ReadBuffer)

Definition at line 321 of file HardwareAdapter.cpp.

◆ Flush()

void DynExp::SerialCommunicationHardwareAdapter::Flush ( ) const

Flushes the underlying hardware interface and calls ReadIntoBuffer().

Definition at line 202 of file HardwareAdapter.cpp.

◆ FlushChild()

virtual void DynExp::SerialCommunicationHardwareAdapter::FlushChild ( ) const
inlineprivatevirtual

Flushes the underlying hardware interface.

Reimplemented in DynExp::QSerialCommunicationHardwareAdapter.

Definition at line 468 of file HardwareAdapter.h.

◆ GetCategory()

virtual std::string DynExp::SerialCommunicationHardwareAdapter::GetCategory ( ) const
inlineoverridevirtual

Returns the category of this Object type.

Reimplemented from DynExp::HardwareAdapterBase.

Definition at line 311 of file HardwareAdapter.h.

◆ GetLineEnding()

auto DynExp::SerialCommunicationHardwareAdapter::GetLineEnding ( ) const
inline

Getter for LineEnding. Thread-safe since LineEnding only changes when Object::Reset() is called (itself calling ResetImpl(dispatch_tag<HardwareAdapterBase>) which calls Init()). LineEnding is still std::atomic since QSerialCommunicationHardwareAdapterWorker running in DynExpCore's worker thread might read it anytime - even if there is no Object instance which makes use of this hardware adapter instance.

Returns
Returns LineEnding.

Definition at line 321 of file HardwareAdapter.h.

◆ GetLineEndingLength()

constexpr unsigned int DynExp::SerialCommunicationHardwareAdapter::GetLineEndingLength ( SerialCommunicationHardwareAdapterParams::LineEndingType  LineEnding)
staticconstexprnoexcept

Determines the amount of characters required to express a line ending type defined by SerialCommunicationHardwareAdapterParams::LineEndingType.

Parameters
LineEndingLine ending type
Returns
Number of char(acters) the specified line ending consists of

Definition at line 510 of file HardwareAdapter.h.

◆ GetMaxBufferSize()

constexpr static auto DynExp::SerialCommunicationHardwareAdapter::GetMaxBufferSize ( )
inlinestaticconstexprnoexcept

Defines the maximal size of the hardware adapter's (read) buffer.

Returns
Always returns a buffer length of 100 MB.

Definition at line 301 of file HardwareAdapter.h.

◆ GetName()

virtual std::string DynExp::SerialCommunicationHardwareAdapter::GetName ( ) const
inlineoverridevirtual

Returns the name of this Object type.

Implements DynExp::Object.

Reimplemented in DynExp::HardwareAdapterSerialPort, and DynExp::HardwareAdapterTcpSocket.

Definition at line 310 of file HardwareAdapter.h.

◆ Init()

void DynExp::SerialCommunicationHardwareAdapter::Init ( )
private

Initializes the instance at construction or in case Object::Reset() is called.

Definition at line 291 of file HardwareAdapter.cpp.

◆ InsertIntoBuffer()

void DynExp::SerialCommunicationHardwareAdapter::InsertIntoBuffer ( const std::string &  String) const
protected

This method can be called from derived classes to manually insert data into the read buffer. This can be especially useful if there is some callback mechanism which notifies the derived object as soon as data is available. If this mechanism is used, it is fine to let the overridden Read() method just return en empty string. This function is thread-safe.

Parameters
StringString to write to the buffer
Exceptions
Util::InvalidStateExceptionis thrown if fail flags of ReadBuffer are set after writing to it.

Definition at line 276 of file HardwareAdapter.cpp.

◆ LineEndingToChar()

constexpr std::array< char, 2 > DynExp::SerialCommunicationHardwareAdapter::LineEndingToChar ( SerialCommunicationHardwareAdapterParams::LineEndingType  LineEnding)
staticconstexprnoexcept

Converts SerialCommunicationHardwareAdapterParams::LineEndingType to two characters being used as the respective line ending.

Parameters
LineEndingLine ending type
Returns
Array of two char(acters) defining a line ending. If the respective line ending type consists of only one character, the second character in the returned array is '\0'.

Definition at line 499 of file HardwareAdapter.h.

◆ Name()

constexpr static auto DynExp::SerialCommunicationHardwareAdapter::Name ( )
inlinestaticconstexprnoexcept

Every derived class has to redefine this function.

Returns
Returns the name of this DynExp object type.

Definition at line 276 of file HardwareAdapter.h.

◆ operator<<() [1/7]

const SerialCommunicationHardwareAdapter & DynExp::SerialCommunicationHardwareAdapter::operator<< ( const char *  Text) const

Writes the input parameter calling Write(). Also writes endl at the end automatically.

Parameters
TextText to write
Returns
Reference to the SerialCommunicationHardwareAdapter instance the function is invoked on

Definition at line 256 of file HardwareAdapter.cpp.

◆ operator<<() [2/7]

const SerialCommunicationHardwareAdapter & DynExp::SerialCommunicationHardwareAdapter::operator<< ( const char  Char) const

Writes the input parameter calling Write(). Also writes endl at the end automatically.

Parameters
CharSingle character to write
Returns
Reference to the SerialCommunicationHardwareAdapter instance the function is invoked on

Definition at line 266 of file HardwareAdapter.cpp.

◆ operator<<() [3/7]

const SerialCommunicationHardwareAdapter & DynExp::SerialCommunicationHardwareAdapter::operator<< ( const std::string &  Text) const

Writes the input parameter calling Write(). Also writes endl at the end automatically.

Parameters
TextText to write
Returns
Reference to the SerialCommunicationHardwareAdapter instance the function is invoked on

Definition at line 236 of file HardwareAdapter.cpp.

◆ operator<<() [4/7]

const SerialCommunicationHardwareAdapter & DynExp::SerialCommunicationHardwareAdapter::operator<< ( const std::string_view  Text) const

Writes the input parameter calling Write(). Also writes endl at the end automatically.

Parameters
TextText to write
Returns
Reference to the SerialCommunicationHardwareAdapter instance the function is invoked on

Definition at line 246 of file HardwareAdapter.cpp.

◆ operator<<() [5/7]

const SerialCommunicationHardwareAdapter & DynExp::SerialCommunicationHardwareAdapter::operator<< ( const std::stringstream &  InStream) const

Writes the input parameter calling Write(). Also writes endl at the end automatically.

Parameters
InStreamStream whose contents to write
Returns
Reference to the SerialCommunicationHardwareAdapter instance the function is invoked on

Definition at line 226 of file HardwareAdapter.cpp.

◆ operator<<() [6/7]

template<typename T >
auto& DynExp::SerialCommunicationHardwareAdapter::operator<< ( const T &  Value) const
inline

Writes the input parameter calling Write(). Also writes endl at the end automatically.

Template Parameters
TType of the value to write
Parameters
ValueValue to write converting it to a string with Util::ToStr()
Returns
Reference to the SerialCommunicationHardwareAdapter instance the function is invoked on

Definition at line 408 of file HardwareAdapter.h.

◆ operator<<() [7/7]

const SerialCommunicationHardwareAdapter & DynExp::SerialCommunicationHardwareAdapter::operator<< ( endl  ) const

Writes a new line calling Write_endl().

Returns
Reference to the SerialCommunicationHardwareAdapter instance the function is invoked on

Definition at line 217 of file HardwareAdapter.cpp.

◆ operator>>()

const SerialCommunicationHardwareAdapter & DynExp::SerialCommunicationHardwareAdapter::operator>> ( std::stringstream &  OutStream) const

Writes the read buffer's content into OutStream calling ReadAll().

Parameters
OutStreamStream to write the read data to
Returns
Reference to the SerialCommunicationHardwareAdapter instance the function is invoked on

Definition at line 210 of file HardwareAdapter.cpp.

◆ Read()

virtual std::string DynExp::SerialCommunicationHardwareAdapter::Read ( ) const
privatepure virtual

Reads a string from the underlying hardware interface.

Returns
String read from the hardware interface

Implemented in DynExp::QSerialCommunicationHardwareAdapter.

◆ ReadAll()

std::string DynExp::SerialCommunicationHardwareAdapter::ReadAll ( ) const

Calls ReadIntoBuffer() before it extracts the entire content from the read buffer.

Returns
Content of the read buffer

Definition at line 167 of file HardwareAdapter.cpp.

◆ ReadIntoBuffer()

void DynExp::SerialCommunicationHardwareAdapter::ReadIntoBuffer ( ) const
private

Calls Read() to retrieve data from the underlying hardware interface. Writes the retrieved data to the read buffer (ReadBuffer).

Exceptions
Util::InvalidStateExceptionis thrown if fail flags of ReadBuffer are set after writing to it.

Definition at line 307 of file HardwareAdapter.cpp.

◆ ReadLine()

std::string DynExp::SerialCommunicationHardwareAdapter::ReadLine ( ) const

Calls ReadIntoBuffer() before it extracts the first line from the read buffer.

Returns
First line from the read buffer or an empty string if the read buffer does not contain a full line.

Definition at line 146 of file HardwareAdapter.cpp.

◆ ResetImpl() [1/2]

void DynExp::SerialCommunicationHardwareAdapter::ResetImpl ( dispatch_tag< HardwareAdapterBase )
finaloverrideprivatevirtual

Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy.

Implements DynExp::HardwareAdapterBase.

Definition at line 299 of file HardwareAdapter.cpp.

◆ ResetImpl() [2/2]

virtual void DynExp::SerialCommunicationHardwareAdapter::ResetImpl ( dispatch_tag< SerialCommunicationHardwareAdapter )
inlineprivatevirtual

Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every derived class gets called - starting from DynExp::Object, descending the inheritance hierarchy.

Reimplemented in DynExp::QSerialCommunicationHardwareAdapter.

Definition at line 435 of file HardwareAdapter.h.

◆ WaitForLine()

std::string DynExp::SerialCommunicationHardwareAdapter::WaitForLine ( unsigned int  NumTries = 10,
std::chrono::milliseconds  DelayBetweenTries = std::chrono::milliseconds(10) 
) const

Calls ReadLine() for NumTries times until a line is received. Makes the calling thread sleep for DelayBetweenTries in between the calls to ReadLine().

Parameters
NumTriesNumber of attempts to read a line from the read buffer
DelayBetweenTriesTime to wait between subsequent attempts to read a line
Returns
First line from the read buffer or an empty string if the read buffer did not receive a full line during the read attempts.

Definition at line 179 of file HardwareAdapter.cpp.

◆ Write()

virtual void DynExp::SerialCommunicationHardwareAdapter::Write ( const std::string &  String) const
privatepure virtual

Writes a string to the underlying hardware interface.

Parameters
StringString to write

Implemented in DynExp::QSerialCommunicationHardwareAdapter.

◆ Write_endl()

virtual void DynExp::SerialCommunicationHardwareAdapter::Write_endl ( ) const
privatepure virtual

Writes end of the line characters to the underlying hardware interface.

Implemented in DynExp::QSerialCommunicationHardwareAdapter.

Member Data Documentation

◆ LineEnding

std::atomic<SerialCommunicationHardwareAdapterParams::LineEndingType> DynExp::SerialCommunicationHardwareAdapter::LineEnding = SerialCommunicationHardwareAdapterParams::LineEndingType::LF
private

Copy of SerialCommunicationHardwareAdapterParams::LineEnding to avoid locking the corresponding SerialCommunicationHardwareAdapterParams instance every time data is read or sent. Refer to GetLineEnding().

Definition at line 493 of file HardwareAdapter.h.

◆ LineEndingString

std::string DynExp::SerialCommunicationHardwareAdapter::LineEndingString
private

String corresponding to LineEnding. Refer to LineEndingToChar()

Definition at line 495 of file HardwareAdapter.h.

◆ ReadBuffer

std::stringstream DynExp::SerialCommunicationHardwareAdapter::ReadBuffer
mutableprivate

Buffer storing data read from the underlying physical hardware.

Definition at line 496 of file HardwareAdapter.h.


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