Scope
SutterController.cpp
1 #include "stdafx.h"
2 #include "SutterController.h"
3 #include "helpers\ScopeException.h"
4 #include "helpers\helpers.h"
5 #include "controllers\ScopeLogger.h"
6 
7 #ifdef SCOPE_USE_SUTTER_XYZSTAGE
8 
9 namespace scope {
10 
11 std::mutex SutterController::mutex;
12 
13 SutterController::SutterController(const std::wstring& _comstring)
14  : comstring(_comstring) {
15 }
16 
17 SerialConnection& SutterController::Ctrl() {
18  return CreateInstance(comstring);
19 }
20 
21 void SutterController::CheckError(const std::vector<BYTE>& _received) {
22  // Returned bytes should end with a carriage return/CR/"\r"/0x0D
23  if ( _received.back() != 0x0D )
24  throw ScopeException("SutterController::CheckError");
25 }
26 
27 std::vector<BYTE> SutterController::Command(const std::string& _cmd, const uint32_t& _answerbytes) {
28  std::lock_guard<std::mutex> lock(mutex);
29  if ( _cmd.back() != '\r' ) {
30  DBOUT(L"SutterController::Command command not terminated by CR!");
31  return std::vector<BYTE>(_answerbytes, 0);
32  }
33 
34  Ctrl().Send(_cmd);
35 
36  std::vector<BYTE> received(Ctrl().Receive(_answerbytes));
37  CheckError(received);
38  return received;
39 }
40 
41 SerialConnection& SutterController::CreateInstance(const std::wstring& _comstring) {
42  // Serial connection needs comstring in a very special format for COM ports, e.g. //.//COM1
43  std::wstring realcomstring = L"//.//" + _comstring;
44 
45  static std::unique_ptr<SerialConnection> connection(new SerialConnection(realcomstring));
46  return *connection;
47 }
48 
49 }
50 
51 #endif
This is the include file for standard system include files, or project specific include files that ar...
bool CheckError(const int32 &error)
Checks return value of NI DAQmx function for error, prints out error information and throws an except...
Definition: DAQmxTask.cpp:9
#define DBOUT(s)
A debug output to the debug console.
Definition: helpers.h:153
Various helper functions and classes for Scope.