11 #include <QtSerialPort/QSerialPort>
12 #include <QtSerialPort/QSerialPortInfo>
19 class HardwareAdapterSerialPort;
35 const std::source_location Location = std::source_location::current()) noexcept
54 virtual const char*
GetParamClassTag() const noexcept
override {
return "HardwareAdapterSerialPortParams"; }
57 "Name of the serial port to be assigned to this hardware adapter" };
59 "Data rate in bits per second",
true, QSerialPort::Baud9600 };
61 "Number of data bits in each character",
true, QSerialPort::Data8 };
63 "Number of stop bits after each character",
true, QSerialPort::OneStop };
65 "Error detection method",
true, QSerialPort::NoParity };
72 void ConfigureParamsImpl(dispatch_tag<QSerialCommunicationHardwareAdapterParams>)
override final;
114 void Init(QString PortName, QSerialPort::BaudRate BaudRate, QSerialPort::DataBits DataBits,
115 QSerialPort::StopBits StopBits, QSerialPort::Parity Parity);
127 bool CheckError(
const std::source_location Location = std::source_location::current())
const;
135 virtual void WriteChild(
const QString& String)
override;
153 constexpr
static auto Name() noexcept {
return "Serial Port"; }
178 void ResetImpl(dispatch_tag<QSerialCommunicationHardwareAdapter>)
override final;
190 void InitSig(QString PortName, QSerialPort::BaudRate BaudRate, QSerialPort::DataBits DataBits,
191 QSerialPort::StopBits StopBits, QSerialPort::Parity Parity);
Implementation of DynExp hardware adapter objects.
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Defines the base class for a hardware adapter object. Hardware adapters describe interfaces/connectio...
Configurator class for HardwareAdapterBase.
Parameter class for HardwareAdapterBase.
Configurator class for HardwareAdapterSerialPort.
virtual DynExp::ParamsBasePtrType MakeParams(ItemIDType ID, const DynExpCore &Core) const override
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
virtual ~HardwareAdapterSerialPortConfigurator()=default
HardwareAdapterSerialPortConfigurator()=default
Parameter class for HardwareAdapterSerialPort.
Param< QSerialPort::StopBits > StopBits
Amount of stop bits.
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
Param< QSerialPort::DataBits > DataBits
Amount of data bits.
HardwareAdapterSerialPortParams(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a HardwareAdapterSerialPort instance.
virtual ~HardwareAdapterSerialPortParams()=default
void ConfigureParamsImpl(dispatch_tag< QSerialCommunicationHardwareAdapterParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Param< QSerialPort::BaudRate > BaudRate
Baud rate.
virtual void ConfigureParamsImpl(dispatch_tag< HardwareAdapterSerialPortParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Param< TextList > PortName
COM port name.
Param< QSerialPort::Parity > Parity
Parity setting.
Qt worker for serial/COM port communication in a separate thread.
HardwareAdapterSerialPortWorker()
bool CheckError(const std::source_location Location=std::source_location::current()) const
Checks whether Port is in an error state. If this is the case, sets an exception using QSerialCommuni...
virtual void ResetChild() override
Resets the worker and the communication connection.
virtual ~HardwareAdapterSerialPortWorker()
virtual void Write_endl_Child() override
Writes end of the line character(s) to the communication connection's hardware interface.
virtual void FlushChild() override
Flushes the communication connection's buffers.
virtual void ClearChild() override
Clears the communication connection's buffers and state.
QSerialPort Port
COM port for serial communication.
virtual void CloseChild() override
Closes the communication connection.
void Init(QString PortName, QSerialPort::BaudRate BaudRate, QSerialPort::DataBits DataBits, QSerialPort::StopBits StopBits, QSerialPort::Parity Parity)
Initializes HardwareAdapterSerialPortWorker::Port for serial communication with the given settings.
virtual void ReadChild() override
Reads from the communication connection's hardware interface.
virtual void WriteChild(const QString &String) override
Writes String to the communication connection's hardware interface.
virtual void OpenChild() override
Opens the communication connection.
void OnDataAvailable()
Qt slot called when Port has received data which can be read.
Implements a hardware adapter to communicate with text-based commands over COM ports.
void Init()
Initializes the instance at construction or in case Object::Reset() is called.
QWorkerPtrType MakeWorker() override
Abstract factory function for a worker instance derived from QSerialCommunicationHardwareAdapterWorke...
static auto Enumerate()
Enumerates all serial ports available on the system.
void RegisterQTypesAsMetaTypes()
Registers QSerialPort enumerations as Qt meta types using qRegisterMetaType() (refer to Qt documentat...
void InitSig(QString PortName, QSerialPort::BaudRate BaudRate, QSerialPort::DataBits DataBits, QSerialPort::StopBits StopBits, QSerialPort::Parity Parity)
Initializes HardwareAdapterSerialPortWorker::Port for serial communication with the given settings.
HardwareAdapterSerialPort(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a hardware adapter instance.
void InitWorker() override
Tells the worker instance to perform initialization steps, e.g. by emitting a Qt signal which is rece...
virtual ~HardwareAdapterSerialPort()=default
virtual std::string GetName() const override
Returns the name of this Object type.
constexpr static auto Name() noexcept
Every derived class has to redefine this function.
void ResetImpl(dispatch_tag< QSerialCommunicationHardwareAdapter >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual void ResetImpl(dispatch_tag< HardwareAdapterSerialPort >)
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Refer to ParamsBase::dispatch_tag.
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
const DynExpCore & Core
Reference to DynExp's core.
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Configurator class for QSerialCommunicationHardwareAdapter.
Parameter class for QSerialCommunicationHardwareAdapter.
Qt worker which performs actual serial communication hardware operations in a separate thread in orde...
SerialCommunicationHardwareAdapter is based on a Qt communication object (wrapped by QSerialCommunica...
std::unique_ptr< QSerialCommunicationHardwareAdapterWorker > QWorkerPtrType
Pointer-type owning the related QSerialCommunicationHardwareAdapterWorker instance.
Defines an exception caused by a serial communication operation of a hardware adapter.
Defines an exception caused by a hardware operation on a COM port (e.g. reading/writing data to a COM...
SerialPortException(std::string Description, const int ErrorCode, const std::source_location Location=std::source_location::current()) noexcept
Constructs a SerialPortException instance.
const int ErrorCode
DynExp error code from DynExpErrorCodes::DynExpErrorCodes
DynExp's main namespace contains the implementation of DynExp including classes to manage resources (...
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
size_t ItemIDType
ID type of objects/items managed by DynExp.
Accumulates include statements to provide a precompiled header.