Scope
XYControl.cpp
1 #include "StdAfx.h"
2 #include "XYControl.h"
3 #include "parameters/Devices.h"
4 #include "controllers/ScopeLogger.h"
5 
6 namespace scope {
7 
8 XYControl::XYControl()
9  : initialized(false)
10  , pollinterval(1000) {
11 }
12 
14  StopPolling();
15 }
16 
18  pos[0] = &_params.xpos;
19  pos[1] = &_params.ypos;
20  pollinterval = round2ui32(_params.pollinterval());
21  initialized = true;
22  // Polling more frequently most definitely will lead to problems...
23  if ( pollinterval > 100 ) {
24  // we need to call from the this pointer to call the most derived version of StartPolling
25  this->StartPolling();
26  }
27 }
28 
30  // If something went wrong during initialization we do not want to poll (and probably cause more errors)
31  if ( initialized ) {
32  fut = std::async([this]() {
33  while (!stop.IsSet()) {
35  std::this_thread::sleep_for(std::chrono::milliseconds(pollinterval));
36  }
37  return true;
38  } );
39  }
40 }
41 
43  stop.Set();
44  if ( fut.valid() )
45  fut.wait();
46 }
47 
49  // Do nothing
50 }
51 
52 }
virtual void Initialize(parameters::XYControl &_params)
Initialize hardware.
Definition: XYControl.cpp:17
bool initialized
true if initialized called successfully
Definition: XYControl.h:18
Parameters for a general xy stage.
Definition: Devices.h:134
virtual void StartPolling()
Start the worker function in the pollthread.
Definition: XYControl.cpp:29
virtual void StopPolling()
Stop the worker function.
Definition: XYControl.cpp:42
This is the include file for standard system include files, or project specific include files that ar...
uint32_t pollinterval
interval (in milliseconds) to poll device
Definition: XYControl.h:33
std::future< bool > fut
future for the async polling thread
Definition: XYControl.h:24
std::array< ScopeNumber< double > *, 2 > pos
pointers to a ScopeNumber that is updated with the polled x and y positions
Definition: XYControl.h:30
StopCondition stop
to signal the async polling thread to stop
Definition: XYControl.h:21
~XYControl()
If pollthread was started, request stop and wait for finish.
Definition: XYControl.cpp:13
ScopeNumber< double > xpos
x position of xy device
Definition: Devices.h:140
ScopeNumber< double > pollinterval
interval in milliseconds to poll device, be careful: long intervals slow quitting of Scope (since to ...
Definition: Devices.h:146
void Set(const bool &_a=true)
Definition: helpers.h:108
ScopeNumber< double > ypos
y position of xy device
Definition: Devices.h:143
virtual void UpdatePositionValues()
Updates xpos and ypos with the current device position.
Definition: XYControl.cpp:48
bool IsSet() const
Definition: helpers.h:105