DynExp
Highly flexible laboratory automation for dynamically changing experiments.
HardwareAdapterSmarAct.h
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
9 #pragma once
10 
11 #include "stdafx.h"
12 #include "HardwareAdapter.h"
13 #include "../MetaInstruments/Stage.h"
14 
16 {
17  #include "../include/SmarAct/SmarActControl.h"
18 }
19 
20 namespace DynExpHardware
21 {
23 
25  {
26  public:
27  SmarActException(std::string Description, const int ErrorCode,
28  const std::source_location Location = std::source_location::current()) noexcept
29  : Exception(std::move(Description), Util::ErrorType::Error, ErrorCode, Location)
30  {}
31  };
32 
34  {
35  public:
37  virtual ~SmarActHardwareAdapterParams() = default;
38 
39  virtual const char* GetParamClassTag() const noexcept override { return "SmarActHardwareAdapterParams"; }
40 
41  Param<TextList> DeviceDescriptor = { *this, {}, "DeviceDescriptor", "Device descriptor",
42  "Descriptor of the SmarAct controller to connect with" };
43 
44  private:
45  void ConfigureParamsImpl(dispatch_tag<HardwareAdapterParamsBase>) override final;
47  };
48 
50  {
51  public:
54 
57 
58  private:
59  virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override { return DynExp::MakeParams<SmarActHardwareAdapterConfigurator>(ID, Core); }
60  };
61 
63  {
64  public:
67 
68  using ChannelType = int8_t;
69  using PositionType = int64_t;
71 
72  constexpr static auto Name() noexcept { return "SmarAct"; }
73  constexpr static auto Category() noexcept { return "Positioners"; }
74  static auto Enumerate();
75 
77  virtual ~SmarActHardwareAdapter();
78 
79  virtual std::string GetName() const override { return Name(); }
80  virtual std::string GetCategory() const override { return Category(); }
81 
82  bool IsOpened() const noexcept { return SmarActHandleValid; }
83 
84  // Position in pm or ndeg
85  PositionType GetCurrentPosition(const ChannelType Channel) const;
86  PositionType GetTargetPosition(const ChannelType Channel) const;
87 
88  // Velocity in pm/s or ndeg/s
89  PositionType GetVelocity(const ChannelType Channel) const;
90 
91  int32_t GetChannelState(const ChannelType Channel) const;
92 
93  void Calibrate(const ChannelType Channel) const;
94  void Reference(const ChannelType Channel) const;
95 
96  // Velocity in pm/s or ndeg/s
97  void SetVelocity(const ChannelType Channel, PositionType Velocity) const;
98 
99  // Position in pm or ndeg
100  void MoveAbsolute(const ChannelType Channel, PositionType Position) const;
101  void MoveRelative(const ChannelType Channel, PositionType Position) const;
102 
103  void StopMotion(const ChannelType Channel) const;
104 
105  private:
106  void Init();
107 
108  void ResetImpl(dispatch_tag<HardwareAdapterBase>) override final;
110 
111  void EnsureReadyStateChild() override final;
112  bool IsReadyChild() const override final;
113  bool IsConnectedChild() const noexcept override final;
114 
115  // Not thread-safe, must be called from function calling AcquireLock().
116  void CheckError(const SmarActSyms::SA_CTL_Result_t Result, const std::source_location Location = std::source_location::current()) const;
117 
118  void OpenUnsafe();
119  void CloseUnsafe();
120 
121  std::string DeviceDescriptor;
122  std::atomic<bool> SmarActHandleValid;
123 
124  SmarActSyms::SA_CTL_DeviceHandle_t SmarActHandle;
125  };
126 }
Implementation of DynExp hardware adapter objects.
SmarActException(std::string Description, const int ErrorCode, const std::source_location Location=std::source_location::current()) noexcept
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
SmarActHardwareAdapterParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
virtual void ConfigureParamsImpl(dispatch_tag< SmarActHardwareAdapterParams >)
void ConfigureParamsImpl(dispatch_tag< HardwareAdapterParamsBase >) override final
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
virtual std::string GetCategory() const override
Returns the category of this Object type.
PositionType GetVelocity(const ChannelType Channel) const
int32_t GetChannelState(const ChannelType Channel) const
void MoveAbsolute(const ChannelType Channel, PositionType Position) const
constexpr static auto Name() noexcept
bool IsConnectedChild() const noexcept override final
Determines the connection status of the hardware interface.
constexpr static auto Category() noexcept
void ResetImpl(dispatch_tag< HardwareAdapterBase >) override final
void MoveRelative(const ChannelType Channel, PositionType Position) const
virtual void ResetImpl(dispatch_tag< SmarActHardwareAdapter >)
void CheckError(const SmarActSyms::SA_CTL_Result_t Result, const std::source_location Location=std::source_location::current()) const
PositionType GetTargetPosition(const ChannelType Channel) const
SmarActSyms::SA_CTL_DeviceHandle_t SmarActHandle
void EnsureReadyStateChild() override final
Ensures that this Object instance is ready by possibly starting its worker thread or by opening conne...
void Calibrate(const ChannelType Channel) const
void SetVelocity(const ChannelType Channel, PositionType Velocity) const
void Reference(const ChannelType Channel) const
SmarActHardwareAdapter(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
bool IsReadyChild() const override final
Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) a...
virtual std::string GetName() const override
Returns the name of this Object type.
void StopMotion(const ChannelType Channel) const
PositionType GetCurrentPosition(const ChannelType Channel) const
DirectionType
Type to determine the direction of the positioner stage's movements.
Definition: Stage.h:160
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition: DynExpCore.h:127
Defines the base class for a hardware adapter object. Hardware adapters describe interfaces/connectio...
Configurator class for HardwareAdapterBase.
Parameter class for HardwareAdapterBase.
HardwareAdapterParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a HardwareAdapterBase instance.
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition: Object.h:2302
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition: Object.h:2303
Refer to ParamsBase::dispatch_tag.
Definition: Object.h:2018
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
Definition: Object.h:1779
const DynExpCore & Core
Reference to DynExp's core.
Definition: Object.h:1780
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Definition: Object.h:349
DynExp exceptions are derived from this class. It contains basic information about the cause of the e...
Definition: Exception.h:51
Exception(std::string Description, const ErrorType Type=ErrorType::Error, const int ErrorCode=-1, const std::source_location Location=std::source_location::current()) noexcept
Constructs an exception. Constructor is noexcept, although std::runtime_error() might throw std::bad_...
Definition: Exception.cpp:8
const int ErrorCode
DynExp error code from DynExpErrorCodes::DynExpErrorCodes
Definition: Exception.h:106
DynExp's hardware namespace contains the implementation of DynExp hardware adapters which extend DynE...
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition: Object.h:1807
size_t ItemIDType
ID type of objects/items managed by DynExp.
DynExp's Util namespace contains commonly used functions and templates as well as extensions to Qt an...
Definition: circularbuf.cpp:7
ErrorType
DynExp's error types
Definition: Exception.h:15
Accumulates include statements to provide a precompiled header.