10 ZILabOneHardwareAdapterSyms::ZIConnection TempConnection;
11 auto Result = ZILabOneHardwareAdapterSyms::ziAPIInit(&TempConnection);
12 if (Result != ZILabOneHardwareAdapterSyms::ZI_INFO_SUCCESS)
15 std::string DeviceList;
16 for (
int i = 1; i < 100; ++i)
18 DeviceList.resize(i * 256);
21 Result = ZILabOneHardwareAdapterSyms::ziAPIDiscoveryFindAll(TempConnection, DeviceList.data(), Util::NumToT<uint32_t>(DeviceList.size()));
22 if (Result != ZILabOneHardwareAdapterSyms::ZI_ERROR_LENGTH)
26 ZILabOneHardwareAdapterSyms::ziAPIDestroy(TempConnection);
29 if (Result != ZILabOneHardwareAdapterSyms::ZI_INFO_SUCCESS)
33 std::vector<std::string> DeviceDescriptors;
34 if (DeviceList[0] !=
'\0')
36 std::replace(DeviceList.begin(), DeviceList.end(),
'\n',
' ');
37 std::string DeviceListRemovedZeros;
38 std::remove_copy(DeviceList.begin(), DeviceList.end(), std::back_inserter(DeviceListRemovedZeros),
'\0');
39 std::istringstream ss(DeviceListRemovedZeros);
40 DeviceDescriptors = { std::istream_iterator<std::string>(ss), std::istream_iterator<std::string>() };
43 return DeviceDescriptors;
50 std::find(ZILabOneHardwareAdapterDevices.cbegin(), ZILabOneHardwareAdapterDevices.cend(),
DeviceDescriptor) == std::cend(ZILabOneHardwareAdapterDevices))
52 if (ZILabOneHardwareAdapterDevices.empty())
61 : HardwareAdapterBase(OwnerThreadID, std::move(Params))
287 auto Result = ZILabOneHardwareAdapterSyms::ziAPIInit(&
ZIConnection);
292 auto DerivedParams = dynamic_Params_cast<ZILabOneHardwareAdapter>(
GetParams());
304 ZILabOneHardwareAdapterSyms::ziAPIDestroy(
ZIConnection);
335 if (Result == ZILabOneHardwareAdapterSyms::ZI_INFO_SUCCESS)
338 char* ErrorString =
nullptr;
339 ZILabOneHardwareAdapterSyms::ziAPIGetError(Result, &ErrorString,
nullptr);
353 const char* DeviceID =
nullptr;
354 const char* ServerAddress;
355 ZILabOneHardwareAdapterSyms::ZIIntegerData Port = 0;
356 ZILabOneHardwareAdapterSyms::ZIIntegerData APILevel = 6;
369 Result = ZILabOneHardwareAdapterSyms::ziAPIConnectEx(
ZIConnection, ServerAddress,
static_cast<uint16_t
>(Port),
370 static_cast<ZILabOneHardwareAdapterSyms::ZIAPIVersion_enum
>(APILevel),
nullptr);
373 const char* Connected;
376 if (std::string(Connected).empty())
379 const char* Interfaces;
384 std::string InterfacesStr(Interfaces);
385 std::replace(InterfacesStr.begin(), InterfacesStr.end(),
'\n',
' ');
386 std::istringstream ss(InterfacesStr);
387 std::vector<std::string> InterfacesList{ std::istream_iterator<std::string>(ss), std::istream_iterator<std::string>() };
388 if (InterfacesList.empty())
390 "The interface list of the selected ZI instrument is empty.")));
391 if (std::find(InterfacesList.cbegin(), InterfacesList.cend(),
Interface) == InterfacesList.cend())
393 "The ZI instrument does not support the specified interface for establishing a connection.")));
434 Result = ZILabOneHardwareAdapterSyms::ziAPIDisconnect(
ZIConnection);
442 if (SignalInput != SignalInputType::Current)
480 ZILabOneHardwareAdapterSyms::ZIIntegerData Finished =
false;
489 ZILabOneHardwareAdapterSyms::ZIDoubleData Progress{};
510 std::map<double, DynExpInstr::LockinAmplifierDefs::LockinSample> RawSamples;
514 std::string NodePath(1024,
'\0');
515 ZILabOneHardwareAdapterSyms::ZIModuleEventPtr EventPtr =
nullptr;
516 ZILabOneHardwareAdapterSyms::ZIValueType_enum EventValueType{};
517 uint64_t NumChunks{};
518 bool ZeroTimestampSet =
false;
519 ZILabOneHardwareAdapterSyms::ZITimeStamp ZeroTimestamp{ 0 };
526 NodePath.data(), Util::NumToT<uint32_t>(NodePath.length()), &EventValueType, &NumChunks);
527 if (Result == ZILabOneHardwareAdapterSyms::ZI_WARNING_NOTFOUND)
531 for (decltype(NumChunks) CurrentChunk = 0; CurrentChunk < NumChunks; ++CurrentChunk)
536 if (EventPtr->value->valueType == ZILabOneHardwareAdapterSyms::ZI_VALUE_TYPE_DOUBLE_DATA_TS)
538 ZILabOneHardwareAdapterSyms::ZIEvent& e = *EventPtr->value;
541 std::string Path(e.path, e.path +
sizeof(e.path) /
sizeof(e.path[0]));
542 auto StartDemodStr = Path.find(
"demods/") + 7;
543 auto EndDemodStr = Path.find(
"/sample");
544 auto Demodulator = std::stoul(Path.substr(StartDemodStr, EndDemodStr - StartDemodStr));
545 if (Demodulator > std::numeric_limits<uint8_t>::max())
547 "A received demodulator number is invalid.")));
550 auto StartChannelStr = Path.find(
"sample.") + 7;
551 auto Channel = Path.substr(StartChannelStr, 1);
552 if (Channel !=
"x" && Channel !=
"y")
554 "A received demodulator channel is invalid.")));
555 bool IsX = Channel ==
"x";
557 for (
size_t i = 0; i < e.count; ++i)
559 if (!ZeroTimestampSet)
561 ZeroTimestamp = e.value.doubleDataTS[i].timeStamp;
562 ZeroTimestampSet =
true;
565 auto Timestamp =
static_cast<double>(e.value.doubleDataTS[i].timeStamp - ZeroTimestamp) /
Clockbase;
566 RawSamples[Timestamp].Time = Timestamp;
567 RawSamples[Timestamp].Channel =
static_cast<uint8_t
>(Demodulator);
570 RawSamples[Timestamp].CartesianResult.X = e.value.doubleDataTS[i].value;
572 RawSamples[Timestamp].CartesianResult.Y = e.value.doubleDataTS[i].value;
593 std::vector<DynExpInstr::LockinAmplifierDefs::LockinSample> Samples;
594 for (
auto& Sample : RawSamples)
596 Sample.second.UpdatePolar();
597 Samples.push_back(Sample.second);
607 case SignalInputType::Current:
return "currins";
608 default:
return "sigins";
681 std::string Data(1024,
'\0');
682 unsigned int Length{};
684 auto Result = ZILabOneHardwareAdapterSyms::ziAPIModGetString(
ZIConnection,
DAQModuleHandle,
"triggernode", Data.data(), &Length, Util::NumToT<unsigned int>(Data.length()));
717 ZILabOneHardwareAdapterSyms::ZIIntegerData Data;
761 ZILabOneHardwareAdapterSyms::ZIDoubleData Data;
765 return static_cast<double>(Data);
770 ZILabOneHardwareAdapterSyms::ZIIntegerData Data;
774 return static_cast<long long>(Data);
Implementation of a hardware adapter to control Zurich Instruments MFLI hardware.
void ConfigureParamsImpl(dispatch_tag< HardwareAdapterParamsBase >) override final
Param< TextList > DeviceDescriptor
double GetDemodPhaseUnsafe(uint8_t Demodulator) const
double GetOscillatorFrequency(uint8_t Oscillator) const
void ForceTrigger() const
bool IsInputOverloadUnsafe(SignalInputType SignalInput) const
void SetTriggerModeUnsafe(DynExpInstr::LockinAmplifierDefs::TriggerModeType TriggerMode, uint8_t Demodulator, uint8_t TriggerChannel) const
bool IsReadyChild() const override final
Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) a...
double GetDemodTimeConstantUnsafe(uint8_t Demodulator) const
constexpr static bool DetermineOverload(double PosInputLoad, double NegInputLoad)
void SetDemodPhaseUnsafe(uint8_t Demodulator, double Phase) const
double GetDemodSamplingRateUnsafe(uint8_t Demodulator) const
bool GetEnabled(uint8_t Demodulator) const
bool IsInputOverload(SignalInputType SignalInput) const
bool IsOpened() const noexcept
double GetAcquisitionProgress() const
ZILabOneHardwareAdapterSyms::ZIModuleHandle DAQModuleHandle
double GetDemodSamplingRate(uint8_t Demodulator) const
double ReadDoubleUnsafe(const std::string &Path) const
double GetDemodPhase(uint8_t Demodulator) const
ZILabOneHardwareAdapter(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
ZILabOneHardwareAdapterSyms::ZIConnection ZIConnection
void StopAcquisitionUnsafe() const
double GetOscillatorFrequencyUnsafe(uint8_t Oscillator) const
void EnsureReadyStateChild() override final
Ensures that this Object instance is ready by possibly starting its worker thread or by opening conne...
void SetTriggerEdgeUnsafe(DynExpInstr::LockinAmplifierDefs::TriggerEdgeType TriggerEdge) const
long long ReadIntUnsafe(const std::string &Path) const
void AutoAdjustDemodPhase(uint8_t Demodulator) const
void ResetImpl(dispatch_tag< HardwareAdapterBase >) override final
double GetDemodTimeConstant(uint8_t Demodulator) const
double GetPosInputLoad(SignalInputType SignalInput) const
virtual ~ZILabOneHardwareAdapter()
void ConfigureInput(SignalInputType SignalInput, uint8_t Demodulator) const
double GetInputRangeUnsafe(SignalInputType SignalInput) const
void AutoAdjustDemodPhaseUnsafe(uint8_t Demodulator) const
double GetInputRange(SignalInputType SignalInput) const
void AutoAdjustInputRangeUnsafe(SignalInputType SignalInput) const
void SetDemodFilterOrder(uint8_t Demodulator, uint8_t FilterOrder) const
double GetAcquisitionProgressUnsafe() const
std::vector< DynExpInstr::LockinAmplifierDefs::LockinSample > GetAcquiredDataUnsafe() const
void SetTriggerEdge(DynExpInstr::LockinAmplifierDefs::TriggerEdgeType TriggerEdge) const
void ForceTriggerUnsafe() const
uint8_t GetDemodFilterOrder(uint8_t Demodulator) const
void ClearAcquiredData() const
double GetPosInputLoadUnsafe(SignalInputType SignalInput) const
DynExpInstr::LockinAmplifierDefs::TriggerModeType GetTriggerMode() const
std::atomic< bool > Opened
void SetDemodTimeConstantUnsafe(uint8_t Demodulator, double TimeConstant) const
bool GetEnabledUnsafe(uint8_t Demodulator) const
bool HasFinishedAcquisitionUnsafe() const
void WriteDoubleUnsafe(const std::string &Path, double Value) const
DynExpInstr::LockinAmplifierDefs::TriggerEdgeType GetTriggerEdgeUnsafe() const
void SetDemodTimeConstant(uint8_t Demodulator, double TimeConstant) const
void AutoAdjustInputRange(SignalInputType SignalInput) const
void SetTriggerMode(DynExpInstr::LockinAmplifierDefs::TriggerModeType TriggerMode, uint8_t Demodulator=0, uint8_t TriggerChannel=1) const
void SetDemodPhase(uint8_t Demodulator, double Phase) const
void SetDemodSamplingRate(uint8_t Demodulator, double SamplingRate) const
void SetEnabledUnsafe(uint8_t Demodulator, bool Enabled) const
double StartAcquisition(uint8_t Demodulator, size_t NumSamples, size_t NumRuns=1, bool AverageRuns=false) const
double GetNegInputLoadUnsafe(SignalInputType SignalInput) const
double GetNegInputLoad(SignalInputType SignalInput) const
void ClearAcquiredDataUnsafe() const
void SetDemodSamplingRateUnsafe(uint8_t Demodulator, double SamplingRate) const
DynExpInstr::LockinAmplifierDefs::TriggerEdgeType GetTriggerEdge() const
DynExpInstr::LockinAmplifierDefs::TriggerModeType GetTriggerModeUnsafe() const
void CheckError(const ZILabOneHardwareAdapterSyms::ZIResult_enum Result, const std::source_location Location=std::source_location::current()) const
void SetInputRangeUnsafe(SignalInputType SignalInput, double InputRange) const
std::string DeviceDescriptor
std::vector< DynExpInstr::LockinAmplifierDefs::LockinSample > GetAcquiredData() const
void SetDemodFilterOrderUnsafe(uint8_t Demodulator, uint8_t FilterOrder) const
bool IsConnectedChild() const noexcept override final
Determines the connection status of the hardware interface.
std::string SignalInputTypeToCmdStr(SignalInputType SignalInput) const
void ConfigureInputUnsafe(SignalInputType SignalInput, uint8_t Demodulator) const
uint8_t GetDemodFilterOrderUnsafe(uint8_t Demodulator) const
void StartAcquisitionUnsafe(uint8_t Demodulator, size_t NumSamples, size_t NumRuns, bool AverageRuns) const
void SetInputRange(SignalInputType SignalInput, double InputRange) const
bool HasFinishedAcquisition() const
void WriteIntUnsafe(const std::string &Path, long long Value) const
void SetEnabled(uint8_t Demodulator, bool Enabled) const
void StopAcquisition() const
static constexpr auto HardwareOperationTimeout
Default timeout used to lock the mutex provided by the base class Util::ILockable to synchronize acce...
void ThrowExceptionUnsafe(std::exception_ptr Exception) const
Stores Exception in LastException, wraps it in a Util::ForwardedException and throws the wrapped exce...
auto GetExceptionUnsafe() const
Getter for LastException.
ParamsConstTypeSyncPtrType GetParams(const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
Locks the mutex of the parameter class instance Params assigned to this Object instance and returns a...
Refer to ParamsBase::dispatch_tag.
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Thrown when a list is expected to contain entries and when a query results in an empty answer or an e...
LockType AcquireLock(const std::chrono::milliseconds Timeout=DefaultTimeout) const
Locks the internal mutex. Blocks until the mutex is locked or until the timeout duration is exceeded.
An invalid argument like a null pointer has been passed to a function.
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Thrown when a requested ressource does not exist.
Thrown when a numeric operation would result in an overflow (e.g. due to incompatible data types)
DynExp's hardware namespace contains the implementation of DynExp hardware adapters which extend DynE...
TriggerEdgeType
Type to determine at which edge of a trigger signal to trigger. Not a strongly-typed enum to allow us...
@ Rise
Trigger on rising edge.
@ Fall
Trigger on falling edge.
TriggerModeType
Type to determine the trigger mode. Not a strongly-typed enum to allow using the enumeration in a Dyn...
@ ExternSingle
Run once after an external trigger signal has been detected.
@ Continuous
Run continuously disabling the trigger.
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.
void ForwardException(std::exception_ptr e)
Wraps the exception passed to the function in a ForwardedException and throws the ForwardedException....
std::string ToLower(std::string_view Str)
Transforms a string into lower case.
Accumulates include statements to provide a precompiled header.