11 auto InstrParams = DynExp::dynamic_Params_cast<NP_Conex_CC>(Instance.
ParamsGetter());
12 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
14 InstrData->Channel = InstrParams->Conex_CC_Address;
15 Instance.
LockObject(InstrParams->HardwareAdapter, InstrData->HardwareAdapter);
16 InstrData->HardwareAdapter->Clear();
20 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"RS";
21 std::this_thread::sleep_for(std::chrono::milliseconds(500));
22 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PW1";
23 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"HT1";
24 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PW0";
25 std::this_thread::sleep_for(std::chrono::seconds(3));
26 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"OR";
36 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
41 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"ST";
56 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
57 auto Owner = DynExp::dynamic_Object_cast<NP_Conex_CC>(&Instance.
GetOwner());
58 bool UpdateError =
false;
63 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"TS";
65 StatusStream.exceptions(std::ofstream::failbit | std::ofstream::badbit);
67 char ErrorMapBuffer[5]{ 0 };
68 StatusStream.read(ErrorMapBuffer, 4);
69 std::istringstream ErrorMapStream(ErrorMapBuffer);
72 ErrorMapStream >> std::hex >> ErrorMap;
75 char StateBuffer[3]{ 0 };
76 StatusStream.read(StateBuffer, 2);
77 std::istringstream StateStream(StateBuffer);
80 StateStream >> std::hex >> State;
81 InstrData->Conex_CCStatus.Set(Util::NumToT<uint8_t>(State));
83 auto Conex_CCStatus = InstrData->GetConex_CCStatus();
85 if (Conex_CCStatus.NotReferencedFromReset() || Conex_CCStatus.NotReferencedFromHoming() || Conex_CCStatus.NotReferencedFromConfiguration()
86 || Conex_CCStatus.NotReferencedFromDisable() || Conex_CCStatus.NotReferencedFromReady() || Conex_CCStatus.NotReferencedFromMoving()
87 || Conex_CCStatus.NotReferencedNoParams() || Conex_CCStatus.Configuration() || Conex_CCStatus.DisableFromReady()
88 || Conex_CCStatus.DisableFromMoving() || Conex_CCStatus.DisableFromTracking() || Conex_CCStatus.DisableFromReadyT()
89 || Conex_CCStatus.TrackingFromReadyT() || Conex_CCStatus.TrackingFromTracking())
91 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"VA?";
93 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::SetVelocityTask>(Owner->GetDefaultVelocity()));
95 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::SetReadyTask>());
99 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"TP";
101 InstrData->SetCurrentPosition(Util::NumToT<PositionerStageData::PositionType>(Util::StrToT<double>(PositionalAnswer) * Owner->GetInputValuePositionTypeRatio()));
104 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"VA?";
106 InstrData->SetVelocity(Util::NumToT<PositionerStageData::PositionType>(Util::StrToT<double>(VelocityAnswer) * Owner->GetInputValuePositionTypeRatio()));
114 if (InstrData->NumFailedStatusUpdateAttempts++ >= 3)
119 InstrData->NumFailedStatusUpdateAttempts = 0;
136 catch (
const std::stringstream::failure& e)
148 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
150 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"RS";
157 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
159 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"OR";
166 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
169 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::SetReadyTask>(
nullptr,
170 std::chrono::system_clock::now() + std::chrono::milliseconds(3000)));
172 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::SetHomeExecutionTask>(
nullptr,
173 std::chrono::system_clock::now() + std::chrono::milliseconds(500)));
175 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::ResetTask>());
182 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
183 auto Owner = DynExp::dynamic_Object_cast<NP_Conex_CC>(&Instance.
GetOwner());
185 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PW1";
186 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"VA" +
Util::ToStr(InstrData->GetVelocity() / Owner->GetInputValuePositionTypeRatio());
187 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"HT1";
188 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PW0";
195 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
198 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::SetReadyTask>(
nullptr,
199 std::chrono::system_clock::now() + std::chrono::milliseconds(3000)));
201 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::ReferenceExecutionTask>(
nullptr,
202 std::chrono::system_clock::now() + std::chrono::milliseconds(500)));
204 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::ResetTask>());
211 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
212 auto Owner = DynExp::dynamic_Object_cast<NP_Conex_CC>(&Instance.
GetOwner());
214 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PW1";
215 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"VA" +
Util::ToStr(InstrData->GetVelocity() / Owner->GetInputValuePositionTypeRatio());
216 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"HT2";
217 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PW0";
224 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
225 auto Owner = DynExp::dynamic_Object_cast<NP_Conex_CC>(&Instance.
GetOwner());
227 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"VA" +
Util::ToStr(Velocity / Owner->GetInputValuePositionTypeRatio());
234 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
237 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::MoveToHomeExecutionTask>(
nullptr,
238 std::chrono::system_clock::now() + std::chrono::milliseconds(300)));
240 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::StopMotionTask>());
247 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
249 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PA0";
256 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
259 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::MoveAbsoluteExecutionTask>(Position,
nullptr,
260 std::chrono::system_clock::now() + std::chrono::milliseconds(300)));
262 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::StopMotionTask>());
269 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
270 auto Owner = DynExp::dynamic_Object_cast<NP_Conex_CC>(&Instance.
GetOwner());
272 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PA" +
Util::ToStr(Position / Owner->GetInputValuePositionTypeRatio());
279 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
282 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::MoveRelativeExecutionTask>(Position,
nullptr,
283 std::chrono::system_clock::now() + std::chrono::milliseconds(300)));
285 InstrData->EnqueuePriorityTask(DynExp::MakeTask<NP_Conex_CC_Tasks::StopMotionTask>());
292 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
293 auto Owner = DynExp::dynamic_Object_cast<NP_Conex_CC>(&Instance.
GetOwner());
295 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"PR" +
Util::ToStr(Position / Owner->GetInputValuePositionTypeRatio());
302 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(Instance.
InstrumentDataGetter());
306 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"ST";
313 Conex_CCStatus.Set(0);
315 NumFailedStatusUpdateAttempts = 0;
322 return Conex_CCStatus.Moving() || Conex_CCStatus.Homing();
327 return Conex_CCStatus.ReadyFromHoming() || Conex_CCStatus.ReadyFromMoving() || Conex_CCStatus.ReadyFromDisable()
328 || Conex_CCStatus.ReadyTFromReady() || Conex_CCStatus.ReadyTFromTracking() || Conex_CCStatus.ReadyTFromDisableT();
333 return ErrorCode != 0
334 || Conex_CCStatus.NotReferencedFromReset() || Conex_CCStatus.NotReferencedFromHoming() || Conex_CCStatus.NotReferencedFromConfiguration()
335 || Conex_CCStatus.NotReferencedFromDisable() || Conex_CCStatus.NotReferencedFromReady() || Conex_CCStatus.NotReferencedFromMoving()
336 || Conex_CCStatus.NotReferencedNoParams() || Conex_CCStatus.Configuration() || Conex_CCStatus.DisableFromReady()
337 || Conex_CCStatus.DisableFromMoving() || Conex_CCStatus.DisableFromTracking() || Conex_CCStatus.DisableFromReadyT()
338 || Conex_CCStatus.TrackingFromReadyT() || Conex_CCStatus.TrackingFromTracking();
343 auto Pos = Answer.find(StartCode);
347 else if (Pos == std::string::npos)
350 return Answer.substr(Pos + 2);
360 auto InstrData = DynExp::dynamic_InstrumentData_cast<NP_Conex_CC>(
GetInstrumentData());
363 *InstrData->HardwareAdapter <<
Util::ToStr(InstrData->GetChannel()) +
"ST";
Implementation of an instrument to control Newport stages with the Conex-CC controller.
virtual bool HasFailedChild() const noexcept override
Returns whether the stage is in an error state, i.e. moving has failed (result of HasFailedChild())
virtual bool IsMovingChild() const noexcept override
Returns whether the stage is currently moving (result of IsMovingChild())
virtual bool HasArrivedChild() const noexcept override
Returns whether the stage has arrived at its destiny position (result of HasArrivedChild())
void ResetImpl(dispatch_tag< PositionerStageData >) override final
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()...
void ExitFuncImpl(dispatch_tag< PositionerStageTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
void InitFuncImpl(dispatch_tag< PositionerStageTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
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...
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...
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...
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...
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...
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...
void UpdateFuncImpl(dispatch_tag< PositionerStageTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
virtual void OnErrorChild() const override
Derived classes can perform critical shutdown actions after an error has occurred....
static std::string AnswerToNumberString(std::string &&Answer, const char *StartCode)
NP_Conex_CC(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
void ResetImpl(dispatch_tag< PositionerStage >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
Implementation of a meta instrument to control single-axis positioner stages.
Refer to DynExp::ParamsBase::dispatch_tag.
Refer to DynExp::ParamsBase::dispatch_tag.
InstrumentDataTypeSyncPtrType GetInstrumentData(const std::chrono::milliseconds Timeout=GetInstrumentDataTimeoutDefault)
Locks the mutex of the instrument data class instance InstrumentData assigned to this InstrumentBase ...
Refer to ParamsBase::dispatch_tag.
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
const InstrumentBase::InstrumentDataGetterType InstrumentDataGetter
Getter for instrument's data. Refer to InstrumentBase::InstrumentDataGetterType.
Refer to ParamsBase::dispatch_tag.
const Object::ParamsGetterType ParamsGetter
Invoke to obtain the parameters (derived from ParamsBase) of Owner.
void UnlockObject(LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer)
Unlocks an Object instance stored in the LinkedObjectWrapperContainer ObjectWrapperContainer....
void LockObject(const ParamsBase::Param< ObjectLink< ObjectT > > &LinkParam, LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer, std::chrono::milliseconds Timeout=ObjectLinkBase::LockObjectTimeoutDefault)
Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< O...
const auto & GetOwner() const noexcept
Returns Owner.
Defines the return type of task functions.
Refer to DynExp::ParamsBase::dispatch_tag.
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Thrown when an operation timed out before it could be completed, especially used for locking shared d...
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
std::string ToStr(const T &Value, int Precision=-1)
Converts a (numeric) value of type T to a std::string using operator<< of std::stringstream.
Accumulates include statements to provide a precompiled header.