Scope
OutputsDAQmxSlave.cpp
1 #include "stdafx.h"
2 #include "OutputsDAQmxSlave.h"
3 #include "parameters/IO.h"
4 #include "parameters/Scope.h"
5 
6 namespace scope {
7 
8 OutputsDAQmxSlave::OutputsDAQmxSlave(const uint32_t& _area, const parameters::OutputsDAQmxSlave& _outputparams, const parameters::Scope& _params)
9  : Outputs(_area) {
10 
11  if ( _area == 0 )
12  throw ScopeException("The first area must not be a slave area! Reconfigure!!!!");
13 
14  int32_t samplingtype = (_params.requested_mode()==DaqModeHelper::continuous)?DAQmx_Val_ContSamps:DAQmx_Val_FiniteSamps;
15 
16  std::wstring commontrig = _params.commontrigger();
17 
20  , L"ZPOut"
21  , -_outputparams.range()
22  , _outputparams.range());
23 
24  // Calculate pixelrate and number of pixels to generate
25  double pixelrate = 1/(_params.areas[ThisAreaOrMasterArea(area)]->daq.pixeltime()*1E-6); // Pixelrate/Pixeltime to be the same as Master area
26  // Slave outputs only one line (repeated)
27  int32_t pixelsperchan = _params.areas[area]->Currentframe().XTotalPixels();
28  if ( _params.requested_mode() == DaqModeHelper::nframes )
29  pixelsperchan = _params.areas[area]->Currentframe().TotalPixels() * _params.areas[area]->daq.requested_frames() * _params.areas[area]->daq.averages();
30 
31  // Configure timing (if using ReferenceClock timing ClockString gives "")
33  , pixelrate
34  , pixelsperchan
35  , samplingtype);
36  if ( DaqTimingHelper::Mode::ReferenceClock ==_outputparams.timing() )
38 
39  zpout_task.ConfigureBuffer( _params.areas[area]->Currentframe().XTotalPixels() );
40 
41  // Regenerate frame samples if we are in nframes mode
42  if ( _params.requested_mode() == DaqModeHelper::nframes )
44 
45  // All (exept the first aouttask) wait for the first tasks start trigger
46  if ( area != 0 ) {
47  zpout_task.ConfigureDigStartTrigger(commontrig, DAQmx_Val_Rising);
48  }
49 }
50 
51 OutputsDAQmxSlave::~OutputsDAQmxSlave(void) {
52  Stop();
53  zpout_task.Clear();
54 }
55 
57  zpout_task.Start();
58 }
59 
61  writeabort = true;
62  zpout_task.Stop();
63 }
64 
65 int32_t OutputsDAQmxSlave::Write(const std::vector<int16_t>& _zp, const uint32_t& _blocks) {
66  int32_t written = 0;
67  assert(_blocks!=0);
68  int32_t sizeperchannel = static_cast<int32_t>(_zp.size() / 2); // number of samples in each output channel
69  int32_t blocksize = sizeperchannel/_blocks;
70  int32_t lastblocksize = blocksize + (sizeperchannel - blocksize*_blocks); // adjust size of last block if sizeperchannel is not a multiple of blocksize
71  DBOUT(L"OutputsDAQmxSlave::Write blocksize " << blocksize << L" last block " << lastblocksize);
72  DBOUT(L"OutputsDAQmxSlave::Write blocks " << _blocks << L" sizeperchannel " << sizeperchannel << L" totblocksize " << (_blocks-1)*blocksize+lastblocksize);
73 
74  try {
75  for ( uint32_t b = 0 ; b < _blocks ; b++ ) {
76  if ( writeabort == true ) {
77  DBOUT(L"OutputsDAQmxSlave::Write writeabort");
78  break;
79  }
80  DBOUT(L"OutputsDAQmxSlave::Write block " << b);
81  zpout_task.SetWriteOffset(b*blocksize); // set write offset in the device buffer
82  written += zpout_task.WriteAnalogI16((_zp.data()+2*b*blocksize) // set offset in the data vector
83  , ((b==_blocks-1)?lastblocksize:blocksize), false, 2, DAQmx_Val_GroupByScanNumber); // data layout is by sample
84  }
85  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
86  writeabort = false;
87 
88  return written;
89 }
90 
93  try {
94  task.CreateTask();
95  task.CreateAOVoltageChannel(_params.zpout()
96  , L"XYZPOut"
97  , -_params.range()
98  , _params.range());
99  task.WriteAnalogI16(std::make_shared<std::vector<int16_t>>(2,0)->data(), 1, true);
100  task.WaitUntilDone(500);
101  task.Clear();
102  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
103 }
104 
105 
106 }
int32_t Write(const std::vector< int16_t > &_xyzp, const uint32_t &_blocks) override
we also take a std::vector but for the slave area it has only samples for z&p ! ...
ScopeString commontrigger
The trigger channel which is the internal common master trigger for all devices.
Definition: Scope.h:262
void SetRegeneration(const bool &_regenerate)
Sets the mode of sample regeneration.
Definition: DAQmxTask.cpp:177
The master parameters class.
Definition: Scope.h:204
Simple exception class for Scope.
Definition: ScopeException.h:9
void ConfigureReferenceClock(const std::wstring &_src, const float64 &_rate)
Configures the reference clock for the task.
Definition: DAQmxTask.cpp:128
int32_t WaitUntilDone(const float64 &_waittime)
Waits until the task is done.
Definition: DAQmxTask.cpp:163
DAQmx::CDAQmxAnalogOutTask zpout_task
Task for fast z/Pockels clocked by a pixel clock.
std::array< std::unique_ptr< Area >, SCOPE_NAREAS > areas
holds AreaParameters for all areas.
Definition: Scope.h:231
ScopeString externalclocksource
source terminal of an external clock for sampling clock (could be e.g.
Definition: IO.h:684
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.
std::atomic< bool > writeabort
Signal for aborting a write operation (since write is performed in several blocks, abort can happen in between)
Definition: Outputs.h:13
ScopeNumber< double > referenceclockrate
rate in Hertz of the reference clock for sampling clock.
Definition: IO.h:681
uInt32 ConfigureBuffer(const uInt32 &_sampsperchannel)
Configure the daqmx output buffer on the PC.
Definition: DAQmxTask.cpp:201
int32 WriteAnalogI16(const int16 *_data, int32 _sampsperchan, bool _autostart=false, int32 _timeout=2, bool32 _layout=DAQmx_Val_GroupByChannel)
Writes several samples to the buffer of an analog output task.
Definition: DAQmxTask.cpp:258
void SetWriteOffset(int32 posreltofirst)
Sets the write offset relative to the first buffer position.
Definition: DAQmxTask.cpp:172
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
void Stop() override
Stops task.
#define DBOUT(s)
A debug output to the debug console.
Definition: helpers.h:153
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 CreateAOVoltageChannel(const std::wstring &_devices, const std::wstring &_channelname=L"", float64 _minval=-10.0, float64 _maxval=10.0, int32 _units=DAQmx_Val_Volts, const std::wstring &_customscalename=L"")
Creates an analog output channel Allowed values for terminal configuration (from NiDAQmx.h): Values for DAQmx_PhysicalChan_AI_TermCfgs and DAQmx_PhysicalChan_AO_TermCfgs Value set TerminalConfigurationBits .
Definition: DAQmxTask.cpp:182
Wraps a DAQmx Analog Output task.
Definition: DAQmxTask.h:137
void Clear(void)
Clear the task.
Definition: DAQmxTask.cpp: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
const uint32_t area
which area this one is for
Definition: Outputs.h:10
ScopeNumber< double > range
Output range of the DAC to use for all outputs.
Definition: IO.h:526
ScopeValue< DaqTiming > timing
where to get the sampling clock from? Onboard, from external reference clock, or from external source...
Definition: IO.h:671
Parameters for fastz/Pockels signal generation with NI-DAQmx where zp are driven by a pixel clock fro...
Definition: IO.h:656
OutputsDAQmxSlave(const uint32_t &_area, const parameters::OutputsDAQmxSlave &_outputparams, const parameters::Scope &_params)
Create the task for pockels and fast z.
ScopeString zpout
Analog output channel for fast z and Pockels cell (clocked by a pixel clock)
Definition: IO.h:668
ZeroOutputsDAQmxSlave(const parameters::OutputsDAQmxSlave &_params)
Create a simple tasks for writing a scalar zero to all channels.
ScopeString referenceclocksource
source terminal of the reference clock for the sampling clock
Definition: IO.h:677
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
Wraps hardware connection for signal output to scanners, fast z control, and pockels cell...
Definition: Outputs.h:6