DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
NIDAQDigitalIn.cpp
Go to the documentation of this file.
1// This file is part of DynExp.
2
3#include "stdafx.h"
4#include "NIDAQDigitalIn.h"
5
6namespace DynExpInstr
7{
9 {
10 auto InstrParams = DynExp::dynamic_Params_cast<NIDAQDigitalIn>(Instance.ParamsGetter());
11 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(Instance.InstrumentDataGetter());
12
13 Instance.LockObject(InstrParams->HardwareAdapter, InstrData->HardwareAdapter);
14 InstrData->ChannelHandle = InstrData->HardwareAdapter->InitializeDigitalInChannel(InstrParams->ChannelName.Get(), 0);
15
17 }
18
20 {
21 ExitFuncImpl(dispatch_tag<ExitTask>(), Instance);
22
23 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(Instance.InstrumentDataGetter());
24
25 InstrData->HardwareAdapter->DeregisterChannel(InstrData->ChannelHandle);
26 Instance.UnlockObject(InstrData->HardwareAdapter);
27 }
28
33
35 {
36 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(Instance.InstrumentDataGetter());
37
38 auto SampleStream = InstrData->GetCastSampleStream<NIDAQDigitalInData::SampleStreamType>();
39 SampleStream->WriteSamples(InstrData->HardwareAdapter->ReadDigitalValues(InstrData->ChannelHandle));
40
41 return {};
42 }
43
45 {
46 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(Instance.InstrumentDataGetter());
47
48 InstrData->HardwareAdapter->StartTask(InstrData->ChannelHandle);
49
50 return {};
51 }
52
54 {
55 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(Instance.InstrumentDataGetter());
56
57 InstrData->HardwareAdapter->StopTask(InstrData->ChannelHandle);
58
59 return {};
60 }
61
63 {
64 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(Instance.InstrumentDataGetter());
65
66 InstrData->HardwareAdapter->RestartTask(InstrData->ChannelHandle);
67
68 return {};
69 }
70
75
80
81 NIDAQDigitalIn::NIDAQDigitalIn(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params)
82 : DigitalIn(OwnerThreadID, std::move(Params))
83 {
84 }
85
87 {
88 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(GetInstrumentData());
89 auto HardwareParams = dynamic_Params_cast<DynExpHardware::NIDAQHardwareAdapter>(InstrData->HardwareAdapter->GetParams());
90
91 return HardwareParams->StreamSizeParams.Values();
92 }
93
95 {
96 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(GetInstrumentData());
97 auto HardwareParams = dynamic_Params_cast<DynExpHardware::NIDAQHardwareAdapter>(InstrData->HardwareAdapter->GetParams());
98
99 return HardwareParams->NumericSampleStreamParams.Values();
100 }
101
103 {
104 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(GetInstrumentData());
105
106 return InstrData->HardwareAdapter->HasFinishedTask(InstrData->ChannelHandle);
107 }
108
110 {
111 auto InstrData = DynExp::dynamic_InstrumentData_cast<NIDAQDigitalIn>(GetInstrumentData());
112
113 InstrData->HardwareAdapter->DeregisterChannel(InstrData->ChannelHandle);
114 }
115
120}
Implementation of an instrument to control a single digital input of the National Instruments NIDAQmx...
void WriteSamples(const std::vector< T > &Samples)
Writes multiple samples to the stream's buffer StreamBuffer.
Meta instrument for a single digital input port based on the data stream and generic input port meta ...
Definition DigitalIn.h:136
void ResetImpl(dispatch_tag< DigitalInData >) override final
void ConfigureParamsImpl(dispatch_tag< DigitalInParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
void ExitFuncImpl(dispatch_tag< DigitalInTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
void InitFuncImpl(dispatch_tag< DigitalInTasks::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< DigitalInTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
virtual StreamSizeParamsExtension::ValueType GetStreamSizeParams() const override
Retrieves the size of the instrument's data stream from the instrument parameters....
virtual Util::OptionalBool HasFinished() const override
Determines whether the underlying hardware adapter finished 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...
NIDAQDigitalIn(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
void ResetImpl(dispatch_tag< DigitalIn >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual void OnErrorChild() const override
Derived classes can perform critical shutdown actions after an error has occurred....
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
Accumulates include statements to provide a precompiled header.