12 unsigned int DeviceCount{};
13 auto Result = QutoolsTDCSyms::TDC_discover(&DeviceCount);
17 std::vector<std::string> DeviceDescriptors;
18 for (
decltype(DeviceCount) i = 0; i < DeviceCount; ++i)
20 std::string DeviceName;
21 DeviceName.resize(32);
23 Result = QutoolsTDCSyms::TDC_getDeviceInfo(i,
nullptr,
nullptr, DeviceName.data(),
nullptr);
28 DeviceDescriptors.emplace_back(std::move(DeviceName));
31 return DeviceDescriptors;
48 std::find(QutoolsTDCDevices.cbegin(), QutoolsTDCDevices.cend(),
DeviceDescriptor) == std::cend(QutoolsTDCDevices))
50 if (QutoolsTDCDevices.empty())
58 const std::chrono::milliseconds Timeout)
71 : Counts(std::move(Counts)), NumUpdates(NumUpdates)
155 QutoolsTDCSyms::TDC_SignalCond Conditioning,
bool UseRisingEdge,
double ThresholdInVolts)
const
164 QutoolsTDCSyms::Int32 ChannelMask)
const
254 return !Timestamps.empty() ? std::move(Timestamps.mapped()) : std::vector<QutoolsTDCHardwareAdapter::ValueType>();
274 QutoolsTDCSyms::Int32 NumUpdates{};
276 auto Result = QutoolsTDCSyms::TDC_getCoincCounters(Counts.data(), &NumUpdates);
359 if (Result == TDC_Ok)
362 std::string ErrorString(QutoolsTDCSyms::TDC_perror(Result));
374 QutoolsTDCSyms::Int32 TimestampBufferSize{};
375 bool UseRisingEdge{};
376 double ThresholdInVolts{};
377 std::chrono::milliseconds ExposureTime{};
381 auto DerivedParams = dynamic_Params_cast<QutoolsTDCHardwareAdapter>(
GetParams());
384 auto DeviceSerialIt = std::find(DeviceSerials.cbegin(), DeviceSerials.cend(), DerivedParams->DeviceDescriptor.Get());
385 DeviceNumber = std::distance(DeviceSerials.cbegin(), DeviceSerialIt);
389 std::string Serial = DeviceSerialIt == DeviceSerials.cend() ?
"< unknown >" : *DeviceSerialIt;
392 "The qutools TDC device with serial " + Serial +
" has not been found.")));
395 TimestampBufferSize = DerivedParams->DefaultTimestampBufferSize;
397 ThresholdInVolts = DerivedParams->DefaultThresholdInVolts;
398 ExposureTime = std::chrono::milliseconds(DerivedParams->DefaultExposureTime);
399 CoincidenceWindow =
ValueType(DerivedParams->DefaultCoincidenceWindow);
403 auto Result = QutoolsTDCSyms::TDC_connect(this->
DeviceNumber);
411 Result = QutoolsTDCSyms::TDC_getTimebase(&
Timebase);
416 Result = QutoolsTDCSyms::TDC_getTimestampBufferSize(&
BufferSize);
420#ifdef QUTOOLSQUTAG_VARIANT_S
440 auto Result = QutoolsTDCSyms::TDC_disconnect(
DeviceNumber);
447 auto Result = QutoolsTDCSyms::TDC_addressDevice(
DeviceNumber);
453 std::vector<QutoolsTDCSyms::Int64> Timestamps(
BufferSize);
454 std::vector<ChannelType> Channels(
BufferSize);
455 QutoolsTDCSyms::Int32 NumValid{};
461 auto Result = QutoolsTDCSyms::TDC_getLastTimestamps(
true, Timestamps.data(), Channels.data(), &NumValid);
465 if (Timestamps.size() != Channels.size() || NumValid < 0 || NumValid > Timestamps.size())
467 "Received invalid data from TDC_getLastTimestamps().")));
469 for (
size_t i = 0; i < NumValid; ++i)
476#ifdef QUTOOLSQUTAG_VARIANT_S
477 ChannelMask |=
static_cast<decltype(ChannelMask)
>(EnableStartChannel);
478 auto Result = QutoolsTDCSyms::TDC_enableChannels(ChannelMask);
480 auto Result = QutoolsTDCSyms::TDC_enableChannels(EnableStartChannel, ChannelMask);
489 QutoolsTDCSyms::Bln32 StartEnabled{};
490 QutoolsTDCSyms::Int32 ChannelMask{};
492#ifdef QUTOOLSQUTAG_VARIANT_S
493 auto Result = QutoolsTDCSyms::TDC_getChannelsEnabled(&ChannelMask);
494 StartEnabled = ChannelMask & 1;
496 auto Result = QutoolsTDCSyms::TDC_getChannelsEnabled(&StartEnabled, &ChannelMask);
500 return std::make_pair(
static_cast<bool>(StartEnabled), ChannelMask);
505 auto Result = QutoolsTDCSyms::TDC_setExposureTime(Util::NumToT<QutoolsTDCSyms::Int32>(ExposureTime.count()));
511 auto Result = QutoolsTDCSyms::TDC_setCoincidenceWindow(Util::NumToT<QutoolsTDCSyms::Int32>(CoincidenceWindow /
Timebase));
517#ifdef QUTOOLSQUTAG_VARIANT_S
519 "The quTAG Standard does not support setting the channel delay.")));
521 auto Result = QutoolsTDCSyms::TDC_setChannelDelay(Channel, Util::NumToT<QutoolsTDCSyms::Int32>(ChannelDelay.count()));
528 auto Result = QutoolsTDCSyms::TDC_setTimestampBufferSize(Size);
535 QutoolsTDCSyms::TDC_SignalCond Conditioning,
bool UseRisingEdge,
double ThresholdInVolts)
const
537 auto Result = QutoolsTDCSyms::TDC_configureSignalConditioning(Channel, Conditioning, UseRisingEdge, ThresholdInVolts);
542 QutoolsTDCSyms::TDC_FilterType FilterType, QutoolsTDCSyms::Int32 ChannelMask)
const
544 auto Result = QutoolsTDCSyms::TDC_configureFilter(Channel + 1, FilterType, ChannelMask);
546 if (Result == TDC_NotAvailable)
554 auto Result = QutoolsTDCSyms::TDC_enableHbt(Enable);
560 auto Result = QutoolsTDCSyms::TDC_setHbtInput(FirstChannel + 1, SecondChannel + 1);
566 auto Result = QutoolsTDCSyms::TDC_setHbtParams(Util::NumToT<QutoolsTDCSyms::Int32>(BinWidth /
Timebase), BinCount);
572 auto Result = QutoolsTDCSyms::TDC_resetHbtCorrelations();
578 QutoolsTDCSyms::Int64 TotalCount{}, LastCount{};
581 auto Result = QutoolsTDCSyms::TDC_getHbtEventCount(&TotalCount, &LastCount, &LastRate);
589 double IntegrationTime{};
591 auto Result = QutoolsTDCSyms::TDC_getHbtIntegrationTime(&IntegrationTime);
594 return std::chrono::microseconds(
static_cast<std::chrono::microseconds::rep
>(std::round(IntegrationTime * std::micro::den)));
599 auto HBTFunc = QutoolsTDCSyms::TDC_createHbtFunction();
605 auto Result = QutoolsTDCSyms::TDC_calcHbtG2(HBTFunc);
609 for (
decltype(HBTFunc->size) i = 0; i < HBTFunc->size; ++i)
610 HBTResult.emplace_back(HBTFunc->values[i], ((i - HBTFunc->indexOffset) *
Timebase * HBTFunc->binWidth).count() / std::pico::den);
612 QutoolsTDCSyms::TDC_releaseHbtFunction(HBTFunc);
620 QutoolsTDCSyms::TDC_releaseHbtFunction(HBTFunc);
HardwareAdapterBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a hardware adapter instance.
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.
void SetWarning(std::string Description, int ErrorCode) const
Setter for Object::Warning. Sets the warning by a description and an error code.
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...
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
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.
std::unique_lock< MutexType > LockType
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 requested feature is either under development and thus not implemented yet or when a sp...
Thrown when an argument passed to a function exceeds the valid range.
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.
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::chrono::duration< double, std::pico > picoseconds
Extends std::chrono by a duration data type for picoseconds.
std::string TrimTrailingZeros(const std::string &Str)
Removes trailing zeros ('\0') from a string.
std::vector< std::pair< TextType, ValueType > > TextValueListType
Type of a list containing key-value pairs where key is a text of type Util::TextType.
Accumulates include statements to provide a precompiled header.