DynExp
Highly flexible laboratory automation for dynamically changing experiments.
NIDAQAnalogOut.cpp
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
3 #include "stdafx.h"
4 #include "NIDAQAnalogOut.h"
5 
6 namespace DynExpInstr
7 {
9  {
10  auto InstrParams = DynExp::dynamic_Params_cast<NIDAQAnalogOut>(Instance.ParamsGetter());
11  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(Instance.InstrumentDataGetter());
12 
13  Instance.LockObject(InstrParams->HardwareAdapter, InstrData->HardwareAdapter);
14  InstrData->ChannelHandle = InstrData->HardwareAdapter->InitializeAnalogOutChannel(InstrParams->ChannelName.Get(),
15  NIDAQAnalogOut::HardwareMinValue(), NIDAQAnalogOut::HardwareMaxValue(), InstrParams->NIDAQOutputPortParams.UseOnlyOnBrdMem);
16 
18  }
19 
21  {
22  ExitFuncImpl(dispatch_tag<ExitTask>(), Instance);
23 
24  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(Instance.InstrumentDataGetter());
25 
26  InstrData->HardwareAdapter->DeregisterChannel(InstrData->ChannelHandle);
27  Instance.UnlockObject(InstrData->HardwareAdapter);
28  }
29 
31  {
32  UpdateFuncImpl(dispatch_tag<UpdateTask>(), Instance);
33  }
34 
36  {
37  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(Instance.InstrumentDataGetter());
38 
39  auto SampleStream = InstrData->GetCastSampleStream<NIDAQAnalogOutData::SampleStreamType>();
40  InstrData->HardwareAdapter->WriteAnalogValues(InstrData->ChannelHandle, SampleStream->ReadSamples(SampleStream->GetStreamSizeRead()));
41 
42  return {};
43  }
44 
46  {
47  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(Instance.InstrumentDataGetter());
48  InstrData->HardwareAdapter->StopTask(InstrData->ChannelHandle);
49 
50  return {};
51  }
52 
54  {
55  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(Instance.InstrumentDataGetter());
56 
57  InstrData->HardwareAdapter->StartTask(InstrData->ChannelHandle);
58 
59  return {};
60  }
61 
63  {
64  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(Instance.InstrumentDataGetter());
65 
66  InstrData->HardwareAdapter->StopTask(InstrData->ChannelHandle);
67 
68  return {};
69  }
70 
72  {
73  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(Instance.InstrumentDataGetter());
74 
75  InstrData->HardwareAdapter->RestartTask(InstrData->ChannelHandle);
76 
77  return {};
78  }
79 
81  {
83  }
84 
86  {
87  ConfigureParamsImpl(dispatch_tag<NIDAQAnalogOutParams>());
88  }
89 
90  NIDAQAnalogOut::NIDAQAnalogOut(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params)
91  : AnalogOut(OwnerThreadID, std::move(Params))
92  {
93  }
94 
96  {
97  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(GetInstrumentData());
98  auto HardwareParams = dynamic_Params_cast<DynExpHardware::NIDAQHardwareAdapter>(InstrData->HardwareAdapter->GetParams());
99 
100  return HardwareParams->StreamSizeParams.Values();
101  }
102 
104  {
105  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(GetInstrumentData());
106  auto HardwareParams = dynamic_Params_cast<DynExpHardware::NIDAQHardwareAdapter>(InstrData->HardwareAdapter->GetParams());
107 
108  return HardwareParams->NumericSampleStreamParams.Values();
109  }
110 
112  {
113  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(GetInstrumentData());
114 
115  return InstrData->HardwareAdapter->HasFinishedTask(InstrData->ChannelHandle);
116  }
117 
119  {
120  bool IsMultisample{};
121 
122  {
123  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(GetInstrumentData());
124  IsMultisample = InstrData->HardwareAdapter->GetTask(InstrData->ChannelHandle)->IsMultisample();
125  } // InstrData unlocked here.
126 
127  if (IsMultisample)
128  {
129  Stop();
130  AnalogOut::SetDefault(CallbackFunc);
131  Start();
132  }
133  else
134  AnalogOut::SetDefault(CallbackFunc);
135  }
136 
138  {
139  auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogOut>(GetInstrumentData());
140 
141  InstrData->HardwareAdapter->DeregisterChannel(InstrData->ChannelHandle);
142  }
143 
145  {
147  }
148 }
Implementation of an instrument to control a single analog output of the National Instruments NIDAQmx...
Meta instrument for a single analog output port based on the data stream, function generator,...
Definition: AnalogOut.h:176
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
void ResetImpl(dispatch_tag< AnalogOutData >) override final
void ConfigureParamsImpl(dispatch_tag< AnalogOutParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
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...
void ExitFuncImpl(dispatch_tag< AnalogOutTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
void InitFuncImpl(dispatch_tag< AnalogOutTasks::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...
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 DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
void UpdateFuncImpl(dispatch_tag< AnalogOutTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
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...
constexpr static DataStreamInstrumentData::ValueType HardwareMinValue() noexcept
void ResetImpl(dispatch_tag< AnalogOut >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
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 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 void SetDefault(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Writes AnalogOutParams::DefaultValue to the sample stream. CallbackFunc gets called after the task Da...
virtual void OnErrorChild() const override
Derived classes can perform critical shutdown actions after an error has occurred....
virtual Util::OptionalBool HasFinished() const override
Determines whether the underlying hardware adapter finished data acquisition or writing data.
constexpr static DataStreamInstrumentData::ValueType HardwareMaxValue() noexcept
NIDAQAnalogOut(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
virtual StreamSizeParamsExtension::ValueType GetStreamSizeParams() const override
Retrieves the size of the instrument's data stream from the instrument parameters....
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.
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...
Type containing the values of all the parameters belonging to StreamSizeParamsExtension.
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1151
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1120
InstrumentDataTypeSyncPtrType GetInstrumentData(const std::chrono::milliseconds Timeout=GetInstrumentDataTimeoutDefault)
Locks the mutex of the instrument data class instance InstrumentData assigned to this InstrumentBase ...
Definition: Instrument.cpp:222
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
const InstrumentBase::InstrumentDataGetterType InstrumentDataGetter
Getter for instrument's data. Refer to InstrumentBase::InstrumentDataGetterType.
Definition: Instrument.h:791
Refer to ParamsBase::dispatch_tag.
Definition: Object.h:2018
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Definition: Object.h:349
const Object::ParamsGetterType ParamsGetter
Invoke to obtain the parameters (derived from ParamsBase) of Owner.
Definition: Object.h:3671
void UnlockObject(LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer)
Unlocks an Object instance stored in the LinkedObjectWrapperContainer ObjectWrapperContainer....
Definition: Object.h:3570
void LockObject(const ParamsBase::Param< ObjectLink< ObjectT >> &LinkParam, LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer, std::chrono::milliseconds Timeout=ObjectLinkBase::LockObjectTimeoutDefault)
Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< O...
Definition: Object.h:3554
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 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
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition: Object.h:1807
Accumulates include statements to provide a precompiled header.