13 #include "../MetaInstruments/DataStreamInstrument.h"
17 #include "../include/NIDAQ/NIDAQmx.h"
28 const std::source_location Location = std::source_location::current()) noexcept
46 "Determines whether samples are written using a buffered transfer or a direct transfer to the device's onboard memory.", true,
DefaultUseOnlyOnBrdMem }
70 virtual const char*
GetParamClassTag() const noexcept
override {
return "NIDAQHardwareAdapterParams"; }
73 "If timing is configured for multiple channels (stream size > 1 sample), they have to be combined into a number of NI-DAQmx tasks limited by the amount of the respective device's clocks.",
74 true, ChannelModeType::TaskPerChannel };
80 "Trigger assigned to this channel to start sample generation/acquisition",
true, TriggerModeType::Disabled };
82 "Path of the trigger channel to be used for triggering (ignored if triggering is disabled)",
true,
"/Dev1/PFI0" };
118 bool IsCombined() const noexcept {
return ChannelMode == NIDAQHardwareAdapterParams::ChannelModeType::CombineChannels; }
165 constexpr
static auto Name() noexcept {
return "NI-DAQmx"; }
166 constexpr
static auto Category() noexcept {
return "I/O"; }
180 int32_t TerminalConfig = DAQmx_Val_RSE)
const;
197 using TasksMapType = std::unordered_map<ChannelHandleType, std::shared_ptr<NIDAQTask>>;
207 void CheckError(const int32_t Result, const std::source_location Location = std::source_location::current()) const;
208 void CheckReadError(
NIDAQTask* Task, const int32_t Result, const std::source_location Location = std::source_location::current()) const;
212 double Timeout,
double SamplingRate,
DynExpInstr::NumericSampleStreamParamsExtension::SamplingModeType SamplingMode) const;
Implementation of DynExp hardware adapter objects.
NIDAQException(std::string Description, const int ErrorCode, Util::ErrorType Type=Util::ErrorType::Error, const std::source_location Location=std::source_location::current()) noexcept
virtual ~NIDAQHardwareAdapterConfigurator()=default
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...
NIDAQHardwareAdapterConfigurator()=default
NIDAQHardwareAdapterParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
virtual void ConfigureParamsImpl(dispatch_tag< NIDAQHardwareAdapterParams >)
DynExpInstr::StreamSizeParamsExtension StreamSizeParams
DynExp::ParamsBase::Param< TriggerModeType > TriggerMode
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...
static Util::TextValueListType< ChannelModeType > ChannelModeTypeStrList()
DynExpInstr::NumericSampleStreamParamsExtension NumericSampleStreamParams
DynExp::ParamsBase::Param< ChannelModeType > ChannelMode
virtual ~NIDAQHardwareAdapterParams()=default
static Util::TextValueListType< TriggerModeType > TriggerModeTypeStrList()
void ConfigureParamsImpl(dispatch_tag< HardwareAdapterParamsBase >) override final
DynExp::ParamsBase::Param< ParamsConfigDialog::TextType > TriggerChannel
ChannelHandleType InitializeDigitalOutChannel(std::string_view ChannelName, NIDAQOutputPortParamsExtension::UseOnlyOnBrdMemType UseOnlyOnBrdMem, double Timeout=0) const
void EnsureReadyStateChild() override final
Ensures that this Object instance is ready by possibly starting its worker thread or by opening conne...
void StartTask(ChannelHandleType ChannelHandle) const
void StartTaskUnsafe(NIDAQTask *Task) const
bool DeregisterChannel(ChannelHandleType ChannelHandle) const
bool HasFinishedTask(ChannelHandleType ChannelHandle) const
void InitializeTaskTimingUnsafe(NIDAQTask *Task, double Timeout, double SamplingRate, DynExpInstr::NumericSampleStreamParamsExtension::SamplingModeType SamplingMode) const
int32_t WriteAnalogValues(ChannelHandleType ChannelHandle, const std::vector< NIDAQTask::AnalogValueType > &Values) const
ChannelHandleType InitializeAnalogInChannel(std::string_view ChannelName, double MinValue, double MaxValue, double Timeout=0, int32_t TerminalConfig=DAQmx_Val_RSE) const
bool TaskExistsUnsafe(ChannelHandleType ChannelHandle) const
void StopTaskUnsafe(NIDAQTask *Task) const
void CheckReadError(NIDAQTask *Task, const int32_t Result, const std::source_location Location=std::source_location::current()) const
virtual ~NIDAQHardwareAdapter()
std::unordered_map< ChannelHandleType, std::shared_ptr< NIDAQTask > > TasksMapType
constexpr static auto Category() noexcept
ChannelHandleType CreateTaskIfNotExistsUnsafe(std::string_view ChannelName, NIDAQTask::ChannelType Type) const
virtual std::string GetCategory() const override
Returns the category of this Object type.
void StopTask(ChannelHandleType ChannelHandle) const
bool IsConnectedChild() const noexcept override final
Determines the connection status of the hardware interface.
ChannelHandleType InsertTaskUnsafe(std::string_view ChannelName, std::shared_ptr< NIDAQTask > &&TaskHandle) const
ChannelHandleType InitializeAnalogOutChannel(std::string_view ChannelName, double MinValue, double MaxValue, NIDAQOutputPortParamsExtension::UseOnlyOnBrdMemType UseOnlyOnBrdMem, double Timeout=0) const
virtual void ResetImpl(dispatch_tag< NIDAQHardwareAdapter >)
NIDAQTask::ChannelHandleType ChannelHandleType
bool HasFinishedTaskUnsafe(NIDAQTask *Task) const
NIDAQTask * GetTaskUnsafe(ChannelHandleType ChannelHandle) const
NIDAQSyms::TaskHandle CreateTaskUnsafe() const
void RestartTaskUnsafe(NIDAQTask *Task) const
const NIDAQTask * GetTask(ChannelHandleType ChannelHandle) const
std::vector< NIDAQTask::DigitalValueType > ReadDigitalValues(ChannelHandleType ChannelHandle) const
constexpr static auto Name() noexcept
void InitializeTriggerUnsafe(NIDAQTask *Task, NIDAQHardwareAdapterParams::TriggerModeType TriggerMode, std::string_view TriggerChannelName) const
ChannelHandleType InitializeDigitalInChannel(std::string_view ChannelName, double Timeout=0) const
bool IsReadyChild() const override final
Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) a...
void RestartTask(ChannelHandleType ChannelHandle) const
virtual std::string GetName() const override
Returns the name of this Object type.
NIDAQHardwareAdapter(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
ChannelHandleType ChannelNameToChannelHandle(std::string_view ChannelName) const
void ResetImpl(dispatch_tag< HardwareAdapterBase >) override final
bool RemoveTaskUnsafe(ChannelHandleType ChannelHandle) const
int32_t WriteDigitalValues(ChannelHandleType ChannelHandle, const std::vector< NIDAQTask::DigitalValueType > &Values) const
std::vector< NIDAQTask::AnalogValueType > ReadAnalogValues(ChannelHandleType ChannelHandle) const
void CheckError(const int32_t Result, const std::source_location Location=std::source_location::current()) const
DynExp::ParamsBase::Param< UseOnlyOnBrdMemType > UseOnlyOnBrdMem
Write directly to device's onboard memory?
void DisableUserEditable()
static constexpr UseOnlyOnBrdMemType DefaultUseOnlyOnBrdMem
static Util::TextValueListType< UseOnlyOnBrdMemType > UseOnlyOnBrdMemTypeStrList()
NIDAQOutputPortParamsExtension(DynExp::ParamsBase &Owner)
bool IsCombined() const noexcept
std::vector< AnalogValueType > AnalogValues
auto GetSamplingMode() const noexcept
bool IsMultisample() const noexcept
NIDAQTask(ChannelType Type, NIDAQSyms::TaskHandle NITask, NIDAQHardwareAdapterParams::ChannelModeType ChannelMode=NIDAQHardwareAdapterParams::ChannelModeType::TaskPerChannel)
std::map< ChannelHandleType, uint32_t > ChannelIndexMap
auto GetSamplingRate() const noexcept
auto GetNumChannels() const noexcept
auto GetTimeout() const noexcept
const NIDAQHardwareAdapterParams::ChannelModeType ChannelMode
auto GetType() const noexcept
auto GetChannelIndex(ChannelHandleType ChannelHandle) const
auto GetNumSamples() const noexcept
auto GetSampleSizeInBytes() const noexcept
void AddChannel(ChannelHandleType ChannelHandle, uint64_t NumSamples)
const NIDAQSyms::TaskHandle NITask
std::vector< std::unique_ptr< CircularStream > > ReadStreamPerChannel
std::vector< DigitalValueType > DigitalValues
SamplingModeType SamplingMode
auto GetBufferSizeInSamples() const noexcept
Bundles parameters to describe a NumericSampleStream's sampling properties.
Bundles parameters to describe a data stream's stream size.
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Defines the base class for a hardware adapter object. Hardware adapters describe interfaces/connectio...
Configurator class for HardwareAdapterBase.
Parameter class for HardwareAdapterBase.
HardwareAdapterParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a HardwareAdapterBase instance.
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Refer to ParamsBase::dispatch_tag.
Abstract base class for object parameter classes. Each class derived from class Object must be accomp...
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
const DynExpCore & Core
Reference to DynExp's core.
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
DynExp exceptions are derived from this class. It contains basic information about the cause of the e...
Exception(std::string Description, const ErrorType Type=ErrorType::Error, const int ErrorCode=-1, const std::source_location Location=std::source_location::current()) noexcept
Constructs an exception. Constructor is noexcept, although std::runtime_error() might throw std::bad_...
const ErrorType Type
DynExp error type from Util::ErrorType
const int ErrorCode
DynExp error code from DynExpErrorCodes::DynExpErrorCodes
Circular stream buffer to be used with the standard library's stream classes. Reading from or writing...
DynExp's hardware namespace contains the implementation of DynExp hardware adapters which extend DynE...
TriggerModeType
Type to determine the trigger mode. Not a strongly-typed enum to allow using the enumeration in a Dyn...
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.
size_t ItemIDType
ID type of objects/items managed by DynExp.
ErrorType
DynExp's error types
std::vector< std::pair< TextType, ValueType > > TextValueListType
Type of a list containing key-value pairs where key is a text of type Util::TextType.
Accumulates include statements to provide a precompiled header.
CircularStream(size_t BufferSize)