DynExp
Highly flexible laboratory automation for dynamically changing experiments.
AnalogOut.cpp
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
3 #include "stdafx.h"
4 #include "AnalogOut.h"
5 
6 namespace DynExpInstr
7 {
9  {
10  if (ApplyLimits())
11  {
12  auto InstrParams = DynExp::dynamic_Params_cast<AnalogOut>(Instance.ParamsGetter());
13  auto InstrData = DynExp::dynamic_InstrumentData_cast<AnalogOut>(Instance.InstrumentDataGetter());
14 
15  InstrData->GetCastSampleStream<AnalogOutData::SampleStreamType>()->SetLimits(InstrParams->MinValue, InstrParams->MaxValue);
16  } // InstrParams and InstrData unlocked here.
17 
19  }
20 
22  {
23  ExitFuncImpl(dispatch_tag<ExitTask>(), Instance);
24  }
25 
27  {
28  ResetImpl(dispatch_tag<AnalogOutData>());
29  }
30 
32  {
33  }
34 
36  {
40  }
41 
43  {
44  }
45 
47  {
48  }
49 
51  {
52  auto DerivedParams = dynamic_Params_cast<AnalogOut>(GetParams());
53  return DerivedParams->MinValue;
54  }
55 
57  {
58  auto DerivedParams = dynamic_Params_cast<AnalogOut>(GetParams());
59  return DerivedParams->MaxValue;
60  }
61 
63  {
64  {
65  auto InstrData = dynamic_InstrumentData_cast<AnalogOut>(GetInstrumentData());
66 
67  InstrData->GetSampleStream()->WriteBasicSample({ static_cast<BasicSample::DataType>(Sample), 0 });
68  } // InstrData unlocked here.
69 
70  WriteData(CallbackFunc);
71  }
72 
74  {
75  AsSyncTask(&AnalogOut::Set, Sample);
76  }
77 
79  {
80  {
81  auto InstrParams = DynExp::dynamic_Params_cast<AnalogOut>(GetParams());
82  auto InstrData = dynamic_InstrumentData_cast<AnalogOut>(GetInstrumentData());
83 
84  AnalogOutData::SampleStreamType::SampleType DefaultValue = InstrParams->DefaultValue;
85  auto SampleStream = InstrData->GetSampleStream();
86 
87  SampleStream->Clear();
88  for (auto i = SampleStream->GetStreamSizeWrite(); i > 0; --i)
89  SampleStream->WriteBasicSample({ static_cast<BasicSample::DataType>(DefaultValue), 0 });
90  } // InstrParams and InstrData unlocked here.
91 
92  WriteData();
93  }
94 
96  {
97  SetDefault();
98  }
99 
101  {
102  ResetImpl(dispatch_tag<AnalogOut>());
103  }
104 }
Defines a meta instrument for a single analog output port to write a data stream consisting of analog...
void ResetImpl(dispatch_tag< OutputPortData >) override final
Definition: AnalogOut.cpp:26
void DisableUserEditable()
Calls DynExp::ParamsBase::DisableUserEditable() on all bundled parameters.
Definition: AnalogOut.cpp:35
void ExitFuncImpl(dispatch_tag< OutputPortTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition: AnalogOut.cpp:21
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
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
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
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
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 ~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
SampleT SampleType
Alias for SampleT.
double ValueType
Data type to represent hardware limits on the sample values to write to the hardware adapter assigned...
Implements a circular data stream based on Util::circularbuf using samples of an arithmetic type Samp...
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1151
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1120
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
static void DisableUserEditable(ParamBase &Param) noexcept
Sets the UserEditable property of the parameter Param to false. Refer to ParamBase::UserEditable.
Definition: Object.cpp:292
const Object::ParamsGetterType ParamsGetter
Invoke to obtain the parameters (derived from ParamsBase) of Owner.
Definition: Object.h:3671
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
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
Definition: Instrument.h:1254
Accumulates include statements to provide a precompiled header.
double DataType
Data type of time and value.