DynExp
Highly flexible laboratory automation for dynamically changing experiments.
NIDAQAnalogIn.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 "DynExpCore.h"
15 
16 namespace DynExpInstr
17 {
18  class NIDAQAnalogIn;
19 
20  namespace NIDAQAnalogInTasks
21  {
23  {
26  };
27 
29  {
32  };
33 
35  {
38  };
39 
40  class ReadTask : public DynExp::TaskBase
41  {
42  public:
44 
45  private:
47  };
48 
49  class StartTask : public DynExp::TaskBase
50  {
51  public:
53 
54  private:
56  };
57 
58  class StopTask : public DynExp::TaskBase
59  {
60  public:
62 
63  private:
65  };
66 
68  {
69  public:
71 
72  private:
74  };
75  }
76 
78  {
79  public:
80  NIDAQAnalogInData() = default;
81  virtual ~NIDAQAnalogInData() = default;
82 
85 
86  private:
87  void ResetImpl(dispatch_tag<AnalogInData>) override final;
89  };
90 
92  {
93  public:
94  enum TerminalConfigType : int32_t { Default = DAQmx_Val_Cfg_Default, RSE = DAQmx_Val_RSE, NRSE = DAQmx_Val_NRSE, Diff = DAQmx_Val_Diff, PseudoDiff = DAQmx_Val_PseudoDiff };
95 
97 
99  : AnalogInParams(ID, Core) {}
100  virtual ~NIDAQAnalogInParams() = default;
101 
102  virtual const char* GetParamClassTag() const noexcept override { return "NIDAQAnalogInParams"; }
103 
105  "HardwareAdapter", "NIDAQmx controller", "Underlying hardware adapter of this instrument", DynExpUI::Icons::HardwareAdapter };
106  Param<ParamsConfigDialog::TextType> ChannelName = { *this, "ChannelName", "Channel name",
107  "Path of the analog in channel to be used", true, "Dev1/ai0" };
108  Param<TerminalConfigType> TerminalConfig = { *this, TerminalConfigTypeStrList(), "TerminalConfig", "Terminal config",
109  "Determines the input terminal configuration of the channel.", true, TerminalConfigType::RSE };
110 
111  private:
112  void ConfigureParamsImpl(dispatch_tag<AnalogInParams>) override final;
114  };
115 
117  {
118  public:
121 
123  virtual ~NIDAQAnalogInConfigurator() = default;
124 
125  private:
126  virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override { return DynExp::MakeParams<NIDAQAnalogInConfigurator>(ID, Core); }
127  };
128 
129  class NIDAQAnalogIn : public AnalogIn
130  {
131  public:
135 
136  constexpr static auto Name() noexcept { return "NIDAQ Analog In"; }
137 
139  virtual ~NIDAQAnalogIn() {}
140 
141  virtual std::string GetName() const override { return Name(); }
142 
143  constexpr static DataStreamInstrumentData::ValueType HardwareMinValue() noexcept { return -10; }
144  constexpr static DataStreamInstrumentData::ValueType HardwareMaxValue() noexcept { return 10; }
145  constexpr static DataStreamInstrumentData::ValueType HardwareResolution() noexcept { return 1e-3; }
146 
147  virtual DataStreamInstrumentData::ValueType GetHardwareMinValue() const noexcept override { return HardwareMinValue(); }
148  virtual DataStreamInstrumentData::ValueType GetHardwareMaxValue() const noexcept override { return HardwareMaxValue(); }
149  virtual DataStreamInstrumentData::ValueType GetHardwareResolution() const noexcept override final { return HardwareResolution(); }
153 
154  virtual void ReadData(DynExp::TaskBase::CallbackType CallbackFunc) const override { MakeAndEnqueueTask<NIDAQAnalogInTasks::ReadTask>(CallbackFunc); }
155  virtual void Start(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NIDAQAnalogInTasks::StartTask>(CallbackFunc); }
156  virtual void Stop(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NIDAQAnalogInTasks::StopTask>(CallbackFunc); }
157  virtual void Restart(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NIDAQAnalogInTasks::RestartTask>(CallbackFunc); }
158  virtual Util::OptionalBool HasFinished() const override;
159 
160  private:
161  virtual void OnErrorChild() const override;
162 
163  void ResetImpl(dispatch_tag<AnalogIn>) override final;
165 
166  virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<NIDAQAnalogInTasks::InitTask>(); }
167  virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<NIDAQAnalogInTasks::ExitTask>(); }
168  virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<NIDAQAnalogInTasks::UpdateTask>(); }
169  };
170 }
Defines a meta instrument for a single analog input port to read a data stream consisting of analog v...
Defines DynExp's core module as an interface between the UI and DynExp objects.
Implementation of a hardware adapter to control National Instruments NIDAQmx hardware.
NIDAQTask::ChannelHandleType ChannelHandleType
Configurator class for AnalogIn.
Definition: AnalogIn.h:122
Data class for AnalogIn.
Definition: AnalogIn.h:67
Parameter class for AnalogIn.
Definition: AnalogIn.h:95
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition: AnalogIn.h:40
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: AnalogIn.h:27
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition: AnalogIn.h:53
Meta instrument for a single analog input port based on the data stream and generic input port meta i...
Definition: AnalogIn.h:136
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...
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
virtual ~NIDAQAnalogInConfigurator()=default
virtual void ResetImpl(dispatch_tag< NIDAQAnalogInData >)
Definition: NIDAQAnalogIn.h:88
DynExp::LinkedObjectWrapperContainer< DynExpHardware::NIDAQHardwareAdapter > HardwareAdapter
Definition: NIDAQAnalogIn.h:83
virtual ~NIDAQAnalogInData()=default
void ResetImpl(dispatch_tag< AnalogInData >) override final
DynExpHardware::NIDAQHardwareAdapter::ChannelHandleType ChannelHandle
Definition: NIDAQAnalogIn.h:84
Param< TerminalConfigType > TerminalConfig
virtual void ConfigureParamsImpl(dispatch_tag< NIDAQAnalogInParams >)
NIDAQAnalogInParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Definition: NIDAQAnalogIn.h:98
static Util::TextValueListType< TerminalConfigType > TerminalConfigTypeStrList()
Param< DynExp::ObjectLink< DynExpHardware::NIDAQHardwareAdapter > > HardwareAdapter
void ConfigureParamsImpl(dispatch_tag< AnalogInParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
virtual ~NIDAQAnalogInParams()=default
Param< ParamsConfigDialog::TextType > ChannelName
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...
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Definition: NIDAQAnalogIn.h:31
void ExitFuncImpl(dispatch_tag< AnalogInTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Definition: NIDAQAnalogIn.h:25
void InitFuncImpl(dispatch_tag< AnalogInTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
ReadTask(CallbackType CallbackFunc) noexcept
Definition: NIDAQAnalogIn.h:43
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
RestartTask(CallbackType CallbackFunc) noexcept
Definition: NIDAQAnalogIn.h:70
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
StartTask(CallbackType CallbackFunc) noexcept
Definition: NIDAQAnalogIn.h:52
StopTask(CallbackType CallbackFunc) noexcept
Definition: NIDAQAnalogIn.h:61
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Definition: NIDAQAnalogIn.h:37
void UpdateFuncImpl(dispatch_tag< AnalogInTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
virtual DataStreamInstrumentData::ValueType GetHardwareMaxValue() const noexcept override
Indicates the maximal value the underlying hardware can record.
virtual DataStreamInstrumentData::ValueType GetHardwareMinValue() const noexcept override
Indicates the minimal value the underlying hardware can record.
virtual void OnErrorChild() const override
Derived classes can perform critical shutdown actions after an error has occurred....
virtual StreamSizeParamsExtension::ValueType GetStreamSizeParams() const override
Retrieves the size of the instrument's data stream from the instrument parameters....
virtual void ResetImpl(dispatch_tag< NIDAQAnalogIn >)
constexpr static DataStreamInstrumentData::ValueType HardwareMinValue() noexcept
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
virtual void Restart(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Enqueues a task to make the underlying hardware adapter restart data acquisition or writing data....
virtual void Start(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Enqueues a task to make the underlying hardware adapter start data acquisition or writing data.
virtual NumericSampleStreamParamsExtension::ValueType GetNumericSampleStreamParams() const override
Retrieves sample stream settings of the instrument's data stream from the instrument's or from the un...
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...
NIDAQAnalogIn(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
constexpr static auto Name() noexcept
void ResetImpl(dispatch_tag< AnalogIn >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
constexpr static DataStreamInstrumentData::ValueType HardwareMaxValue() noexcept
virtual Util::OptionalBool HasFinished() const override
Determines whether the underlying hardware adapter finished data acquisition or writing data.
virtual void Stop(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Enqueues a task to make the underlying hardware adapter stop data acquisition or writing data.
virtual DataStreamInstrumentData::ValueType GetHardwareResolution() const noexcept override final
Indicates the value's resolution the underlying hardware can record.
virtual DataStreamInstrumentData::UnitType GetValueUnit() const noexcept override
Determines which unit corresponds to the values managed by this DataStreamInstrument instance....
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
virtual void ReadData(DynExp::TaskBase::CallbackType CallbackFunc) const override
Enqueues a task to read data from the hardware to the data stream. The default implementation does no...
constexpr static DataStreamInstrumentData::ValueType HardwareResolution() noexcept
virtual std::string GetName() const override
Returns the name of this Object type.
Type containing the values of all the parameters belonging to NumericSampleStreamParamsExtension.
Type containing the values of all the parameters belonging to StreamSizeParamsExtension.
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition: DynExpCore.h:127
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1151
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 auto & GetCore() const noexcept
Returns a reference to DynExp's core.
Definition: Object.h:1677
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
Base class for all tasks being processed by instruments. The class must not contain public virtual fu...
Definition: Instrument.h:892
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
TaskBase(CallbackType CallbackFunc=nullptr) noexcept
Constructs an instrument task.
Definition: Instrument.h:979
const CallbackType CallbackFunc
This callback function is called after the task has finished (either successfully or not) with a refe...
Definition: Instrument.h:1072
Defines the return type of task functions.
Definition: Instrument.h:824
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1182
Data type which stores an optional bool value (unknown, false, true). The type evaluates to bool whil...
Definition: Util.h:549
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
Definition: Instrument.h:1254
constexpr auto HardwareAdapter
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.
std::vector< std::pair< TextType, ValueType > > TextValueListType
Type of a list containing key-value pairs where key is a text of type Util::TextType.
Definition: QtUtil.h:37
Accumulates include statements to provide a precompiled header.