Scope
InputsDAQmx.cpp
1 #include "stdafx.h"
2 #include "InputsDAQmx.h"
3 #include "parameters/IO.h"
4 #include "parameters/Scope.h"
5 #include "ScopeDatatypes.h"
6 #include "helpers/DaqChunk.h"
7 #include "helpers/ScopeException.h"
8 
9 namespace scope {
10 
11 InputsDAQmx::InputsDAQmx(const uint32_t& _area, const parameters::InputsDAQmx* const _inputparams, const parameters::Scope& _params)
12  : Inputs(_area) {
13  int32_t samplingtype = (_params.requested_mode() == DaqModeHelper::continuous)?DAQmx_Val_ContSamps:DAQmx_Val_FiniteSamps;
14 
15  std::wstring commontrig = _params.commontrigger();
16 
17  task.CreateTask();
19  , L"Acquisition"
20  , DAQmx_Val_Cfg_Default
21  , -(_inputparams->range())
22  , (_inputparams->range()));
23 
24  // Calculate pixelrate/samplerate if oversampling and number of pixels/samples to acquire
25  // Note: Coercion to pixelrates supported by the device is already done in parameters::InputsDAQmx
26  double pixelrate = 1/(_params.areas[area]->daq.pixeltime()*1E-6);
27  double inputrate = pixelrate;
28  if ( _inputparams->oversampling() )
29  inputrate = 1/(_inputparams->MinimumPixeltime()*1E-6);
30 
31  uint32_t oversampling = round2ui32(inputrate/pixelrate);
32 
33  uint32_t pixelsperchan = _params.areas[area]->Currentframe().TotalPixels();
34 
35  if ( _params.requested_mode() == DaqModeHelper::nframes)
36  pixelsperchan *= _params.areas[area]->daq.requested_frames() * _params.areas[ThisAreaOrMasterArea(area)]->daq.averages();
37 
38  requested_samples = oversampling * pixelsperchan;
39 
40  // Configure timing
42  , inputrate
43  , static_cast<int32_t>(requested_samples)
44  , samplingtype);
45  if ( DaqTimingHelper::Mode::ReferenceClock == _inputparams->daq_timing() )
47 
48  task.ConfigureDigStartTrigger(commontrig, DAQmx_Val_Rising);
49 
50  // Size of data chunks to readm should be between 64^2 and 128^2
51  standardchunksize = oversampling * std::max(64u*64u, std::min(_params.areas[area]->Currentframe().TotalPixels() >> 2, 128u*128u));
52 }
53 
55  task.Stop();
56  task.Clear();
57 }
58 
60  task.Start();
61 }
62 
64  task.Stop();
65 }
66 
68  return standardchunksize;
69 }
70 
71 int32_t InputsDAQmx::Read(DaqChunk& _chunk, bool& _timedout, const double& _timeout) {
72  int32_t read = 0;
73  bool timedout = false;
74  try {
75  read = task.ReadU16(_chunk.data, _chunk.PerChannel(), _chunk.NChannels(), timedout, _timeout);
76  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
77  return read;
78 }
79 
80 }
ScopeNumber< double > range
Input range of the ADC.
Definition: IO.h:73
ScopeString referenceclocksource
source terminal of the reference clock
Definition: IO.h:79
Wraps hardware connection for signal input from PMTs.
Definition: Inputs.h:13
ScopeString commontrigger
The trigger channel which is the internal common master trigger for all devices.
Definition: Scope.h:262
const uint32_t area
the area
Definition: Inputs.h:17
ScopeNumber< bool > oversampling
if yes acquisition with maximum rate allowed by device (1/MinimumPixelTime(), calculated from maxrate...
Definition: IO.h:34
The master parameters class.
Definition: Scope.h:204
void ConfigureReferenceClock(const std::wstring &_src, const float64 &_rate)
Configures the reference clock for the task.
Definition: DAQmxTask.cpp:128
std::array< std::unique_ptr< Area >, SCOPE_NAREAS > areas
holds AreaParameters for all areas.
Definition: Scope.h:231
ScopeNumber< double > referenceclockrate
rate in Hertz of the reference clock.
Definition: IO.h:83
std::wstring ClockString(const scope::DaqTimingHelper::Mode &_timing, const std::wstring &_externalclocksource)
Generates a string for the sample clock from daq_timing.
Definition: DAQmxTask.cpp:46
void Start() override
Start task.
Definition: InputsDAQmx.cpp:59
DAQmx::CDAQmxAnalogInTask task
The DAQmx task.
Definition: InputsDAQmx.h:25
uint32_t requested_samples
the total number of samples that should be read (in case of nframes mode) otherwise the buffer size (...
Definition: Inputs.h:20
double MinimumPixeltime() const override
Definition: IO.cpp:85
void Stop() override
Stops task.
Definition: InputsDAQmx.cpp:63
ScopeString channelsstring
How many input channels (if sampling non-simulataneous this influences the available sampling rates) ...
Definition: IO.h:70
uint32_t standardchunksize
the standard chunk size per channel for Read
Definition: InputsDAQmx.h:28
int32_t Read(DaqChunk &_chunk, bool &_timedout, const double &_timeout) override
Reads one chunk of samples for one area.
Definition: InputsDAQmx.cpp:71
std::vector< uint16_t > data
The data vector.
Definition: DaqChunk.h:26
A DaqChunk contains data from all channels sequentially.
Definition: DaqChunk.h:9
This is the include file for standard system include files, or project specific include files that ar...
ScopeValue< DaqMode > requested_mode
requested acquisition mode (see DaqModeHelper)
Definition: Scope.h:279
void Start(void)
Starts the task.
Definition: DAQmxTask.cpp:145
uint32_t StandardChunkSize() const override
Definition: InputsDAQmx.cpp:67
In here all declarations for all kinds of datatypes Scope needs.
ScopeValue< DaqTiming > daq_timing
where to get the sampling clock from? Onboard, from external reference clock, or from external source...
Definition: IO.h:76
void ScopeExceptionHandler(const std::string &_origin, const bool &_log, const bool &_showmessagebox, const bool &_trace, const bool &_rethrow)
Handles all exceptions and does nice logging.
void Clear(void)
Clear the task.
Definition: DAQmxTask.cpp:153
~InputsDAQmx()
Stop and clear input tasks.
Definition: InputsDAQmx.cpp:54
void CreateTask(const std::wstring &_name=L"")
Definition: DAQmxTask.cpp:91
Parameters for pixel acquisition with NI-DAQmx.
Definition: IO.h:58
ScopeString externalclocksource
source terminal of an external clock
Definition: IO.h:86
InputsDAQmx(const uint32_t &_area, const parameters::InputsDAQmx *const _inputparams, const parameters::Scope &_params)
Creates a task for PMT signal acquisition with NI DAQmx.
Definition: InputsDAQmx.cpp:11
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
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
void Stop(void)
Stops the task.
Definition: DAQmxTask.cpp:149
int32 ReadU16(std::vector< uint16_t > &_data, const int32 &_sampsperchan, const uint32_t &_channels, bool &_timedout, const float64 &_timeout=2)
Definition: DAQmxTask.cpp:340