DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
NetworkLaser.h
Go to the documentation of this file.
1// This file is part of DynExp.
2
8#pragma once
9
10#include "stdafx.h"
11#include "DynExpCore.h"
14
15#include "NetworkLaser.pb.h"
16#include "NetworkLaser.grpc.pb.h"
17
18namespace DynExpInstr
19{
20 class NetworkLaser;
21
22 constexpr DynExp::Units::UnitType ToLaserUnitType(DynExpProto::Common::FrequencyUnitType Unit)
23 {
24 switch (Unit)
25 {
26 case DynExpProto::Common::FrequencyUnitType::Hz: return DynExp::Units::UnitType::Freq_Hz;
27 case DynExpProto::Common::FrequencyUnitType::nm: return DynExp::Units::UnitType::Wavelength_nm;
28 default: throw Util::InvalidDataException("The given unit is not supported here. Did you forget to adjust this function or the FrequencyUnitType enumeration in file \"Common.proto\"?");
29 }
30 }
31
32 constexpr DynExp::Units::UnitType ToLaserUnitType(DynExpProto::Common::IntensityUnitType Unit)
33 {
34 switch (Unit)
35 {
36 case DynExpProto::Common::IntensityUnitType::Power_W: return DynExp::Units::UnitType::Power_W;
37 default: throw Util::InvalidDataException("The given unit is not supported here. Did you forget to adjust this function or the IntensityUnitType enumeration in file \"Common.proto\"?");
38 }
39 }
40
41 constexpr LaserData::LaserStateType ToLaserStateType(DynExpProto::NetworkLaser::StateType State)
42 {
43 switch (State)
44 {
45 case DynExpProto::NetworkLaser::StateType::Ready: return LaserData::LaserStateType::Ready;
46 case DynExpProto::NetworkLaser::StateType::Startup: return LaserData::LaserStateType::Startup;
47 case DynExpProto::NetworkLaser::StateType::EnabledConstant: return LaserData::LaserStateType::EmissionEnabledConstant;
48 case DynExpProto::NetworkLaser::StateType::EnabledScanning: return LaserData::LaserStateType::EmissionEnabledScanning;
49 case DynExpProto::NetworkLaser::StateType::ErrorState: return LaserData::LaserStateType::Error;
50 default: throw Util::InvalidDataException("The given state does not exist in the DynExpProto::NetworkLaser::StateType enumeration.");
51 }
52 }
53
54 namespace NetworkLaserTasks
55 {
56 class InitTask : public gRPCInstrumentTasks::InitTask<Laser, 0, DynExpProto::NetworkLaser::NetworkLaser>
57 {
59
60 virtual void InitFuncImpl(dispatch_tag<InitTask>, DynExp::InstrumentInstance& Instance) {}
61 };
62
63 class ExitTask : public gRPCInstrumentTasks::ExitTask<Laser, 0, DynExpProto::NetworkLaser::NetworkLaser>
64 {
66
67 virtual void ExitFuncImpl(dispatch_tag<ExitTask>, DynExp::InstrumentInstance& Instance) {}
68 };
69
70 class UpdateTask : public gRPCInstrumentTasks::UpdateTask<Laser, 0, DynExpProto::NetworkLaser::NetworkLaser>
71 {
73
74 virtual void UpdateFuncImpl(dispatch_tag<UpdateTask>, DynExp::InstrumentInstance& Instance) {}
75 };
76
78 {
79 public:
81
82 private:
84
85 double Frequency;
86 };
87
89 {
90 public:
92
93 private:
95
96 double Intensity;
97 };
98
100 {
101 public:
103
104 private:
106
107 double ScanRange;
108 };
109
111 {
112 public:
114
115 private:
117
118 double ScanRate;
119 };
120
121 class EnableTask final : public DynExp::TaskBase
122 {
123 public:
125
126 private:
128 };
129
131 {
132 public:
134
135 private:
137 };
138
140 {
141 public:
143
144 private:
146 };
147
148 class DisableTask final : public DynExp::TaskBase
149 {
150 public:
152
153 private:
155 };
156 }
157
158 class NetworkLaserData : public gRPCInstrumentData<Laser, 0, DynExpProto::NetworkLaser::NetworkLaser>
159 {
162
163 public:
164 NetworkLaserData() = default;
165 virtual ~NetworkLaserData() = default;
166
167 auto GetFrequencyUnit() const noexcept { return FrequencyUnit; }
168 auto GetIntensityUnit() const noexcept { return IntensityUnit; }
169 auto GetMinFrequency() const noexcept { return HardwareMinFrequency; }
170 auto GetMaxFrequency() const noexcept { return HardwareMaxFrequency; }
171 auto GetMinIntensity() const noexcept { return HardwareMinIntensity; }
172 auto GetMaxIntensity() const noexcept { return HardwareMaxIntensity; }
173 auto GetMinScanRange() const noexcept { return HardwareMinScanRange; }
174 auto GetMaxScanRange() const noexcept { return HardwareMaxScanRange; }
175 auto GetMinScanRate() const noexcept { return HardwareMinScanRate; }
176 auto GetMaxScanRate() const noexcept { return HardwareMaxScanRate; }
178
179 private:
181 virtual void ResetImpl(dispatch_tag<NetworkLaserData>) {};
182
183 virtual LaserStateType GetLaserStateChild() const noexcept override { return LaserState; }
184
196
197 LaserStateType LaserState = LaserStateType::Ready;
198 };
199
200 class NetworkLaserParams : public gRPCInstrumentParams<Laser, 0, DynExpProto::NetworkLaser::NetworkLaser>
201 {
202 public:
204 virtual ~NetworkLaserParams() = default;
205
206 virtual const char* GetParamClassTag() const noexcept override { return "NetworkLaserParams"; }
207
208 private:
209 void ConfigureParamsImpl(dispatch_tag<gRPCInstrumentParams<Laser, 0, DynExpProto::NetworkLaser::NetworkLaser>>) override final { ConfigureParamsImpl(dispatch_tag<NetworkLaserParams>()); }
210 virtual void ConfigureParamsImpl(dispatch_tag<NetworkLaserParams>) {}
211
212 DummyParam Dummy = { *this };
213 };
214
215 class NetworkLaserConfigurator : public gRPCInstrumentConfigurator<Laser, 0, DynExpProto::NetworkLaser::NetworkLaser>
216 {
217 public:
220
222 virtual ~NetworkLaserConfigurator() = default;
223
224 private:
225 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override { return DynExp::MakeParams<NetworkLaserConfigurator>(ID, Core); }
226 };
227
228 class NetworkLaser : public gRPCInstrument<Laser, 0, DynExpProto::NetworkLaser::NetworkLaser>
229 {
230 public:
234
235 constexpr static auto Name() noexcept { return "Network Laser"; }
236
238 virtual ~NetworkLaser() {}
239
240 virtual std::string GetName() const override { return Name(); }
241
242 virtual DynExp::Units::UnitType GetFrequencyUnit() const override;
243 virtual DynExp::Units::UnitType GetIntensityUnit() const override;
244 virtual double GetMinFrequency() const override;
245 virtual double GetMaxFrequency() const override;
246 virtual double GetMinIntensity() const override;
247 virtual double GetMaxIntensity() const override;
248 virtual double GetMinScanRange() const override;
249 virtual double GetMaxScanRange() const override;
250 virtual double GetMinScanRate() const override;
251 virtual double GetMaxScanRate() const override;
252 virtual double GetModeHopFreeTuningRange() const override;
253
254 // Logical const-ness: const member functions to allow inserting tasks into task queue.
255 virtual void SetFrequency(double Frequency, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkLaserTasks::SetFrequencyTask>(Frequency, std::move(CallbackFunc)); }
256 virtual void SetIntensity(double Intensity, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkLaserTasks::SetIntensityTask>(Intensity, std::move(CallbackFunc)); }
257 virtual void SetScanRange(double ScanRange, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkLaserTasks::SetScanRangeTask>(ScanRange, std::move(CallbackFunc)); }
258 virtual void SetScanRate(double ScanRate, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkLaserTasks::SetScanRateTask>(ScanRate, std::move(CallbackFunc)); }
259
260 virtual void Enable(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkLaserTasks::EnableTask>(std::move(CallbackFunc)); }
261 virtual void Disable(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkLaserTasks::DisableTask>(std::move(CallbackFunc)); }
262 virtual void ScanContinuously(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkLaserTasks::ScanContinuouslyTask>(std::move(CallbackFunc)); }
263 virtual void DisableScan(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkLaserTasks::DisableScanTask>(std::move(CallbackFunc)); }
264
265 private:
268
269 virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<NetworkLaserTasks::InitTask>(); }
270 virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<NetworkLaserTasks::ExitTask>(); }
271 virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<NetworkLaserTasks::UpdateTask>(); }
272 };
273}
Defines DynExp's core module as an interface between the UI and DynExp objects.
Defines a meta instrument for a laser source.
LaserStateType
Possible laser states.
Definition Laser.h:71
@ Startup
The laser is warming up.
@ Error
The laser is in an error state.
@ EmissionEnabledConstant
The laser is emitting in constant mode.
@ EmissionEnabledScanning
The laser is emitting in scan mode.
@ Ready
The laser is ready for emission.
Meta instrument for a laser.
Definition Laser.h:154
virtual ~NetworkLaserConfigurator()=default
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...
auto GetModeHopFreeTuningRange() const noexcept
auto GetMinIntensity() const noexcept
auto GetIntensityUnit() const noexcept
auto GetMaxFrequency() const noexcept
virtual ~NetworkLaserData()=default
auto GetMaxIntensity() const noexcept
void ResetImpl(dispatch_tag< gRPCInstrumentData< Laser, 0, DynExpProto::NetworkLaser::NetworkLaser > >) override final
auto GetMinScanRate() const noexcept
virtual LaserStateType GetLaserStateChild() const noexcept override
DynExp::Units::UnitType IntensityUnit
auto GetMinScanRange() const noexcept
auto GetMaxScanRange() const noexcept
auto GetMinFrequency() const noexcept
auto GetMaxScanRate() const noexcept
auto GetFrequencyUnit() const noexcept
DynExp::Units::UnitType FrequencyUnit
virtual void ConfigureParamsImpl(dispatch_tag< NetworkLaserParams >)
virtual ~NetworkLaserParams()=default
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...
NetworkLaserParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
void ConfigureParamsImpl(dispatch_tag< gRPCInstrumentParams< Laser, 0, DynExpProto::NetworkLaser::NetworkLaser > >) override final
DisableScanTask(CallbackType CallbackFunc) noexcept
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
DisableTask(CallbackType CallbackFunc) noexcept
EnableTask(CallbackType CallbackFunc) noexcept
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
void ExitFuncImpl(dispatch_tag< gRPCInstrumentTasks::ExitTask< Laser, 0, DynExpProto::NetworkLaser::NetworkLaser > >, DynExp::InstrumentInstance &Instance) override final
void InitFuncImpl(dispatch_tag< gRPCInstrumentTasks::InitTask< Laser, 0, DynExpProto::NetworkLaser::NetworkLaser > >, DynExp::InstrumentInstance &Instance) override final
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
ScanContinuouslyTask(CallbackType CallbackFunc) noexcept
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
SetFrequencyTask(double Frequency, CallbackType CallbackFunc) noexcept
SetIntensityTask(double Intensity, CallbackType CallbackFunc) noexcept
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
SetScanRangeTask(double ScanRange, CallbackType CallbackFunc) noexcept
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
SetScanRateTask(double ScanRate, CallbackType CallbackFunc) noexcept
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
void UpdateFuncImpl(dispatch_tag< gRPCInstrumentTasks::UpdateTask< Laser, 0, DynExpProto::NetworkLaser::NetworkLaser > >, DynExp::InstrumentInstance &Instance) override final
virtual void Disable(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Disables emission.
virtual std::unique_ptr< DynExp::UpdateTaskBase > MakeUpdateTask() const override
Factory function for an update task (UpdateTaskBase). Override to define the desired update task in d...
virtual double GetMinScanRate() const override
Determines the minimal frequency scan rate. The default implementation returns 0.0,...
virtual double GetMinFrequency() const override
Determines the minimal emission frequency. The default implementation returns GetMaxFrequency() which...
virtual DynExp::Units::UnitType GetIntensityUnit() const override
Determines the intensity unit.
virtual void SetFrequency(double Frequency, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Sets the laser's emission frequency.
virtual double GetMaxScanRange() const override
Determines the maximal frequency scan range. The default implementation returns 0....
virtual void SetScanRate(double ScanRate, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Sets the laser's frequency scan rate.
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
virtual void SetIntensity(double Intensity, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Sets the laser's output intensity.
virtual void DisableScan(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Disables scan and changes to constant emission mode.
virtual double GetMaxScanRate() const override
Determines the maximal frequency scan rate. The default implementation returns 0.0,...
virtual std::string GetName() const override
Returns the name of this Object type.
virtual void ScanContinuously(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Enables emission in scan mode.
virtual DynExp::Units::UnitType GetFrequencyUnit() const override
Determines the frequency unit.
virtual double GetMinScanRange() const override
Determines the minimal frequency scan range. The default implementation returns 0....
static constexpr auto Name() noexcept
virtual void SetScanRange(double ScanRange, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Sets the laser's frequency scan range.
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
virtual double GetModeHopFreeTuningRange() const override
Determines the mode hop free tuning range. The default implementation returns 0.0,...
virtual double GetMinIntensity() const override
Determines the minimal emission intensity. The default implementation returns GetMaxIntensity() which...
virtual double GetMaxIntensity() const override
Determines the maximal emission intensity.
virtual void Enable(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Enables emission in constant mode.
virtual double GetMaxFrequency() const override
Determines the maximal emission frequency.
void ResetImpl(dispatch_tag< gRPCInstrument< Laser, 0, DynExpProto::NetworkLaser::NetworkLaser > >) override final
Configurator class for gRPCInstrument.
Data class for gRPCInstrument.
Parameter class for gRPCInstrument.
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
DynExp::ExitTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
DynExp::InitTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
Defines a task for updating an instrument within an instrument inheritance hierarchy....
DynExp::UpdateTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
Meta instrument template for transforming meta instruments into network instruments,...
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition DynExpCore.h:127
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition Instrument.h:813
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition Object.h:2310
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition Object.h:2311
Refer to ParamsBase::dispatch_tag.
Definition Object.h:2026
Type owning a callback function which is invoked when a task has finished, failed,...
Definition Instrument.h:978
Base class for all tasks being processed by instruments. The class must not contain public virtual fu...
Definition Instrument.h:929
CallbackType CallbackFunc
This callback function is called after the task has finished (either successfully or not) with a poin...
TaskBase(CallbackType CallbackFunc=nullptr, std::chrono::system_clock::time_point DeferUntil={}) noexcept
Constructs an instrument task.
Defines the return type of task functions.
Definition Instrument.h:865
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Definition Exception.h:164
Defines a meta instrument template for transforming meta instruments into network instruments,...
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
constexpr LaserData::LaserStateType ToLaserStateType(DynExpProto::NetworkLaser::StateType State)
constexpr DynExp::Units::UnitType ToLaserUnitType(DynExpProto::Common::FrequencyUnitType Unit)
UnitType
Units which can be used with DynExp instruments.
Definition Units.h:28
@ Freq_Hz
Frequency in Hz.
@ Wavelength_nm
Wavelength in nm.
@ Power_W
Power in Watt (W)
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.
Accumulates include statements to provide a precompiled header.