DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
NIDAQAnalogIn.cpp
Go to the documentation of this file.
1// This file is part of DynExp.
2
3#include "stdafx.h"
4#include "NIDAQAnalogIn.h"
5
6namespace DynExpInstr
7{
9 {
10 auto InstrParams = DynExp::dynamic_Params_cast<NIDAQAnalogIn>(Instance.ParamsGetter());
11 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(Instance.InstrumentDataGetter());
12
13 Instance.LockObject(InstrParams->HardwareAdapter, InstrData->HardwareAdapter);
14 InstrData->ChannelHandle = InstrData->HardwareAdapter->InitializeAnalogInChannel(InstrParams->ChannelName.Get(),
15 NIDAQAnalogIn::HardwareMinValue(), NIDAQAnalogIn::HardwareMaxValue(), 0, InstrParams->TerminalConfig);
16
18 }
19
21 {
22 ExitFuncImpl(dispatch_tag<ExitTask>(), Instance);
23
24 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(Instance.InstrumentDataGetter());
25
26 InstrData->HardwareAdapter->DeregisterChannel(InstrData->ChannelHandle);
27 Instance.UnlockObject(InstrData->HardwareAdapter);
28 }
29
34
36 {
37 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(Instance.InstrumentDataGetter());
38
39 auto SampleStream = InstrData->GetCastSampleStream<NIDAQAnalogInData::SampleStreamType>();
40 SampleStream->WriteSamples(InstrData->HardwareAdapter->ReadAnalogValues(InstrData->ChannelHandle));
41
42 return {};
43 }
44
46 {
47 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(Instance.InstrumentDataGetter());
48
49 InstrData->HardwareAdapter->StartTask(InstrData->ChannelHandle);
50
51 return {};
52 }
53
55 {
56 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(Instance.InstrumentDataGetter());
57
58 InstrData->HardwareAdapter->StopTask(InstrData->ChannelHandle);
59
60 return {};
61 }
62
64 {
65 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(Instance.InstrumentDataGetter());
66
67 InstrData->HardwareAdapter->RestartTask(InstrData->ChannelHandle);
68
69 return {};
70 }
71
76
78 {
80 { "Default terminal configuration chosen by NI DAQ at run time", TerminalConfigType::Default },
81 { "Referenced single-ended terminal configuration", TerminalConfigType::RSE },
82 { "Non-referenced single-ended terminal configuration", TerminalConfigType::NRSE },
83 { "Differential terminal configuration", TerminalConfigType::Diff },
84 { "Pseudodifferential terminal configuration", TerminalConfigType::PseudoDiff }
85 };
86
87 return List;
88 }
89
94
95 NIDAQAnalogIn::NIDAQAnalogIn(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params)
96 : AnalogIn(OwnerThreadID, std::move(Params))
97 {
98 }
99
101 {
102 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(GetInstrumentData());
103 auto HardwareParams = dynamic_Params_cast<DynExpHardware::NIDAQHardwareAdapter>(InstrData->HardwareAdapter->GetParams());
104
105 return HardwareParams->StreamSizeParams.Values();
106 }
107
109 {
110 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(GetInstrumentData());
111 auto HardwareParams = dynamic_Params_cast<DynExpHardware::NIDAQHardwareAdapter>(InstrData->HardwareAdapter->GetParams());
112
113 return HardwareParams->NumericSampleStreamParams.Values();
114 }
115
117 {
118 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(GetInstrumentData());
119
120 return InstrData->HardwareAdapter->HasFinishedTask(InstrData->ChannelHandle);
121 }
122
124 {
125 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQAnalogIn>(GetInstrumentData());
126
127 InstrData->HardwareAdapter->DeregisterChannel(InstrData->ChannelHandle);
128 }
129
134}
Implementation of an instrument to control a single analog input of the National Instruments NIDAQmx ...
Meta instrument for a single analog input port based on the data stream and generic input port meta i...
Definition AnalogIn.h:136
void WriteSamples(const std::vector< T > &Samples)
Writes multiple samples to the stream's buffer StreamBuffer.
void ResetImpl(dispatch_tag< AnalogInData >) override final
static Util::TextValueListType< TerminalConfigType > TerminalConfigTypeStrList()
void ConfigureParamsImpl(dispatch_tag< AnalogInParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
void ExitFuncImpl(dispatch_tag< AnalogInTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
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...
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< AnalogInTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
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....
static constexpr DataStreamInstrumentData::ValueType HardwareMinValue() noexcept
virtual NumericSampleStreamParamsExtension::ValueType GetNumericSampleStreamParams() const override
Retrieves sample stream settings of the instrument's data stream from the instrument's or from the un...
NIDAQAnalogIn(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
void ResetImpl(dispatch_tag< AnalogIn >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
static constexpr DataStreamInstrumentData::ValueType HardwareMaxValue() noexcept
virtual Util::OptionalBool HasFinished() const override
Determines whether the underlying hardware adapter finished 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.
Refer to DynExp::ParamsBase::dispatch_tag.
InstrumentDataTypeSyncPtrType GetInstrumentData(const std::chrono::milliseconds Timeout=GetInstrumentDataTimeoutDefault)
Locks the mutex of the instrument data class instance InstrumentData assigned to this InstrumentBase ...
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
Defines the return type of task functions.
Definition Instrument.h:824
Refer to DynExp::ParamsBase::dispatch_tag.
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...
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition Object.h:1807
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.