Scope
StimulationsDAQmx.cpp
1 #include "stdafx.h"
2 #include "StimulationsDAQmx.h"
3 #include "parameters/Scope.h"
4 #include "ScopeDatatypes.h"
5 #include "helpers/ScopeException.h"
6 
7 namespace scope {
8 
10  if ( _params.stimulation.enable.Value() ) {
11  task.CreateTask();
12  task.CreateDOChannel(_params.stimulation.channel, L"DigStimOut");
13  int32 samplingtype = (_params.requested_mode()==DaqModeHelper::continuous)?DAQmx_Val_ContSamps:DAQmx_Val_FiniteSamps;
14  // Calculate pixelrate and number of pixels to generate
15  double pixelrate = 1/(_params.areas[ThisAreaOrMasterArea(0)]->daq.pixeltime()*1E-6);
16  int32_t pixelsperchan = _params.areas[ThisAreaOrMasterArea(0)]->Currentframe().TotalPixels();;
17  if ( _params.requested_mode() == DaqModeHelper::nframes )
18  pixelsperchan = _params.areas[ThisAreaOrMasterArea(0)]->Currentframe().TotalPixels() * _params.areas[ThisAreaOrMasterArea(0)]->daq.requested_frames() * _params.areas[ThisAreaOrMasterArea(0)]->daq.averages();
19 
20  // Synchronize stimulation to the first output task
21  task.ConfigureSampleTiming(_params.stimulation.timingsource(), pixelrate, pixelsperchan, samplingtype);
22  }
23 }
24 
26  task.Stop();
27  task.Clear();
28 }
29 
31  task.Start();
32 }
33 
34 int32_t StimulationsDAQmx::Write(std::shared_ptr<const std::vector<uint8_t>> const _stimvec) {
35  int32_t written = -1;
36  try {
37  written = task.WriteDigitalU8(_stimvec->data(), static_cast<int32_t>(_stimvec->size()));
38  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
39  return written;
40 }
41 
42 }
StimulationsDAQmx(const parameters::Scope &_params)
Creates the tasks for digital stimulation output with NI-DAQmx.
The master parameters class.
Definition: Scope.h:204
std::array< std::unique_ptr< Area >, SCOPE_NAREAS > areas
holds AreaParameters for all areas.
Definition: Scope.h:231
T Value() const
Definition: ScopeValue.h:46
ScopeString channel
digital output channel
Definition: Scope.h:33
~StimulationsDAQmx()
Stop and clear the digital stimulation task.
void CreateDOChannel(const std::wstring &_devicelines, const std::wstring &_channelname=L"")
Creates a digital output channel.
Definition: DAQmxTask.cpp:270
ScopeNumber< bool > enable
stimulation enabled/disabled
Definition: Scope.h:42
void Start()
Start stimulation task, waits on first output task sample clock.
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
In here all declarations for all kinds of datatypes Scope needs.
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
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
int32 WriteDigitalU8(const uInt8 *_data, int32 _sampsperchan, bool _autostart=false, float64 _timeout=2, bool32 _layout=DAQmx_Val_GroupByChannel)
Writes to an 8 bit digital output port, lowest bit is line0, highest bit is line7.
Definition: DAQmxTask.cpp:284
DAQmx::CDAQmxDigitalOutTask task
The DAQmx tasks.
ScopeString timingsource
timing source.
Definition: Scope.h:39
Stimulation stimulation
the StimulationParameters
Definition: Scope.h:249
void Stop(void)
Stops the task.
Definition: DAQmxTask.cpp:149
virtual int32_t Write(std::shared_ptr< const std::vector< uint8_t >> const _stimvec)
Write the stimulation vector to the digital stimulation task.