13 PVCamSyms::int16 NumberOfCameras = 0;
14 if (PVCamSyms::pl_cam_get_total(&NumberOfCameras) != PVCamSyms::PV_OK)
15 throw PVCamException(
"Error enumerating PVCAM cameras.", PVCamSyms::pl_error_code());
17 std::vector<std::string> DeviceDescriptors;
18 for (decltype(NumberOfCameras) i = 0; i < NumberOfCameras; ++i)
23 if (PVCamSyms::pl_cam_get_name(i,
CameraName.data()) != PVCamSyms::PV_OK)
24 throw PVCamException(
"Error obtaining a PVCAM camera's name.", PVCamSyms::pl_error_code());
27 DeviceDescriptors.emplace_back(std::move(
CameraName));
30 return DeviceDescriptors;
37 std::find(PVCamDevices.cbegin(), PVCamDevices.cend(),
CameraName) == std::cend(PVCamDevices))
39 if (PVCamDevices.empty())
41 CameraName.SetTextList(std::move(PVCamDevices));
50 PVCamSyms::pl_pvcam_uninit();
55 return GetInstance().AcquireLock(
Timeout);
64 auto lock = Instance.
AcquireLock(std::chrono::milliseconds(100));
69 if (PVCamSyms::pl_pvcam_init() != PVCamSyms::PV_OK)
70 throw PVCamException(
"Error initializing PVCAM library.", PVCamSyms::pl_error_code());
110 for (
auto GainMode : SpeedMode.Gains)
111 Modes.emplace_back(SpeedMode.Port.second +
": " +
Util::ToStr(SpeedMode.ReadoutFrequency, 0) +
" MHz, "
194 using namespace PVCamSyms;
203 uns32 BytesRequired = 0;
204 auto CaptureRegion =
Region;
207 auto Result = pl_exp_setup_seq(
PVCamHandle, 1, 1, &CaptureRegion, TIMED_MODE,
static_cast<uns32
>(
ExposureTime.count()), &BytesRequired);
241 if (PVCamHardwareAdapterPtr)
247 auto DerivedParams = dynamic_Params_cast<PVCamHardwareAdapter>(
GetParams());
255 Region = { 0, 0, 1, 0, 0, 1 };
257 ColorMode = PVCamSyms::PL_COLOR_MODES::COLOR_NONE;
304 if (Result == PVCamSyms::PV_OK)
307 auto ErrorCode = PVCamSyms::pl_error_code();
310 std::string ErrorString;
311 ErrorString.resize(ERROR_MSG_LEN);
312 PVCamSyms::pl_error_message(ErrorCode, ErrorString.data());
332 using namespace PVCamSyms;
341 auto Result = pl_cam_open(TmpName.data(), &
PVCamHandle, OPEN_EXCLUSIVE);
355 int32 ColorModeAvlbl = 0;
356 Result = pl_get_param(
PVCamHandle, PARAM_COLOR_MODE, ATTR_AVAIL, &ColorModeAvlbl);
364 uns16 ExposueTimeMode = EXP_RES_ONE_MILLISEC;
365 Result = pl_set_param(
PVCamHandle, PARAM_EXP_RES_INDEX, &ExposueTimeMode);
384 auto Result = PVCamSyms::pl_cam_deregister_callback(
PVCamHandle, PVCamSyms::PL_CALLBACK_EOF);
401 using namespace PVCamSyms;
404 auto Result = pl_get_param(
PVCamHandle, ParamID, ATTR_COUNT, &Count);
410 for (decltype(Count) i = 0; i < Count; ++i)
414 Result = pl_enum_str_length(
PVCamHandle, ParamID, i, &StrLength);
418 Name.resize(StrLength);
422 Result = pl_get_enum_param(
PVCamHandle, ParamID, i, &Value,
Name.data(), StrLength);
425 PVCamEnumVector.emplace_back(Value, std::move(
Name));
428 return PVCamEnumVector;
433 using namespace PVCamSyms;
440 for (
auto& Port : Ports)
443 auto Result = pl_set_param(
PVCamHandle, PARAM_READOUT_PORT, &Port.first);
448 Result = pl_get_param(
PVCamHandle, PARAM_SPDTAB_INDEX, ATTR_COUNT, &SpeedCount);
452 for (int16 i = 0; i < Util::NumToT<int16>(SpeedCount); ++i)
457 Result = pl_set_param(
PVCamHandle, PARAM_SPDTAB_INDEX, &Tmpi);
462 Result = pl_get_param(
PVCamHandle, PARAM_PIX_TIME, ATTR_CURRENT, &PixelTime);
466 int16 GainMin, GainMax, GainIncrement;
467 Result = pl_get_param(
PVCamHandle, PARAM_GAIN_INDEX, ATTR_MIN, &GainMin);
469 Result = pl_get_param(
PVCamHandle, PARAM_GAIN_INDEX, ATTR_MAX, &GainMax);
471 Result = pl_get_param(
PVCamHandle, PARAM_GAIN_INDEX, ATTR_INCREMENT, &GainIncrement);
476 for (
auto Gain = GainMin; Gain <= GainMax; Gain += GainIncrement)
480 Result = pl_set_param(
PVCamHandle, PARAM_GAIN_INDEX, &TmpGain);
490 if (PVCamReadoutOption.
Gains.empty())
492 "The gain list of a speed table's entry of the selected PVCam camera is empty.")));
504 using namespace PVCamSyms;
509 decltype(ID) CurrentIndex = 0;
512 for (
auto GainMode : SpeedMode.Gains)
514 if (ID == CurrentIndex)
517 auto PortID = SpeedMode.Port.first;
518 auto Result = pl_set_param(
PVCamHandle, PARAM_READOUT_PORT, &PortID);
523 auto SpeedIndex = SpeedMode.SpeedIndex;
524 Result = pl_set_param(
PVCamHandle, PARAM_SPDTAB_INDEX, &SpeedIndex);
528 auto GainIndex = GainMode.GainIndex;
529 Result = pl_set_param(
PVCamHandle, PARAM_GAIN_INDEX, &GainIndex);
548 PVCamSyms::uns32 BytesRequired = 0;
549 auto CaptureRegion =
Region;
552 auto Result = pl_exp_setup_cont(
PVCamHandle, 1, &CaptureRegion, PVCamSyms::TIMED_MODE,
553 static_cast<PVCamSyms::uns32
>(
ExposureTime.count()), &BytesRequired, PVCamSyms::CIRC_OVERWRITE);
572 auto Result = PVCamSyms::pl_exp_stop_cont(
PVCamHandle, PVCamSyms::CCS_CLEAR);
576 auto Result = PVCamSyms::pl_exp_abort(
PVCamHandle, PVCamSyms::CCS_CLEAR);
584 using namespace PVCamSyms;
586 ulong64 IntMinExpTime, IntMaxExpTime;
587 auto Result = pl_get_param(
PVCamHandle, PARAM_EXPOSURE_TIME, ATTR_MIN, &IntMinExpTime);
589 Result = pl_get_param(
PVCamHandle, PARAM_EXPOSURE_TIME, ATTR_MAX, &IntMaxExpTime);
592 MinExpTime = std::chrono::milliseconds(IntMinExpTime);
593 MaxExpTime = std::chrono::milliseconds(IntMaxExpTime);
598 PVCamSyms::ulong64 CurrentExpTime;
599 auto Result = PVCamSyms::pl_get_param(
PVCamHandle, PARAM_EXPOSURE_TIME, PVCamSyms::ATTR_CURRENT, &CurrentExpTime);
602 ExposureTime = std::chrono::milliseconds(CurrentExpTime);
632 unsigned char* FrameAdr =
nullptr;
636 auto Result = PVCamSyms::pl_exp_get_latest_frame(
PVCamHandle,
reinterpret_cast<void**
>(&FrameAdr));
642 static std::chrono::time_point<std::chrono::system_clock> LastCall;
644 auto now = std::chrono::system_clock::now();
645 if (LastCall.time_since_epoch().count())
646 CurrentFPS = 1000.f / std::chrono::duration_cast<std::chrono::milliseconds>(now - LastCall).count();
Implementation of a hardware adapter to control Teledyne Photometrics PVCam hardware....
void ConfigureParamsImpl(dispatch_tag< HardwareAdapterParamsBase >) override final
Param< TextList > CameraName
Only one instance of this class is allowed for synchronizing calls to the PVCam library from any PVCa...
std::atomic< bool > IsInitialized
static LockType Lock(const std::chrono::milliseconds Timeout=std::chrono::milliseconds(100))
static PVCamInitializer & GetInstance(bool MayInit=false)
constexpr static auto BytesPerPixel() noexcept
void StartCapturing() const
static constexpr unsigned int NumFramesInBuffer
std::atomic< bool > PVCamHandleValid
void StopCapturing() const
void StopCapturingUnsafe() const
void ReserveMemory(const PVCamSyms::uns32 BytesRequired) const
PVCamHardwareAdapter(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
bool IsConnectedChild() const noexcept override final
Determines the connection status of the hardware interface.
decltype(PVCamSyms::rgn_type::p2) GetImageHeight() const
TimeType GetMaxExposureTime() const
Util::BlobDataType GetCurrentImage() const
std::vector< PVCamReadoutOptionType > CameraSpeedTable
PVCamEnumVectorType ReadPVCamEnumUnsafe(PVCamSyms::uns32 ParamID, std::string ParamName)
void CaptureSingle() const
decltype(PVCamSyms::rgn_type::s2) GetImageWidth() const
void ResetImpl(dispatch_tag< HardwareAdapterBase >) override final
virtual ~PVCamHardwareAdapter()
std::chrono::milliseconds TimeType
PVCamSyms::rgn_type Region
void SetCameraModeUnsafe(size_t ID) const
static void PV_DECL NewFrameCallback(PVCamSyms::FRAME_INFO *FrameInfo, void *PVCamHardwareAdapterPtr)
Util::BlobDataType GetCurrentImageCopy() const
void ReadExposureTimeUnsafe() const
TimeType GetExposureTime() const
void StartCapturingUnsafe() const
std::vector< PVCamEnumType > PVCamEnumVectorType
PVCamSyms::int16 PVCamHandle
void NewFrame(PVCamSyms::FRAME_INFO *FrameInfo) noexcept
bool IsReadyChild() const override final
Returns wheter this Object instance is ready (e.g. it is running or connected to a hardware device) a...
std::atomic< PVCamSyms::PL_COLOR_MODES > ColorMode
void EnsureReadyStateChild() override final
Ensures that this Object instance is ready by possibly starting its worker thread or by opening conne...
void CheckError(const PVCamSyms::rs_bool Result, bool OnlyLog=false, const std::source_location Location=std::source_location::current()) const
void ReadMinMaxExposureTimeUnsafe() const
constexpr static auto Name() noexcept
Util::BlobDataType CopiedImageData
bool IsOpened() const noexcept
std::atomic< CameraStateType > CameraState
Util::BlobDataType ImageData
TimeType GetMinExposureTime() const
void SetExposureTime(TimeType Time) const
void SetCameraMode(size_t ID) const
DynExpInstr::CameraData::CameraModesType GetCameraModes() const
std::atomic< PVCamSyms::int16 > BitDepth
void SetupSpeedTableUnsafe()
CapturingStateType
Type indicating whether the camera is currently capturing images.
@ CapturingSingle
The camera is caturing a single image and will stop afterwards.
@ CapturingContinuously
The camera is capturing one image after the other.
@ Stopped
The camera is not capturing.
std::vector< std::string > CameraModesType
List type containing strings of modes the camera can operate in.
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...
Data type which manages a binary large object. The reserved memory is freed upon destruction.
void Reserve(size_t Size)
Reserves Size bytes of memory freeing any previously reserved memory.
auto Size() const noexcept
Returns the size of the stored data in bytes.
void Reset()
Frees any reserved memory.
auto GetPtr() noexcept
Returns a pointer to the stored buffer.
void Assign(size_t Size, const DataType Data)
Copies Size bytes from Data to the buffer freeing any previously reserved memory.
Thrown when a list is expected to contain entries and when a query results in an empty answer or an e...
void Log(const std::string &Message, const ErrorType Type=ErrorType::Info, const size_t Line=0, const std::string &Function="", const std::string &File="", const int ErrorCode=0, const std::stacktrace &Trace={}) noexcept
Logs an event from information specified manually.
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
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...
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....
EventLogger & EventLog()
This function holds a static EventLogger instance and returns a reference to it. DynExp uses only one...
std::string TrimTrailingZeros(const std::string &Str)
Removes trailing zeros ('\0') from a string.
Accumulates include statements to provide a precompiled header.
std::vector< GainOptionType > Gains