DynExp
Highly flexible laboratory automation for dynamically changing experiments.
DigitalOut.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 DigitalOut;
17 
21  namespace DigitalOutTasks
22  {
27  {
29 
34  };
35 
40  {
42 
47  };
48 
53  {
55 
60  };
61  }
62 
67  {
68  public:
70 
77  DigitalOutData(size_t BufferSizeInSamples = 1) : OutputPortData(std::make_unique<SampleStreamType>(BufferSizeInSamples)) {}
78 
83 
84  virtual ~DigitalOutData() = default;
85 
86  private:
87  void ResetImpl(dispatch_tag<OutputPortData>) override final;
89  };
90 
95  {
96  public:
102  : OutputPortParams(ID, Core) {}
103 
104  virtual ~DigitalOutParams() = 0;
105 
106  virtual const char* GetParamClassTag() const noexcept override { return "DigitalOutParams"; }
107 
112  Param<ParamsConfigDialog::NumberType> DefaultValue = { *this, "DefaultValue", "Default value",
113  "Value to be written to this output port after it has been initialized and before it is stopped.", false, 0, 0, 1, 1, 0 };
114 
115  protected:
116  void DisableUserEditable();
117 
118  private:
121  };
122 
127  {
128  public:
131 
133  virtual ~DigitalOutConfigurator() = 0;
134  };
135 
140  class DigitalOut : public OutputPort
141  {
142  public:
146 
155 
156  constexpr static auto Name() noexcept { return "Digital Out"; }
157  constexpr static auto Category() noexcept { return "I/O"; }
158 
163  : OutputPort(OwnerThreadID, std::move(Params)) {}
164 
165  virtual ~DigitalOut() = 0;
166 
167  virtual std::string GetName() const override { return Name(); }
168  virtual std::string GetCategory() const override { return Category(); }
169 
175  virtual DataStreamInstrumentData::ValueType GetHardwareMinValue() const noexcept override final { return 0; }
176  virtual DataStreamInstrumentData::ValueType GetHardwareMaxValue() const noexcept override final { return 1; }
177  virtual DataStreamInstrumentData::ValueType GetHardwareResolution() const noexcept override final { return 1; }
181 
190 
197 
203  virtual void Set(DigitalOutData::SampleStreamType::SampleType Sample, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
204 
209  virtual void SetSync(DigitalOutData::SampleStreamType::SampleType Sample) const;
210 
217  virtual void SetDefault(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
219 
220  private:
221  virtual void OnPrepareExitChild() const override;
222 
223  void ResetImpl(dispatch_tag<OutputPort>) override final;
225 
226  virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<DigitalOutTasks::InitTask>(); }
227  virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<DigitalOutTasks::ExitTask>(); }
228  virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<DigitalOutTasks::UpdateTask>(); }
229  };
230 }
Defines a generic output port meta instrument which is used to extract data from a data stream and to...
SampleT SampleType
Alias for SampleT.
UnitType
Units which can be used for data stream instruments.
@ LogicLevel
Logic level (TTL) units (1 or 0)
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()...
Configurator class for DigitalOut.
Definition: DigitalOut.h:127
Data class for DigitalOut.
Definition: DigitalOut.h:67
DigitalOutData(DataStreamBasePtrType &&SampleStream)
Constructs a DataStreamInstrumentData instance.
Definition: DigitalOut.h:82
virtual ~DigitalOutData()=default
void ResetImpl(dispatch_tag< OutputPortData >) override final
Definition: DigitalOut.cpp:18
virtual void ResetImpl(dispatch_tag< DigitalOutData >)
Definition: DigitalOut.h:88
DigitalOutData(size_t BufferSizeInSamples=1)
Constructs a DataStreamInstrumentData instance.
Definition: DigitalOut.h:77
Parameter class for DigitalOut.
Definition: DigitalOut.h:95
virtual void ConfigureParamsImpl(dispatch_tag< DigitalOutParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: DigitalOut.h:120
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: DigitalOut.h:106
Param< ParamsConfigDialog::NumberType > DefaultValue
Default value to be written to the output port after initialization and after termination of this ins...
Definition: DigitalOut.h:112
void DisableUserEditable()
Calls DynExp::ParamsBase::DisableUserEditable() on all bundled parameters.
Definition: DigitalOut.cpp:27
DigitalOutParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a DigitalOut instance.
Definition: DigitalOut.h:101
void ConfigureParamsImpl(dispatch_tag< OutputPortParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: DigitalOut.h:119
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition: DigitalOut.h:40
void ExitFuncImpl(dispatch_tag< OutputPortTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition: DigitalOut.cpp:13
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition: DigitalOut.h:46
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: DigitalOut.h:27
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Initializes the respective instrument within the instrument inheritance hierarchy....
Definition: DigitalOut.h:33
void InitFuncImpl(dispatch_tag< OutputPortTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
Definition: DigitalOut.cpp:8
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition: DigitalOut.h:53
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Definition: DigitalOut.h:59
void UpdateFuncImpl(dispatch_tag< OutputPortTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Definition: DigitalOut.h:54
Meta instrument for a single digital output port based on the data stream, function generator,...
Definition: DigitalOut.h:141
constexpr static auto Name() noexcept
Every derived class has to redefine this function.
Definition: DigitalOut.h:156
virtual void SetDefault(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Writes DigitalOutParams::DefaultValue to the sample stream. CallbackFunc gets called after the task D...
Definition: DigitalOut.cpp:56
virtual void OnPrepareExitChild() const override
This function enables derived classes to enqueue tasks to be executed directly before the final exit ...
Definition: DigitalOut.cpp:73
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: DigitalOut.h:228
void ResetImpl(dispatch_tag< OutputPort >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
Definition: DigitalOut.cpp:78
virtual DataStreamInstrumentData::UnitType GetValueUnit() const noexcept override final
Determines which unit corresponds to the values managed by this DataStreamInstrument instance....
Definition: DigitalOut.h:178
virtual DataStreamInstrumentData::ValueType GetHardwareMinValue() const noexcept override final
Indicates the minimal value the underlying hardware can generate. Also refer to GetUserMinValue().
Definition: DigitalOut.h:175
virtual NumericSampleStreamParamsExtension::ValueType GetNumericSampleStreamParams() const
Retrieves sample stream settings of the instrument's data stream from the instrument's or from the un...
Definition: DigitalOut.h:188
virtual void Set(DigitalOutData::SampleStreamType::SampleType Sample, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Writes one sample to the sample stream. CallbackFunc gets called after the task DataStreamInstrument:...
Definition: DigitalOut.cpp:40
constexpr static auto Category() noexcept
Every derived class has to redefine this function.
Definition: DigitalOut.h:157
virtual DataStreamInstrumentData::ValueType GetUserMinValue() const override
Indicates the minimal allowed value to generate as defined by the user/software. This value should be...
Definition: DigitalOut.h:179
virtual std::string GetName() const override
Returns the name of this Object type.
Definition: DigitalOut.h:167
DigitalOut(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs an instrument instance.
Definition: DigitalOut.h:162
virtual void ResetImpl(dispatch_tag< DigitalOut >)=0
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual std::string GetCategory() const override
Returns the category of this Object type.
Definition: DigitalOut.h:168
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
Definition: DigitalOut.h:227
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
Definition: DigitalOut.h:226
virtual DataStreamInstrumentData::ValueType GetUserMaxValue() const override
Indicates the maximal allowed value to generate as defined by the user/software. This value should be...
Definition: DigitalOut.h:180
virtual void SetSync(DigitalOutData::SampleStreamType::SampleType Sample) const
Synchronized version of Set(), which blocks until Sample has been written.
Definition: DigitalOut.cpp:51
virtual DataStreamInstrumentData::ValueType GetHardwareMaxValue() const noexcept override final
Indicates the maximal value the underlying hardware can generate. Also refer to GetUserMaxValue().
Definition: DigitalOut.h:176
virtual DataStreamInstrumentData::ValueType GetHardwareResolution() const noexcept override final
Indicates the value's resolution the underlying hardware can generate.
Definition: DigitalOut.h:177
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< uint8_t > DigitalSampleStream
Alias for a numeric sample stream of uint8_t (single byte) 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.