Scope
SwitchResonance.cpp
1 #include "stdafx.h"
2 #include "SwitchResonance.h"
3 #include "helpers/ScopeException.h"
4 
5 namespace scope {
6 
7 SwitchResonance::SwitchResonance()
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 SwitchResonance::Initialize(const std::wstring& _outputline) {
19  try {
20  task.CreateTask();
21  task.CreateDOChannel(_outputline);
22  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
23  TurnOff();
24 }
25 
27  try {
28  task.WriteDigitalLines(&ondata, 1, true);
29  state = true;
30  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
31 }
32 
34  try {
35  task.WriteDigitalLines(&offdata, 1, true);
36  state = false;
37  } catch (...) { ScopeExceptionHandler(__FUNCTION__); }
38 }
39 
40 void SwitchResonance::Set(const bool& _on) {
41  if ( _on )
42  TurnOn();
43  else
44  TurnOff();
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 TurnOn(void)
Turns the relay on.
~SwitchResonance()
Relay gets closed on destruction.
void CreateDOChannel(const std::wstring &_devicelines, const std::wstring &_channelname=L"")
Creates a digital output channel.
Definition: DAQmxTask.cpp:270
void Set(const bool &_on)
Turns the relay on and off.
const uint8_t ondata
a one
This is the include file for standard system include files, or project specific include files that ar...
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 Initialize(const std::wstring &_outputline)
Relay gets closed on initialization.
void CreateTask(const std::wstring &_name=L"")
Definition: DAQmxTask.cpp:91
void TurnOff(void)
Turns the relay off.
std::atomic< bool > state
current relay state
const uint8_t offdata
a zero
DAQmx::CDAQmxDigitalOutTask task
the DAQmx task