Scope
GaterDAQmx.cpp
1 #include "stdafx.h"
2 #include "GaterDAQmx.h"
3 #include "helpers/helpers.h"
4 #include "daqmx/DAQmxTask.h"
5 
6 namespace scope {
7 
8 GaterDAQmx::GaterDAQmx(const std::wstring& _gateline, const StopCondition* const _sc)
9  : gateline(_gateline)
10  , sc(_sc) {
11 }
12 
13 bool GaterDAQmx::WaitFor(const bool& _waitforhigh) {
14  if ( sc->IsSet() )
15  return false;
16 
18  task.CreateTask();
19  task.CreateAIVoltageChannel(L"PXI-6229_0/ai0", L"Gater");
20  //task.ConfigureDigStartTrigger(gateline, _waitforhigh?DAQmx_Val_Rising:DAQmx_Val_Falling);
21  task.ConfigureDigStartTrigger(L"PFI0", _waitforhigh?DAQmx_Val_Rising:DAQmx_Val_Falling);
22  task.ConfigureSampleTiming(L"OnboardClock", 10000, 500, DAQmx_Val_ContSamps);
23 
24  bool timeout = true;
25  std::vector<uint16_t> readvec(1,0);
26 
27  // Try repeatedly to read for 200ms, as long as the read from the task times out or until the Stop condition is set
28  while ( timeout ) {
29  task.ReadU16(readvec, 1, 1, timeout, 120);
30  if ( sc->IsSet() ) {
31  DBOUT(L"GaterDAQmx::WaitFor StopCondition set");
32  return false;
33  }
34  }
35  DBOUT(L"GaterDAQmx::WaitFor waiting succeeded");
36  return true;
37 }
38 
39 
40 }
Thread-safe lock-free bool to signal a requested stop to the worker function currently executed in th...
Definition: helpers.h:87
const StopCondition *const sc
The StopCondition to check if set for aborting the WaitFor.
Definition: GaterDAQmx.h:16
GaterDAQmx(const std::wstring &_gateline, const StopCondition *const _sc)
Initialize waiting task.
Definition: GaterDAQmx.cpp:8
bool WaitFor(const bool &_waitforhigh)
Starts a DAQmx task that waits until the digital line is either high or low (depending on _waitforhig...
Definition: GaterDAQmx.cpp:13
This is the include file for standard system include files, or project specific include files that ar...
#define DBOUT(s)
A debug output to the debug console.
Definition: helpers.h:153
void CreateTask(const std::wstring &_name=L"")
Definition: DAQmxTask.cpp:91
void ConfigureSampleTiming(const std::wstring &_src, const float64 &_rate, const int32 &_samplesperchan, const int32 &_samplingtype=DAQmx_Val_ContSamps, const int32 &_actedge=DAQmx_Val_Rising)
Configures a sample timing for the task.
Definition: DAQmxTask.cpp:109
Various helper functions and classes for Scope.
void CreateAIVoltageChannel(const std::wstring &_devicechannel, const std::wstring &_name=L"", int32 _terminalconfig=DAQmx_Val_Cfg_Default, float64 _minval=-10.0, float64 _maxval=10.0, int32 _units=DAQmx_Val_Volts, const std::wstring &_customscalename=L"")
Definition: DAQmxTask.cpp:312
void ConfigureDigStartTrigger(const std::wstring &_src, const int32 &_trigedge=DAQmx_Val_Rising)
Configures the start trigger.
Definition: DAQmxTask.cpp:134
Wraps a DAQmx Analog Input Task.
Definition: DAQmxTask.h:258
int32 ReadU16(std::vector< uint16_t > &_data, const int32 &_sampsperchan, const uint32_t &_channels, bool &_timedout, const float64 &_timeout=2)
Definition: DAQmxTask.cpp:340
bool IsSet() const
Definition: helpers.h:105