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;
37 {
"Trigger on rising edge.", EdgeType::RisingEdge },
38 {
"Trigger on falling edge.", EdgeType::FallingEdge }
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
182 if (FirstChannel >= 31 || SecondChannel >= 31)
184 "Specify valid channels between 0 and 31.")));
254 return !Timestamps.empty() ? std::move(Timestamps.mapped()) : std::vector<QutoolsTDCHardwareAdapter::ValueType>();
273 std::vector<QutoolsTDCSyms::Int32> Counts(59);
274 QutoolsTDCSyms::Int32 NumUpdates{};
276 auto Result = QutoolsTDCSyms::TDC_getCoincCounters(Counts.data(), &NumUpdates);
290 if (Channel < 0 || Channel >= 59)
292 "Specify a channel between 0 and 59.")));
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;
396 UseRisingEdge = DerivedParams->DefaultTriggerEdge == QutoolsTDCHardwareAdapterParams::EdgeType::RisingEdge;
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);
436 auto Result = QutoolsTDCSyms::TDC_disconnect(
DeviceNumber);
443 auto Result = QutoolsTDCSyms::TDC_addressDevice(
DeviceNumber);
449 std::vector<QutoolsTDCSyms::Int64> Timestamps(
BufferSize);
450 std::vector<ChannelType> Channels(
BufferSize);
451 QutoolsTDCSyms::Int32 NumValid{};
457 auto Result = QutoolsTDCSyms::TDC_getLastTimestamps(
true, Timestamps.data(), Channels.data(), &NumValid);
461 if (Timestamps.size() != Channels.size() || NumValid < 0 || NumValid > Timestamps.size())
463 "Received invalid data from TDC_getLastTimestamps().")));
465 for (
size_t i = 0; i < NumValid; ++i)
472 auto Result = QutoolsTDCSyms::TDC_enableChannels(EnableStartChannel, ChannelMask);
480 QutoolsTDCSyms::Bln32 StartEnabled{};
481 QutoolsTDCSyms::Int32 ChannelMask{};
483 auto Result = QutoolsTDCSyms::TDC_getChannelsEnabled(&StartEnabled, &ChannelMask);
486 return std::make_pair(
static_cast<bool>(StartEnabled), ChannelMask);
491 auto Result = QutoolsTDCSyms::TDC_setExposureTime(Util::NumToT<QutoolsTDCSyms::Int32>(ExposureTime.count()));
497 auto Result = QutoolsTDCSyms::TDC_setCoincidenceWindow(Util::NumToT<QutoolsTDCSyms::Int32>(CoincidenceWindow /
Timebase));
503 auto Result = QutoolsTDCSyms::TDC_setChannelDelay(Channel, Util::NumToT<QutoolsTDCSyms::Int32>(ChannelDelay.count()));
509 auto Result = QutoolsTDCSyms::TDC_setTimestampBufferSize(Size);
516 QutoolsTDCSyms::TDC_SignalCond Conditioning,
bool UseRisingEdge,
double ThresholdInVolts)
const
518 auto Result = QutoolsTDCSyms::TDC_configureSignalConditioning(Channel, Conditioning, UseRisingEdge, ThresholdInVolts);
523 QutoolsTDCSyms::TDC_FilterType FilterType, QutoolsTDCSyms::Int32 ChannelMask)
const
525 auto Result = QutoolsTDCSyms::TDC_configureFilter(Channel + 1, FilterType, ChannelMask);
531 auto Result = QutoolsTDCSyms::TDC_enableHbt(Enable);
537 auto Result = QutoolsTDCSyms::TDC_setHbtInput(FirstChannel + 1, SecondChannel + 1);
543 auto Result = QutoolsTDCSyms::TDC_setHbtParams(Util::NumToT<QutoolsTDCSyms::Int32>(BinWidth /
Timebase), BinCount);
549 auto Result = QutoolsTDCSyms::TDC_resetHbtCorrelations();
555 QutoolsTDCSyms::Int64 TotalCount{}, LastCount{};
558 auto Result = QutoolsTDCSyms::TDC_getHbtEventCount(&TotalCount, &LastCount, &LastRate);
566 double IntegrationTime{};
568 auto Result = QutoolsTDCSyms::TDC_getHbtIntegrationTime(&IntegrationTime);
571 return std::chrono::microseconds(
static_cast<std::chrono::microseconds::rep
>(std::round(IntegrationTime * std::micro::den)));
576 auto HBTFunc = QutoolsTDCSyms::TDC_createHbtFunction();
582 auto Result = QutoolsTDCSyms::TDC_calcHbtG2(HBTFunc);
586 for (decltype(HBTFunc->size) i = 0; i < HBTFunc->size; ++i)
587 HBTResult.emplace_back(HBTFunc->values[i], ((i - HBTFunc->indexOffset) *
Timebase * HBTFunc->binWidth).count() / std::pico::den);
589 QutoolsTDCSyms::TDC_releaseHbtFunction(HBTFunc);
597 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.
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 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.