DynExp
Highly flexible laboratory automation for dynamically changing experiments.
|
Implements a hardware adapter to communicate with text-based commands over TCP sockets. More...
Public Types | |
using | ParamsType = HardwareAdapterTcpSocketParams |
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 = HardwareAdapterTcpSocketConfigurator |
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::QSerialCommunicationHardwareAdapter | |
using | ParamsType = QSerialCommunicationHardwareAdapterParams |
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 = QSerialCommunicationHardwareAdapterConfigurator |
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 | QWorkerPtrType = std::unique_ptr< QSerialCommunicationHardwareAdapterWorker > |
Pointer-type owning the related QSerialCommunicationHardwareAdapterWorker instance. More... | |
Public Types inherited from DynExp::SerialCommunicationHardwareAdapter | |
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... | |
Signals | |
Qt signals | |
Signals emitted by this hardware adapter. The worker instance's slots are connected to them to handles the signals. | |
void | InitSig (QString ServerName, quint16 Port) |
Initializes HardwareAdapterTcpSocketWorker::Socket for TCP communication with the given settings. More... | |
Signals inherited from DynExp::QSerialCommunicationHardwareAdapter | |
void | OpenSig () |
Opens the communication connection. More... | |
void | CloseSig () |
Closes the communication connection. More... | |
void | ResetSig () |
Resets the worker and the communication connection. More... | |
void | ClearSig () const |
Clears the communication connection's buffers and state. More... | |
void | FlushSig () const |
Flushes the communication connection's buffers. More... | |
void | ReadSig () const |
Reads from the communication connection's hardware interface. More... | |
void | WriteSig (const QString String) const |
Writes String to the communication connection's hardware interface. More... | |
void | Write_endl_Sig () const |
Writes end of the line character(s) to the communication connection's hardware interface. More... | |
Public Member Functions | |
HardwareAdapterTcpSocket (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params) | |
Constructs a hardware adapter instance. More... | |
virtual | ~HardwareAdapterTcpSocket ()=default |
virtual std::string | GetName () const override |
Returns the name of this Object type. More... | |
Public Member Functions inherited from DynExp::QSerialCommunicationHardwareAdapter | |
QSerialCommunicationHardwareAdapter (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params) | |
Constructs a hardware adapter instance. More... | |
virtual | ~QSerialCommunicationHardwareAdapter ()=0 |
Public Member Functions inherited from DynExp::SerialCommunicationHardwareAdapter | |
SerialCommunicationHardwareAdapter (const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params) | |
Constructs a hardware adapter instance. More... | |
virtual | ~SerialCommunicationHardwareAdapter ()=0 |
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 SerialCommunicationHardwareAdapter & | operator>> (std::stringstream &OutStream) const |
Writes the read buffer's content into OutStream calling ReadAll() . More... | |
const SerialCommunicationHardwareAdapter & | operator<< (endl) const |
Writes a new line calling Write_endl() . More... | |
const SerialCommunicationHardwareAdapter & | operator<< (const std::stringstream &InStream) const |
Writes the input parameter calling Write() . Also writes endl at the end automatically. More... | |
const SerialCommunicationHardwareAdapter & | operator<< (const std::string &Text) const |
Writes the input parameter calling Write() . Also writes endl at the end automatically. More... | |
const SerialCommunicationHardwareAdapter & | operator<< (const std::string_view Text) const |
Writes the input parameter calling Write() . Also writes endl at the end automatically. More... | |
const SerialCommunicationHardwareAdapter & | operator<< (const char *Text) const |
Writes the input parameter calling Write() . Also writes endl at the end automatically. More... | |
const SerialCommunicationHardwareAdapter & | operator<< (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 | |
INonCopyable & | operator= (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... | |
Static Public Member Functions inherited from DynExp::SerialCommunicationHardwareAdapter | |
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... | |
Private Member Functions | |
QWorkerPtrType | MakeWorker () override |
Abstract factory function for a worker instance derived from QSerialCommunicationHardwareAdapterWorker . Also connects Qt signals to the worker instance's slots. More... | |
void | InitWorker () override |
Tells the worker instance to perform initialization steps, e.g. by emitting a Qt signal which is received by the worker's slots. More... | |
void | Init () |
Initializes the instance at construction or in case Object::Reset() is called. More... | |
void | ResetImpl (dispatch_tag< QSerialCommunicationHardwareAdapter >) 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< HardwareAdapterTcpSocket >) |
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... | |
Additional Inherited Members | |
Public Attributes inherited from DynExp::QSerialCommunicationHardwareAdapter | |
QSerialCommunicationHardwareAdapterWorkerOnlyType | QSerialCommunicationHardwareAdapterWorkerOnly |
Allow exclusive access to some of QSerialCommunicationHardwareAdapter's private methods to QSerialCommunicationHardwareAdapterWorkerOnlyType. More... | |
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 > |
Protected Member Functions inherited from DynExp::SerialCommunicationHardwareAdapter | |
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... | |
Implements a hardware adapter to communicate with text-based commands over TCP sockets.
Definition at line 185 of file HardwareAdapterEthernet.h.
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 191 of file HardwareAdapterEthernet.h.
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 190 of file HardwareAdapterEthernet.h.
DynExp::HardwareAdapterTcpSocket::HardwareAdapterTcpSocket | ( | const std::thread::id | OwnerThreadID, |
ParamsBasePtrType && | Params | ||
) |
Constructs a hardware adapter instance.
OwnerThreadID | Thread id of the thread owning the Object instance to be constructed. |
Params | Parameter class instance to be assigned to the Object instance to be constructed. |
Util::InvalidArgException | is thrown if OwnerThreadID is an invalid thread id or if Params is nullptr. |
Definition at line 114 of file HardwareAdapterEthernet.cpp.
|
virtualdefault |
|
inlineoverridevirtual |
Returns the name of this Object
type.
Reimplemented from DynExp::SerialCommunicationHardwareAdapter.
Definition at line 198 of file HardwareAdapterEthernet.h.
|
private |
Initializes the instance at construction or in case Object::Reset() is called.
Util::OutOfRangeException | is thrown if the port specified in NetworkParamsExtension::Port of the parameter class instance related to this hardware adaper instance is lower than 1 or higher than 65535. |
Definition at line 128 of file HardwareAdapterEthernet.cpp.
|
signal |
Initializes HardwareAdapterTcpSocketWorker::Socket for TCP communication with the given settings.
ServerName | IP address |
Port | Network port |
|
inlineoverrideprivatevirtual |
Tells the worker instance to perform initialization steps, e.g. by emitting a Qt signal which is received by the worker's slots.
Reimplemented from DynExp::QSerialCommunicationHardwareAdapter.
Definition at line 202 of file HardwareAdapterEthernet.h.
|
overrideprivatevirtual |
Abstract factory function for a worker instance derived from QSerialCommunicationHardwareAdapterWorker
. Also connects Qt signals to the worker instance's slots.
Implements DynExp::QSerialCommunicationHardwareAdapter.
Definition at line 119 of file HardwareAdapterEthernet.cpp.
|
inlinestaticconstexprnoexcept |
Every derived class has to redefine this function.
Definition at line 193 of file HardwareAdapterEthernet.h.
|
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.
Definition at line 213 of file HardwareAdapterEthernet.h.
|
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.
Reimplemented from DynExp::QSerialCommunicationHardwareAdapter.
Definition at line 139 of file HardwareAdapterEthernet.cpp.