DynExp
Highly flexible laboratory automation for dynamically changing experiments.
AnalogOut.h
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
9 #pragma once
10 
11 #include "stdafx.h"
12 #include "OutputPort.h"
13 
14 namespace DynExpInstr
15 {
16  class AnalogOut;
17 
21  namespace AnalogOutTasks
22  {
27  {
29 
34 
39 
44  virtual bool ApplyLimits() const noexcept { return true; }
46  };
47 
52  {
54 
59  };
60 
65  {
67 
72  };
73  }
74 
79  {
80  public:
82 
89  AnalogOutData(size_t BufferSizeInSamples = 1) : OutputPortData(std::make_unique<SampleStreamType>(BufferSizeInSamples)) {}
90 
95 
96  virtual ~AnalogOutData() = default;
97 
98  private:
99  void ResetImpl(dispatch_tag<OutputPortData>) override final;
101  };
102 
107  {
108  public:
114  : OutputPortParams(ID, Core) {}
115 
116  virtual ~AnalogOutParams() = 0;
117 
118  virtual const char* GetParamClassTag() const noexcept override { return "AnalogOutParams"; }
119 
124  Param<ParamsConfigDialog::NumberType> DefaultValue = { *this, "DefaultValue", "Default value",
125  "Value to be written to this output port after it has been initialized and before it is stopped.", false,
126  0, std::numeric_limits<ParamsConfigDialog::NumberType>::lowest(), std::numeric_limits<ParamsConfigDialog::NumberType>::max(), 1, 3 };
127 
135  Param<ParamsConfigDialog::NumberType> MinValue = { *this, "MinValue", "Minimal value",
136  "Lower limit the values written to this output port must not exceed.", true,
137  -5, std::numeric_limits<ParamsConfigDialog::NumberType>::lowest(), std::numeric_limits<ParamsConfigDialog::NumberType>::max(), 1, 3 };
138 
146  Param<ParamsConfigDialog::NumberType> MaxValue = { *this, "MaxValue", "Maximal value",
147  "Upper limit the values written to this output port must not exceed.", true,
148  5, std::numeric_limits<ParamsConfigDialog::NumberType>::lowest(), std::numeric_limits<ParamsConfigDialog::NumberType>::max(), 1, 3 };
149 
150  protected:
151  void DisableUserEditable();
152 
153  private:
156  };
157 
162  {
163  public:
166 
168  virtual ~AnalogOutConfigurator() = 0;
169  };
170 
175  class AnalogOut : public OutputPort
176  {
177  public:
181 
190 
191  constexpr static auto Name() noexcept { return "Analog Out"; }
192  constexpr static auto Category() noexcept { return "I/O"; }
193 
198  : OutputPort(OwnerThreadID, std::move(Params)) {}
199 
200  virtual ~AnalogOut() = 0;
201 
202  virtual std::string GetName() const override { return Name(); }
203  virtual std::string GetCategory() const override { return Category(); }
204 
211  virtual DataStreamInstrumentData::ValueType GetUserMinValue() const override;
212  virtual DataStreamInstrumentData::ValueType GetUserMaxValue() const override;
213 
222 
229 
235  virtual void Set(AnalogOutData::SampleStreamType::SampleType Sample, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
236 
241  virtual void SetSync(AnalogOutData::SampleStreamType::SampleType Sample) const;
242 
249  virtual void SetDefault(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
251 
252  private:
253  virtual void OnPrepareExitChild() const override;
254 
255  void ResetImpl(dispatch_tag<OutputPort>) override final;
256  virtual void ResetImpl(dispatch_tag<AnalogOut>) = 0;
257 
258  virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<AnalogOutTasks::InitTask>(); }
259  virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<AnalogOutTasks::ExitTask>(); }
260  virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<AnalogOutTasks::UpdateTask>(); }
261  };
262 }
Defines a generic output port meta instrument which is used to extract data from a data stream and to...
Configurator class for AnalogOut.
Definition: AnalogOut.h:162
Data class for AnalogOut.
Definition: AnalogOut.h:79
virtual void ResetImpl(dispatch_tag< AnalogOutData >)
Definition: AnalogOut.h:100
virtual ~AnalogOutData()=default
AnalogOutData(DataStreamBasePtrType &&SampleStream)
Constructs a DataStreamInstrumentData instance.
Definition: AnalogOut.h:94
AnalogOutData(size_t BufferSizeInSamples=1)
Constructs a DataStreamInstrumentData instance.
Definition: AnalogOut.h:89
void ResetImpl(dispatch_tag< OutputPortData >) override final
Definition: AnalogOut.cpp:26
Parameter class for AnalogOut.
Definition: AnalogOut.h:107
virtual void ConfigureParamsImpl(dispatch_tag< AnalogOutParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: AnalogOut.h:155
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...
Definition: AnalogOut.h:118
Param< ParamsConfigDialog::NumberType > MinValue
In contrast to the hardware limits (minimal value the underlying hardware can generate),...
Definition: AnalogOut.h:135
Param< ParamsConfigDialog::NumberType > MaxValue
In contrast to the hardware limits (maximal value the underlying hardware can generate),...
Definition: AnalogOut.h:146
AnalogOutParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a AnalogOut instance.
Definition: AnalogOut.h:113
Param< ParamsConfigDialog::NumberType > DefaultValue
Default value to be written to the output port after initialization and after termination of this ins...
Definition: AnalogOut.h:124
void DisableUserEditable()
Calls DynExp::ParamsBase::DisableUserEditable() on all bundled parameters.
Definition: AnalogOut.cpp:35
void ConfigureParamsImpl(dispatch_tag< OutputPortParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: AnalogOut.h:154
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition: AnalogOut.h:52
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition: AnalogOut.h:58
void ExitFuncImpl(dispatch_tag< OutputPortTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition: AnalogOut.cpp:21
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: AnalogOut.h:27
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Initializes the respective instrument within the instrument inheritance hierarchy....
Definition: AnalogOut.h:33
void InitFuncImpl(dispatch_tag< OutputPortTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
Definition: AnalogOut.cpp:8
virtual bool ApplyLimits() const noexcept
Indicates whether value limits are to be applied to the data stream of the AnalogOut instrument.
Definition: AnalogOut.h:44
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition: AnalogOut.h:65
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Definition: AnalogOut.h:71
void UpdateFuncImpl(dispatch_tag< OutputPortTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Definition: AnalogOut.h:66
Meta instrument for a single analog output port based on the data stream, function generator,...
Definition: AnalogOut.h:176
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
Definition: AnalogOut.h:259
virtual void SetDefault(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Writes AnalogOutParams::DefaultValue to the sample stream. CallbackFunc gets called after the task Da...
Definition: AnalogOut.cpp:78
virtual void OnPrepareExitChild() const override
This function enables derived classes to enqueue tasks to be executed directly before the final exit ...
Definition: AnalogOut.cpp:95
virtual std::string GetName() const override
Returns the name of this Object type.
Definition: AnalogOut.h:202
virtual std::string GetCategory() const override
Returns the category of this Object type.
Definition: AnalogOut.h:203
void ResetImpl(dispatch_tag< OutputPort >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
Definition: AnalogOut.cpp:100
virtual void Set(AnalogOutData::SampleStreamType::SampleType Sample, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Writes one sample to the sample stream. CallbackFunc gets called after the task DataStreamInstrument:...
Definition: AnalogOut.cpp:62
constexpr static auto Category() noexcept
Every derived class has to redefine this function.
Definition: AnalogOut.h:192
virtual DataStreamInstrumentData::ValueType GetUserMaxValue() const override
Indicates the maximal allowed value to generate as defined by the user/software. This value should be...
Definition: AnalogOut.cpp:56
constexpr static auto Name() noexcept
Every derived class has to redefine this function.
Definition: AnalogOut.h:191
virtual DataStreamInstrumentData::ValueType GetUserMinValue() const override
Indicates the minimal allowed value to generate as defined by the user/software. This value should be...
Definition: AnalogOut.cpp:50
virtual std::unique_ptr< DynExp::UpdateTaskBase > MakeUpdateTask() const override
Factory function for an update task (UpdateTaskBase). Override to define the desired update task in d...
Definition: AnalogOut.h:260
virtual DataStreamInstrumentData::UnitType GetValueUnit() const override
Determines which unit corresponds to the values managed by this DataStreamInstrument instance....
Definition: AnalogOut.h:210
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
Definition: AnalogOut.h:258
virtual ~AnalogOut()=0
Definition: AnalogOut.cpp:46
virtual void SetSync(AnalogOutData::SampleStreamType::SampleType Sample) const
Synchronized version of Set(), which blocks until Sample has been written.
Definition: AnalogOut.cpp:73
AnalogOut(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs an instrument instance.
Definition: AnalogOut.h:197
virtual NumericSampleStreamParamsExtension::ValueType GetNumericSampleStreamParams() const
Retrieves sample stream settings of the instrument's data stream from the instrument's or from the un...
Definition: AnalogOut.h:220
virtual void ResetImpl(dispatch_tag< AnalogOut >)=0
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
SampleT SampleType
Alias for SampleT.
UnitType
Units which can be used for data stream instruments.
double ValueType
Data type to represent hardware limits on the sample values to write to the hardware adapter assigned...
const DataStreamBasePtrType SampleStream
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()...
Type containing the values of all the parameters belonging to NumericSampleStreamParamsExtension.
Implements a circular data stream based on Util::circularbuf using samples of an arithmetic type Samp...
Configurator class for OutputPort.
Definition: OutputPort.h:143
Data class for OutputPort.
Definition: OutputPort.h:98
Parameter class for OutputPort.
Definition: OutputPort.h:116
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition: OutputPort.h:54
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: OutputPort.h:27
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition: OutputPort.h:67
Generic output port meta instrument based on the data stream and function generator meta instruments ...
Definition: OutputPort.h:158
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition: DynExpCore.h:127
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition: Instrument.h:1144
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1151
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: Instrument.h:1113
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1120
Base class for instruments. Instruments comprise virtual devices (meta instruments) and physial devic...
Definition: Instrument.h:451
Configurator class for InstrumentBase.
Definition: Instrument.h:435
Data structure to contain data which is synchronized in between different threads....
Definition: Instrument.h:135
Refer to ParamsBase::dispatch_tag.
Definition: Instrument.h:146
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition: Instrument.h:772
Parameter class for InstrumentBase.
Definition: Instrument.h:401
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition: Object.h:2302
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition: Object.h:2303
Refer to ParamsBase::dispatch_tag.
Definition: Object.h:2018
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
Definition: Object.h:1779
const DynExpCore & Core
Reference to DynExp's core.
Definition: Object.h:1780
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Definition: Object.h:349
std::function< void(const TaskBase &, ExceptionContainer &)> CallbackType
Type of a callback function which is invoked when a task has finished, failed or has been aborted....
Definition: Instrument.h:939
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition: Instrument.h:1175
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1182
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
Definition: Instrument.h:1254
NumericSampleStream< double > AnalogSampleStream
Alias for a numeric sample stream of double samples.
DataStreamPtrType< DataStreamBase > DataStreamBasePtrType
Type of a pointer owning a DataStreamBase instance.
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition: Object.h:1807
size_t ItemIDType
ID type of objects/items managed by DynExp.
Accumulates include statements to provide a precompiled header.