Scope
Shutter.cpp
1 #include "stdafx.h"
2 #include "Shutter.h"
3 #include "helpers/ScopeException.h"
4 
5 namespace scope {
6 
7 Shutter::Shutter()
8  : state(false)
9  , ondata(1)
10  , offdata(0) {
11 }
12 
14  task.WriteDigitalLines(&offdata, 1, true); // Do not check for exception here
15  state = false;
16 }
17 
18 void Shutter::Initialize(const std::wstring& _outputline) {
19  try {
20  task.CreateTask();
21  task.CreateDOChannel(_outputline);
22  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
23  Close();
24 }
25 
26 void Shutter::Open(void) {
27  try {
28  task.WriteDigitalLines(&ondata, 1, true);
29  state = true;
30  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
31 }
32 
33 void Shutter::Close(void) {
34  try {
35  task.WriteDigitalLines(&offdata, 1, true);
36  state = false;
37  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
38 }
39 
40 void Shutter::Set(const bool& _open) {
41  if ( _open )
42  Open();
43  else
44  Close();
45 }
46 
47 }
int32_t WriteDigitalLines(const uInt8 *_data, int32 _sampsperchan, bool _autostart=false, float64 _timeout=2, bool32 _layout=DAQmx_Val_GroupByChannel)
Writes to up to 8 digital lines (in one port, I suppose), depending on which lines are configured int...
Definition: DAQmxTask.cpp:296
void Set(const bool &_open)
Open/Closes the shutter.
Definition: Shutter.cpp:40
void Open(void)
Opens the shutter.
Definition: Shutter.cpp:26
void CreateDOChannel(const std::wstring &_devicelines, const std::wstring &_channelname=L"")
Creates a digital output channel.
Definition: DAQmxTask.cpp:270
~Shutter()
Shutter gets closed on destruction.
Definition: Shutter.cpp:13
void Close(void)
Closes the shutter.
Definition: Shutter.cpp:33
This is the include file for standard system include files, or project specific include files that ar...
void Initialize(const std::wstring &_outputline)
Shutter gets closed on initialization.
Definition: Shutter.cpp:18
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.
const uint8_t ondata
a one
Definition: Shutter.h:19
void CreateTask(const std::wstring &_name=L"")
Definition: DAQmxTask.cpp:91
const uint8_t offdata
a zero
Definition: Shutter.h:22
std::atomic< bool > state
current shutter state
Definition: Shutter.h:16
DAQmx::CDAQmxDigitalOutTask task
the DAQmx task
Definition: Shutter.h:13