From c7d7dbb3fbcde53e09312fb1d34f5aac5fb199f1 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Thu, 22 Jun 2023 12:45:12 +0200 Subject: [PATCH 01/43] First prototype implementation Changes: - Image snapping - Live stream from camera - Device adapter base - Camera listing - Property page (read only) - SDK wrapper and lib loader Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 537 ++++ .../AlliedVisionCamera/AlliedVisionCamera.h | 132 + .../AlliedVisionCamera.vcxproj | 183 ++ .../AlliedVisionCamera.vcxproj.filters | 54 + .../AlliedVisionCamera/SDK/Loader/Constants.h | 27 + .../SDK/Loader/LibLoader.cpp | 81 + .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 143 ++ .../AlliedVisionCamera/SDK/VmbC/VmbC.h | 2182 +++++++++++++++++ .../SDK/VmbC/VmbCTypeDefinitions.h | 610 +++++ .../SDK/VmbC/VmbCommonTypes.h | 444 ++++ .../SDK/VmbC/VmbConstants.h | 85 + .../SDK/VmbImageTransform/VmbTransform.h | 336 +++ .../SDK/VmbImageTransform/VmbTransformTypes.h | 1018 ++++++++ micromanager.sln | 6 + 14 files changed, 5838 insertions(+) create mode 100644 DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp create mode 100644 DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h create mode 100644 DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj create mode 100644 DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbC.h create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCTypeDefinitions.h create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCommonTypes.h create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbConstants.h create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransform.h create mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransformTypes.h diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp new file mode 100644 index 000000000..3df9abb8e --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -0,0 +1,537 @@ +/*============================================================================= + Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ +#include "AlliedVisionCamera.h" + +#include + +#include +#include +#include +#include + +#include "ModuleInterface.h" +#include "VmbC/VmbC.h" + +/////////////////////////////////////////////////////////////////////////////// +// Exported MMDevice API +/////////////////////////////////////////////////////////////////////////////// +MODULE_API void InitializeModuleData() { + g_api = std::make_unique(); + assert(g_api != nullptr); + auto err = g_api->VmbStartup_t(nullptr); + assert(err == VmbErrorSuccess); + + err = AlliedVisionCamera::getCamerasList(); + if (err != VmbErrorSuccess) { + // TODO Handle error + } + + g_api->VmbShutdown_t(); +} + +MODULE_API MM::Device* CreateDevice(const char* deviceName) { + if (deviceName == nullptr) { + return nullptr; + } + + return new AlliedVisionCamera(deviceName); +} + +MODULE_API void DeleteDevice(MM::Device* pDevice) { delete pDevice; } + +/////////////////////////////////////////////////////////////////////////////// +// AlliedVisionCamera +/////////////////////////////////////////////////////////////////////////////// + +AlliedVisionCamera::~AlliedVisionCamera() { + m_handle = nullptr; + + for (size_t i = 0; i < MAX_FRAMES; i++) { + delete[] m_buffer[i]; + } +} + +AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) + : CCameraBase(), + m_handle{nullptr}, + m_cameraName{deviceName}, + m_frames{}, + m_buffer{}, + m_bufferSize{0}, + m_imageWidth{}, + m_imageHeight{}, + m_isAcquisitionRunning{false} { + // [Rule] Create properties here (pre-init only) + InitializeDefaultErrorMessages(); + setApiErrorMessages(); +} + +int AlliedVisionCamera::Initialize() { + // [Rule] Implement communication here + LogMessage("Initializing Vimba X API..."); + VmbError_t err = g_api->VmbStartup_t(nullptr); + if (err != VmbErrorSuccess) { + return err; + } + + VmbVersionInfo_t ver; + err = g_api->VmbVersionQuery_t(&ver, sizeof(ver)); + if (err != VmbErrorSuccess) { + return err; + } + std::string v = std::to_string(ver.major) + "." + std::to_string(ver.minor) + + "." + std::to_string(ver.patch); + LogMessage("SDK version:" + v); + + LogMessage("Opening camera: " + m_cameraName); + err = g_api->VmbCameraOpen_t(m_cameraName.c_str(), + VmbAccessModeType::VmbAccessModeFull, &m_handle); + if (err != VmbErrorSuccess || m_handle == nullptr) { + return err; + } + + // Init properties and buffer + setupProperties(); + resizeImageBuffer(); + + return DEVICE_OK; +} + +int AlliedVisionCamera::Shutdown() { + // [Rule] Implement disconnection here + LogMessage("Shutting down camera: " + m_cameraName); + if (m_handle != nullptr) { + VmbError_t err = g_api->VmbCameraClose_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + } + + g_api->VmbShutdown_t(); + return DEVICE_OK; +} + +const unsigned char* AlliedVisionCamera::GetImageBuffer() { + return reinterpret_cast(m_buffer[0]); +} + +unsigned AlliedVisionCamera::GetImageWidth() const { return m_imageWidth; } + +unsigned AlliedVisionCamera::GetImageHeight() const { return m_imageHeight; } + +unsigned AlliedVisionCamera::GetImageBytesPerPixel() const { + // TODO implement + return 1; +} + +int AlliedVisionCamera::SnapImage() { + if (m_isAcquisitionRunning) { + return DEVICE_CAMERA_BUSY_ACQUIRING; + } + resizeImageBuffer(); + + VmbFrame_t frame; + frame.buffer = m_buffer[0]; + frame.bufferSize = m_bufferSize; + + VmbError_t err = + g_api->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureStart_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureFrameWait_t(m_handle, &frame, 3000); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureEnd_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureQueueFlush_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbFrameRevokeAll_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + return err; +} + +long AlliedVisionCamera::GetImageBufferSize() const { return m_bufferSize; } +unsigned AlliedVisionCamera::GetBitDepth() const { + // TODO implement + return 8; +} +int AlliedVisionCamera::GetBinning() const { + // TODO implement + return 1; +} +int AlliedVisionCamera::SetBinning(int binSize) { + // TODO implement + return VmbErrorSuccess; +} +void AlliedVisionCamera::SetExposure(double exp_ms) { + // TODO implement +} +double AlliedVisionCamera::GetExposure() const { + // TODO implement + return 8058.96; +} +int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, + unsigned ySize) { + // TODO implement + return VmbErrorSuccess; +} +int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, + unsigned& ySize) { + // TODO implement + return VmbErrorSuccess; +} +int AlliedVisionCamera::ClearROI() { + // TODO implement + return 0; +} +int AlliedVisionCamera::IsExposureSequenceable(bool& isSequenceable) const { + // TODO implement + return VmbErrorSuccess; +} +void AlliedVisionCamera::GetName(char* name) const { + CDeviceUtils::CopyLimitedString(name, m_cameraName.c_str()); +} +bool AlliedVisionCamera::IsCapturing() { return m_isAcquisitionRunning; } + +void AlliedVisionCamera::setApiErrorMessages() { + SetErrorText(VmbErrorApiNotStarted, "Vimba X API not started"); + SetErrorText(VmbErrorNotFound, "Device cannot be found"); + SetErrorText(VmbErrorDeviceNotOpen, "Device cannot be opened"); + SetErrorText(VmbErrorBadParameter, + "Invalid parameter passed to the function"); + SetErrorText(VmbErrorNotImplemented, "Feature not implemented"); + SetErrorText(VmbErrorNotSupported, "Feature not supported"); + SetErrorText(VmbErrorUnknown, "Unknown error"); +} + +VmbError_t AlliedVisionCamera::getCamerasList() { + VmbUint32_t camNum; + + // Get the number of connected cameras first + VmbError_t err = g_api->VmbCamerasList_t(nullptr, 0, &camNum, 0); + if (VmbErrorSuccess == err) { + VmbCameraInfo_t* camInfo = new VmbCameraInfo_t[camNum]; + + // Get the cameras + err = g_api->VmbCamerasList_t(camInfo, camNum, &camNum, sizeof *camInfo); + + if (err == VmbErrorSuccess) { + for (VmbUint32_t i = 0; i < camNum; ++i) { + RegisterDevice(camInfo[i].cameraIdString, MM::CameraDevice, + camInfo[i].cameraName); + } + } + + delete[] camInfo; + } + + return err; +} + +VmbError_t AlliedVisionCamera::resizeImageBuffer() { + auto err = g_api->VmbFeatureIntGet_t(m_handle, "Width", &m_imageWidth); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbFeatureIntGet_t(m_handle, "Height", &m_imageHeight); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); + if (err != VmbErrorSuccess) { + return err; + } + + for (size_t i = 0; i < MAX_FRAMES; i++) { + delete[] m_buffer[i]; + m_buffer[i] = new VmbUint8_t[m_bufferSize]; + } + + return VmbErrorSuccess; +} + +int AlliedVisionCamera::OnPixelTypeChanged(MM::PropertyBase* pProp, + MM::ActionType eAct) { + // TODO implement + resizeImageBuffer(); + return 0; +} + +int AlliedVisionCamera::OnBinningChanged(MM::PropertyBase* pProp, + MM::ActionType eAct) { + // TODO implement + resizeImageBuffer(); + return 0; +} + +VmbError_t AlliedVisionCamera::createPropertyFromFeature( + const VmbFeatureInfo_t* feature) { + // TODO + // Implemnet onProperyChanged for some properties and buffer resize + // Implement readOnly/WriteOnly reading + if (feature == nullptr) { + return VmbErrorInvalidValue; + } + + VmbError_t err = VmbErrorSuccess; + switch (feature->featureDataType) { + case VmbFeatureDataBool: { + VmbBool_t value; + err = g_api->VmbFeatureBoolGet_t(m_handle, feature->name, &value); + if (VmbErrorSuccess == err) { + CreateIntegerProperty(feature->name, value, true, nullptr); + } + break; + } + case VmbFeatureDataEnum: { + char const* value = nullptr; + err = g_api->VmbFeatureEnumGet_t(m_handle, feature->name, &value); + if (VmbErrorSuccess == err) { + CreateStringProperty(feature->name, value, true, nullptr); + } + break; + } + case VmbFeatureDataFloat: { + double value; + err = g_api->VmbFeatureFloatGet_t(m_handle, feature->name, &value); + if (err == VmbErrorSuccess) { + CreateFloatProperty(feature->name, value, true, nullptr); + } + break; + } + case VmbFeatureDataInt: { + VmbInt64_t value; + err = g_api->VmbFeatureIntGet_t(m_handle, feature->name, &value); + if (err == VmbErrorSuccess) { + CreateIntegerProperty(feature->name, value, true, nullptr); + } + break; + } + case VmbFeatureDataString: { + VmbUint32_t size = 0; + err = g_api->VmbFeatureStringGet_t(m_handle, feature->name, nullptr, 0, + &size); + if (VmbErrorSuccess == err && size > 0) { + std::shared_ptr buff = std::shared_ptr(new char[size]); + err = g_api->VmbFeatureStringGet_t(m_handle, feature->name, buff.get(), + size, &size); + if (VmbErrorSuccess == err) { + CreateStringProperty(feature->name, buff.get(), true, nullptr); + } + } + break; + } + case VmbFeatureDataCommand: + case VmbFeatureDataUnknown: + case VmbFeatureDataRaw: + case VmbFeatureDataNone: + default: + err = VmbErrorFeaturesUnavailable; + break; + } + + return err; +} + +VmbError_t AlliedVisionCamera::setupProperties() { + VmbUint32_t featureCount = 0; + VmbError_t err = g_api->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, + sizeof(VmbFeatureInfo_t)); + if (err != VmbErrorSuccess || !featureCount) { + return err; + } + + std::shared_ptr features = + std::shared_ptr(new VmbFeatureInfo_t[featureCount]); + + err = g_api->VmbFeaturesList_t(m_handle, features.get(), featureCount, + &featureCount, sizeof(VmbFeatureInfo_t)); + + if (err != VmbErrorSuccess) { + return err; + } + + const VmbFeatureInfo_t* end = features.get() + featureCount; + for (VmbFeatureInfo_t* feature = features.get(); feature != end; ++feature) { + std::stringstream ss; + ss << "/// Feature Name: " << feature->name << "\n"; + ss << "/// Display Name: " << feature->displayName << "\n"; + ss << "/// Tooltip: " << feature->tooltip << "\n"; + ss << "/// Description: " << feature->description << "\n"; + ss << "/// SNFC Namespace: " << feature->sfncNamespace << "\n"; + LogMessage(ss.str().c_str()); + createPropertyFromFeature(feature); + } +} + +int AlliedVisionCamera::StartSequenceAcquisition(long numImages, + double interval_ms, + bool stopOnOverflow) { + if (m_isAcquisitionRunning) { + return DEVICE_CAMERA_BUSY_ACQUIRING; + } + + int err = GetCoreCallback()->PrepareForAcq(this); + if (err != DEVICE_OK) { + return err; + } + + err = resizeImageBuffer(); + if (err != VmbErrorSuccess) { + return err; + } + + for (size_t i = 0; i < MAX_FRAMES; i++) { + // Setup frame with buffer + m_frames[i].buffer = new uint8_t[m_bufferSize]; + m_frames[i].bufferSize = m_bufferSize; + m_frames[i].context[0] = this; //(i); //VmbFrameAnnounce_t(m_handle, &(m_frames[i]), sizeof(VmbFrame_t)); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureFrameQueue_t( + m_handle, &(m_frames[i]), + [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, + VmbFrame_t* frame) { + reinterpret_cast(frame->context[0]) + ->insertFrame(frame); + }); + if (err != VmbErrorSuccess) { + return err; + } + } + + err = g_api->VmbCaptureStart_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); + if (err != VmbErrorSuccess) { + return err; + } + + m_isAcquisitionRunning = true; + return err; +} + +int AlliedVisionCamera::StartSequenceAcquisition(double interval_ms) { + return StartSequenceAcquisition(LONG_MAX, interval_ms, true); +} +int AlliedVisionCamera::StopSequenceAcquisition() { + if (m_isAcquisitionRunning) { + auto err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); + if (err != VmbErrorSuccess) { + return err; + } + + m_isAcquisitionRunning = false; + } + + auto err = g_api->VmbCaptureEnd_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureQueueFlush_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbFrameRevokeAll_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + return err; +} + +void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { + if (frame != nullptr && frame->receiveStatus == VmbFrameStatusComplete) { + VmbUint8_t* buffer = reinterpret_cast(frame->buffer); + + // TODO implement metadata + Metadata md; + md.put("Camera", m_cameraName); + + // TODO implement parameters + auto err = GetCoreCallback()->InsertImage(this, buffer, m_imageWidth, + m_imageHeight, 1, 1, + md.Serialize().c_str()); + + if (err == DEVICE_BUFFER_OVERFLOW) { + GetCoreCallback()->ClearImageBuffer(this); + // TODO implement parameters + err = GetCoreCallback()->InsertImage(this, buffer, frame->width, + frame->height, 1, 1, + md.Serialize().c_str(), false); + } + + if (m_isAcquisitionRunning) { + g_api->VmbCaptureFrameQueue_t( + m_handle, frame, + [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, + VmbFrame_t* frame) { + reinterpret_cast(frame->context[0]) + ->insertFrame(frame); + }); + } + } +} \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h new file mode 100644 index 000000000..a6b208606 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -0,0 +1,132 @@ +/*============================================================================= + Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ +#ifndef ALLIEDVISIONCAMERA_H +#define ALLIEDVISIONCAMERA_H + +#include + +#include "DeviceBase.h" +#include "Loader/LibLoader.h" + +/** + * @brief Pointer to the Vimba API +*/ +static std::unique_ptr g_api; + +/** + * @brief Main Allied Vision Camera class +*/ +class AlliedVisionCamera : public CCameraBase { + // PUBLIC + public: + /** + * @brief Contructor of Allied Vision Camera + * @param[in] deviceName Device name + */ + AlliedVisionCamera(const char* deviceName); + /** + * @brief Allied Vision Camera destructor + */ + ~AlliedVisionCamera(); + + /** + * @brief Get connected camera list + * @return VmbError_t + */ + static VmbError_t getCamerasList(); + + // API Methods + int Initialize() override; + int Shutdown() override; + const unsigned char* GetImageBuffer() override; + unsigned GetImageWidth() const override; + unsigned GetImageHeight() const override; + unsigned GetImageBytesPerPixel() const override; + int SnapImage() override; + long GetImageBufferSize() const override; + unsigned GetBitDepth() const override; + int GetBinning() const override; + int SetBinning(int binSize) override; + void SetExposure(double exp_ms) override; + double GetExposure() const override; + int SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) override; + int GetROI(unsigned& x, unsigned& y, unsigned& xSize, + unsigned& ySize) override; + int ClearROI() override; + int IsExposureSequenceable(bool& isSequenceable) const override; + void GetName(char* name) const override; + int StartSequenceAcquisition(double interval_ms) override; + int StartSequenceAcquisition(long numImages, double interval_ms, + bool stopOnOverflow) override; + int StopSequenceAcquisition() override; + bool IsCapturing() override; + + // Callbacks + int OnPixelTypeChanged(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnBinningChanged(MM::PropertyBase* pProp, MM::ActionType eAct); + + // Static variables + static constexpr const VmbUint8_t MAX_FRAMES = 7; + + // PRIVATE + private: + /** + * @brief Setup error messages for Vimba API + */ + void setApiErrorMessages(); + + /** + * @brief Resize all buffers for image frames + * @return VmbError_t + */ + VmbError_t resizeImageBuffer(); + + /** + * @brief Setup uManager properties from Vimba features + * @return VmbError_t + */ + VmbError_t setupProperties(); + + /** + * @brief Helper method to create single uManager property from Vimba feature + * @param[in] feature Pointer to the Vimba feature + * @return VmbError_t + */ + VmbError_t createPropertyFromFeature(const VmbFeatureInfo_t* feature); + + /** + * @brief Insert ready frame to the uManager + * @param[in] frame Pointer to the frame + */ + void insertFrame(VmbFrame_t* frame); + + // MEMBERS + VmbHandle_t m_handle; // m_frames; // m_buffer; // + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + {b8c95f39-54bf-40a9-807b-598df2821d55} + + + + 16.0 + Win32Proj + {12e75cb0-4b48-4d7c-bb26-d928f18488c2} + AlliedVisionCamera + 10.0 + + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + C:\Program Files\Micro-Manager-2.0 + + + false + + + + Level3 + true + WIN32;_DEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + + + + + Level3 + true + true + true + WIN32;NDEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + + + + + true + _DEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + $(ProjectDir)SDK;%(AdditionalIncludeDirectories) + + + Windows + true + false + + + + + true + true + true + NDEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + $(ProjectDir)SDK;%(AdditionalIncludeDirectories) + + + Windows + true + true + true + false + + + + + + \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters new file mode 100644 index 000000000..03328d086 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters @@ -0,0 +1,54 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h new file mode 100644 index 000000000..929d01061 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h @@ -0,0 +1,27 @@ +/*============================================================================= + Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ +#ifndef CONSTANTS_H +#define CONSTANTS_H + +static constexpr const char* VIMBA_X_ENV_VAR = "VIMBA_X_HOME"; // + +#include + +#include "VmbC/VmbC.h" + +/** + * @brief Wrapper for single Windows process + */ +class ProcWrapper { + // PUBLIC + public: + /** + * @brief Constructor of wrapper + * @param[in] funPtr Pointer to the process + */ + explicit ProcWrapper(FARPROC funPtr) : m_funPtr(funPtr) {} + + /** + * @brief Operator () overload to call function + */ + template >> + operator T*() const { + return reinterpret_cast(m_funPtr); + } + // PRIVATE + private: + FARPROC m_funPtr; // +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief Timeout parameter signaling a blocking call. + */ +#define VMBINFINITE 0xFFFFFFFF + +/** + * \brief Define for the handle to use for accessing the Vmb system features cast to a given type + * + * Note: The primary purpose of this macro is the use in the VmbC sources. + * API users should use ::gVmbHandle instead. + */ +#define VMB_API_HANDLE(typeName) ((typeName)((((VmbUint64_t)1) << (VmbUint64_t)(sizeof(VmbHandle_t) * 8 - 4)) | ((VmbUint64_t) 1))) + +/** + * \brief Constant for the Vmb handle to be able to access Vmb system features. + */ +static const VmbHandle_t gVmbHandle = VMB_API_HANDLE(VmbHandle_t); + +//===== FUNCTION PROTOTYPES =================================================== + +/** + * \defgroup Functions Vmb C API Functions + * \{ + */ + +/** + * \name API Version + * \defgroup Version API Version + * \{ + */ + +/** + * \brief Retrieve the version number of VmbC. + * + * This function can be called at anytime, even before the API is + * initialized. All other version numbers may be queried via feature access. + * + * \param[out] versionInfo Pointer to the struct where version information resides + * \param[in] sizeofVersionInfo Size of structure in bytes + * + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback. + * + * \retval ::VmbErrorStructSize The given struct size is not valid for this version of the API + * + * \retval ::VmbErrorBadParameter \p versionInfo is null. + * + */ +IMEXPORTC VmbError_t VMB_CALL VmbVersionQuery ( VmbVersionInfo_t* versionInfo, + VmbUint32_t sizeofVersionInfo ); +/** + * \} + */ + +/** + * \name API Initialization + * \{ + * \defgroup Init API Initialization + * \{ + */ + +/** + * \brief Initializes the VmbC API. + * + * Note: This function must be called before any VmbC function other than ::VmbVersionQuery() is run. + * + * \param[in] pathConfiguration A string containing a semicolon (Windows) or colon (other os) separated list of paths. The paths contain directories to search for .cti files, + * paths to .cti files and optionally the path to a configuration xml file. If null is passed the parameter is the cti files found in the paths + * the GENICAM_GENTL{32|64}_PATH environment variable are considered + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorAlready This function was called before and call to ::VmbShutdown has been executed on a non-callback thread + * + * \retval ::VmbErrorInvalidCall If called from a callback or ::VmbShutdown is currently running + * + * \retval ::VmbErrorXml If parsing the settings xml is unsuccessful; a missing default xml file does not result in this error. + * + * \retval ::VmbErrorTLNotFound A transport layer that was marked as required was not found. + * + * \retval ::VmbErrorNoTL No transport layer was found on the system; note that some of the transport layers may have been filtered out via the settings file. + * + * \retval ::VmbErrorIO A log file should be written according to the settings xml file, but this log file could not be opened. + * + * \retval ::VmbErrorBadParameter \p pathConfiguration contains only separator and whitespace chars. + * + */ +IMEXPORTC VmbError_t VMB_CALL VmbStartup (const VmbFilePathChar_t* pathConfiguration); + +/** + * \brief Perform a shutdown of the API. + * + * This frees some resources and deallocates all physical resources if applicable. + * + * The call is silently ignored, if executed from a callback. + * + */ +IMEXPORTC void VMB_CALL VmbShutdown ( void ); + +/** + * \} \} + */ + +/** + * \name Camera Enumeration & Information + * \{ + * \defgroup CameraInfo Camera Enumeration & Information + * \{ + */ + +/** + * List all the cameras that are currently visible to the API. + * + * Note: This function is usually called twice: once with an empty array to query the length + * of the list, and then again with an array of the correct length. + * If camera lists change between the calls, numFound may deviate from the query return. + * + * \param[in,out] cameraInfo Array of VmbCameraInfo_t, allocated by the caller. + * The camera list is copied here. May be null. + * + * \param[in] listLength Number of entries in the callers cameraInfo array. + * + * \param[in,out] numFound Number of cameras found. Can be more than listLength. + * + * \param[in] sizeofCameraInfo Size of one VmbCameraInfo_t entry (if \p cameraInfo is null, this parameter is ignored). + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p numFound is null + * + * \retval ::VmbErrorStructSize The given struct size is not valid for this API version and \p cameraInfo is not null + * + * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries + */ +IMEXPORTC VmbError_t VMB_CALL VmbCamerasList ( VmbCameraInfo_t* cameraInfo, + VmbUint32_t listLength, + VmbUint32_t* numFound, + VmbUint32_t sizeofCameraInfo ); + +/** + * \brief Retrieve information about a single camera given its handle. + * + * Note: Some information is only filled for opened cameras. + * + * \param[in] cameraHandle The handle of the camera; both remote and local device handles are permitted + * + * \param[in,out] info Structure where information will be copied + * + * \param[in] sizeofCameraInfo Size of the structure + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorStructSize The given struct size is not valid for this API version + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorBadParameter \p info is null + * + * \retval ::VmbErrorBadHandle The handle does not correspond to a camera + */ +IMEXPORTC VmbError_t VMB_CALL VmbCameraInfoQueryByHandle( VmbHandle_t cameraHandle, + VmbCameraInfo_t* info, + VmbUint32_t sizeofCameraInfo); + +/** + * \brief Retrieve information about a single camera given the ID of the camera. + * + * Note: Some information is only filled for opened cameras. + * + * \param[in] idString ID of the camera + * + * \param[in,out] info Structure where information will be copied + * + * \param[in] sizeofCameraInfo Size of the structure + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p idString or \p info are null or \p idString is the empty string + * + * \retval ::VmbErrorNotFound No camera with the given id is found + * + * \retval ::VmbErrorStructSize The given struct size is not valid for this API version + */ +IMEXPORTC VmbError_t VMB_CALL VmbCameraInfoQuery ( const char* idString, + VmbCameraInfo_t* info, + VmbUint32_t sizeofCameraInfo ); + +/** + * \brief Open the specified camera. + * + * \param[in] idString ID of the camera. + * \param[in] accessMode The desired access mode. + * \param[out] cameraHandle The remote device handle of the camera, if opened successfully. + * + * A camera may be opened in a specific access mode, which determines + * the level of control you have on a camera. + * Examples for idString: + * + * "DEV_81237473991" for an ID given by a transport layer, + * "169.254.12.13" for an IP address, + * "000F314C4BE5" for a MAC address or + * "DEV_1234567890" for an ID as reported by Vmb + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInUse The camera with the given ID is already opened + * + * \retval ::VmbErrorInvalidCall If called from frame callback or chunk access callback + * + * \retval ::VmbErrorBadParameter If \p idString or \p cameraHandle are null + * + * \retval ::VmbErrorInvalidAccess A camera with the given id was found, but could not be opened + * + * \retval ::VmbErrorNotFound The designated camera cannot be found + */ +IMEXPORTC VmbError_t VMB_CALL VmbCameraOpen ( const char* idString, + VmbAccessMode_t accessMode, + VmbHandle_t* cameraHandle ); + +/** + * \brief Close the specified camera. + * + * Depending on the access mode this camera was opened with, events are killed, + * callbacks are unregistered, and camera control is released. + * + * \param[in] cameraHandle A valid camera handle + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInUse The camera is currently in use with ::VmbChunkDataAccess + * + * \retval ::VmbErrorBadHandle The handle does not correspond to an open camera + * + * \retval ::VmbErrorInvalidCall If called from frame callback or chunk access callback + */ +IMEXPORTC VmbError_t VMB_CALL VmbCameraClose ( const VmbHandle_t cameraHandle ); + +/** + * \} \} + */ + +//----- Features ---------------------------------------------------------- + +/** + * \name General Feature Functions + * \{ + * \defgroup GeneralFeatures General Feature Functions + * \{ + */ + +/** + * \brief List all the features for this entity. + * + * This function lists all implemented features, whether they are currently available or not. + * The list of features does not change as long as the entity is connected. + * + * This function is usually called twice: once with an empty list to query the length + * of the list, and then again with a list of the correct length. + * + * If ::VmbErrorMoreData is returned and \p numFound is non-null, the total number of features has been written to \p numFound. + * + * If there are more elements in \p featureInfoList than features available, the remaining elements + * are filled with zero-initialized ::VmbFeatureInfo_t structs. + * + * \param[in] handle Handle for an entity that exposes features + * \param[out] featureInfoList An array of ::VmbFeatureInfo_t to be filled by the API. May be null if \p numFund is used for size query. + * \param[in] listLength Number of ::VmbFeatureInfo_t elements provided + * \param[out] numFound Number of ::VmbFeatureInfo_t elements found. May be null if \p featureInfoList is not null. + * \param[in] sizeofFeatureInfo Size of a ::VmbFeatureInfo_t entry + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorStructSize The given struct size of ::VmbFeatureInfo_t is not valid for this version of the API + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter Both \p featureInfoList and \p numFound are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeaturesList ( VmbHandle_t handle, + VmbFeatureInfo_t* featureInfoList, + VmbUint32_t listLength, + VmbUint32_t* numFound, + VmbUint32_t sizeofFeatureInfo ); + +/** + * \brief Query information about the constant properties of a feature. + * + * Users provide a pointer to ::VmbFeatureInfo_t, which is then set to the internal representation. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] featureInfo The feature info to query + * \param[in] sizeofFeatureInfo Size of the structure + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorStructSize The given struct size of ::VmbFeatureInfo_t is not valid for this version of the API + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name or \p featureInfo are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound A feature with the given name does not exist. + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureInfoQuery ( const VmbHandle_t handle, + const char* name, + VmbFeatureInfo_t* featureInfo, + VmbUint32_t sizeofFeatureInfo ); + +/** + * \brief List all the features selected by a given feature for this module. + * + * This function lists all selected features, whether they are currently available or not. + * Features with selected features ("selectors") have no direct impact on the camera, + * but only influence the register address that selected features point to. + * The list of features does not change while the camera/interface is connected. + * This function is usually called twice: once with an empty array to query the length + * of the list, and then again with an array of the correct length. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] featureInfoList An array of ::VmbFeatureInfo_t to be filled by the API. May be null if \p numFound is used for size query. + * \param[in] listLength Number of ::VmbFeatureInfo_t elements provided + * \param[out] numFound Number of ::VmbFeatureInfo_t elements found. May be null if \p featureInfoList is not null. + * \param[in] sizeofFeatureInfo Size of a ::VmbFeatureInfo_t entry + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorBadParameter \p name is null or both \p featureInfoList and \p numFound are null + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorStructSize The given struct size of ::VmbFeatureInfo_t is not valid for this version of the API + * + * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureListSelected ( const VmbHandle_t handle, + const char* name, + VmbFeatureInfo_t* featureInfoList, + VmbUint32_t listLength, + VmbUint32_t* numFound, + VmbUint32_t sizeofFeatureInfo ); + +/** + * \brief Return the dynamic read and write capabilities of this feature. + * + * The access mode of a feature may change. For example, if "PacketSize" + * is locked while image data is streamed, it is only readable. + * + * \param[in] handle Handle for an entity that exposes features. + * \param[in] name Name of the feature. + * \param[out] isReadable Indicates if this feature is readable. May be null. + * \param[out] isWriteable Indicates if this feature is writable. May be null. + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name is null or both \p isReadable and \p isWriteable are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureAccessQuery ( const VmbHandle_t handle, + const char* name, + VmbBool_t * isReadable, + VmbBool_t * isWriteable ); + +/** + * \} \} + */ + +/** + * \name Integer Feature Access + * \{ + * \defgroup IntAccess Integer Feature Access + * \{ + */ + +/** + * \brief Get the value of an integer feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] value Value to get + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name or \p value are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Integer + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntGet ( const VmbHandle_t handle, + const char* name, + VmbInt64_t* value ); + +/** + * \brief Set the value of an integer feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[in] value Value to set + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorInvalidCall If called from feature callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter If \p name is null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Integer + * + * \retval ::VmbErrorInvalidAccess The feature is unavailable or not writable + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + * + * \retval ::VmbErrorInvalidValue If value is either out of bounds or not an increment of the minimum + * + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntSet ( const VmbHandle_t handle, + const char* name, + VmbInt64_t value ); + +/** + * \brief Query the range of an integer feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] min Minimum value to be returned. May be null. + * \param[out] max Maximum value to be returned. May be null. + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter If \p name is null or both \p min and \p max are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature name is not Integer + * + * \retval ::VmbErrorInvalidAccess The range information is unavailable or not writable + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntRangeQuery ( const VmbHandle_t handle, + const char* name, + VmbInt64_t* min, + VmbInt64_t* max ); + +/** + * \brief Query the increment of an integer feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] value Value of the increment to get. + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter If \p name or \p value are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Integer + * + * \retval ::VmbErrorInvalidAccess The information is unavailable or cannot be read + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntIncrementQuery ( const VmbHandle_t handle, + const char* name, + VmbInt64_t* value ); + +/** + * \brief Retrieves info about the valid value set of an integer feature. + * + * Retrieves information about the set of valid values of an integer feature. If null is passed as buffer, + * only the size of the set is determined and written to bufferFilledCount; Otherwise the largest possible + * number of elements of the valid value set is copied to buffer. + * + * \param[in] handle The handle for the entity the feature information is retrieved from + * \param[in] name The name of the feature to retrieve the info for; if null is passed ::VmbErrorBadParameter is returned + * \param[in] buffer The array to copy the valid values to or null if only the size of the set is requested + * \param[in] bufferSize The size of buffer; if buffer is null, the value is ignored + * \param[out] setSize The total number of elements in the set; the value is set, if ::VmbErrorMoreData is returned + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name is null or both \p buffer and \p bufferFilledCount are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of the feature is not Integer + * + * \retval ::VmbErrorValidValueSetNotPresent The feature does not provide a valid value set + * + * \retval ::VmbErrorMoreData Some of data was retrieved successfully, but the size of buffer is insufficient to store all elements + * + * \retval ::VmbErrorIncomplete The module the handle refers to is in a state where it cannot complete the request + * + * \retval ::VmbErrorOther Some other issue occurred + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntValidValueSetQuery(const VmbHandle_t handle, + const char* name, + VmbInt64_t* buffer, + VmbUint32_t bufferSize, + VmbUint32_t* setSize); + +/** + * \} \} + */ + +/** + * \name Float Feature Access + * \{ + * \defgroup FloatAccess Float Feature Access + * \{ + */ + +/** + * \brief Get the value of a float feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] value Value to get + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name or \p value are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Float + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureFloatGet ( const VmbHandle_t handle, + const char* name, + double* value ); + +/** + * \brief Set the value of a float feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[in] value Value to set + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from feature callback + * + * \retval ::VmbErrorBadParameter \p name is null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Float + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + * + * \retval ::VmbErrorInvalidValue If value is not within valid bounds + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureFloatSet ( const VmbHandle_t handle, + const char* name, + double value ); + +/** + * \brief Query the range of a float feature. + * + * Only one of the values may be queried if the other parameter is set to null, + * but if both parameters are null, an error is returned. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] min Minimum value to be returned. May be null. + * \param[out] max Maximum value to be returned. May be null. + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorBadParameter \p name is null or both \p min and \p max are null + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Float + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureFloatRangeQuery ( const VmbHandle_t handle, + const char* name, + double* min, + double* max ); + +/** + * \brief Query the increment of a float feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] hasIncrement `true` if this float feature has an increment. + * \param[out] value Value of the increment to get. + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorBadParameter \p name is null or both \p value and \p hasIncrement are null + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Float + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureFloatIncrementQuery ( const VmbHandle_t handle, + const char* name, + VmbBool_t* hasIncrement, + double* value ); + +/** + * \} \} +*/ + +/** + * \name Enum Feature Access + * \{ + * \defgroup EnumAccess Enum Feature Access + * \{ + */ + +/** + * \brief Get the value of an enumeration feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] value The current enumeration value. The returned value is a + * reference to the API value + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorBadParameter \p name or \p value are null + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature featureName is not Enumeration + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature is not available + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumGet ( const VmbHandle_t handle, + const char* name, + const char** value ); + +/** + * \brief Set the value of an enumeration feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[in] value Value to set + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from feature callback + * + * \retval ::VmbErrorBadParameter If \p name or \p value are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration + * + * \retval ::VmbErrorNotAvailable The feature is not available + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorInvalidValue \p value is not a enum entry for the feature or the existing enum entry is currently not available + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumSet ( const VmbHandle_t handle, + const char* name, + const char* value ); + +/** + * \brief Query the value range of an enumeration feature. + * + * All elements not filled with the names of enum entries by the function are set to null. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[out] nameArray An array of enumeration value names; may be null if \p numFound is used for size query + * \param[in] arrayLength Number of elements in the array + * \param[out] numFound Number of elements found; may be null if \p nameArray is not null + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name is null or both \p nameArray and \p numFound are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorNotImplemented The feature \p name is not implemented + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration + * + * \retval ::VmbErrorMoreData The given array length was insufficient to hold all available entries + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumRangeQuery ( const VmbHandle_t handle, + const char* name, + const char** nameArray, + VmbUint32_t arrayLength, + VmbUint32_t* numFound ); + +/** + * \brief Check if a certain value of an enumeration is available. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[in] value Value to check + * \param[out] isAvailable Indicates if the given enumeration value is available + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name, \p value or \p isAvailable are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration + * + * \retval ::VmbErrorNotImplemented The feature \p name is not implemented + * + * \retval ::VmbErrorInvalidValue There is no enum entry with string representation of \p value for the given enum feature + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumIsAvailable ( const VmbHandle_t handle, + const char* name, + const char* value, + VmbBool_t * isAvailable ); + +/** + * \brief Get the integer value for a given enumeration string value. + * + * Converts a name of an enum member into an int value ("Mono12Packed" to 0x10C0006) + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[in] value The enumeration value to get the integer value for + * \param[out] intVal The integer value for this enumeration entry + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter If \p name, \p value or \p intVal are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound No feature with the given name was found + * + * \retval ::VmbErrorNotImplemented The feature \p name is not implemented + * + * \retval ::VmbErrorInvalidValue \p value is not the name of a enum entry for the feature + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumAsInt ( const VmbHandle_t handle, + const char* name, + const char* value, + VmbInt64_t* intVal ); + +/** + * \brief Get the enumeration string value for a given integer value. + * + * Converts an int value to a name of an enum member (e.g. 0x10C0006 to "Mono12Packed") + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[in] intValue The numeric value + * \param[out] stringValue The string value for the numeric value + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name or \p stringValue are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound No feature with the given name was found + * + * \retval ::VmbErrorNotImplemented No feature \p name is not implemented + * + * \retval ::VmbErrorInvalidValue \p intValue is not the int value of an enum entry + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumAsString ( VmbHandle_t handle, + const char* name, + VmbInt64_t intValue, + const char** stringValue ); + +/** + * \brief Get infos about an entry of an enumeration feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] featureName Name of the feature + * \param[in] entryName Name of the enum entry of that feature + * \param[out] featureEnumEntry Infos about that entry returned by the API + * \param[in] sizeofFeatureEnumEntry Size of the structure + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorStructSize Size of ::VmbFeatureEnumEntry_t is not compatible with the API version + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p featureName, \p entryName or \p featureEnumEntry are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorNotImplemented The feature \p name is not implemented + * + * \retval ::VmbErrorInvalidValue There is no enum entry with a string representation of \p entryName + * + * \retval ::VmbErrorWrongType The type of feature featureName is not Enumeration + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumEntryGet ( const VmbHandle_t handle, + const char* featureName, + const char* entryName, + VmbFeatureEnumEntry_t* featureEnumEntry, + VmbUint32_t sizeofFeatureEnumEntry ); + +/** + * \} \} + */ + +/** + * \name String Feature Access + * \{ + * \defgroup StringAccess String Feature Access + * \{ + */ + +/** + * \brief Get the value of a string feature. + * + * This function is usually called twice: once with an empty buffer to query the length + * of the string, and then again with a buffer of the correct length. + * + * The value written to \p sizeFilled includes the terminating 0 character of the string. + * + * If a \p buffer is provided and there its insufficient to hold all the data, the longest + * possible prefix fitting the buffer is copied to \p buffer; the last element of \p buffer is + * set to 0 case. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the string feature + * \param[out] buffer String buffer to fill. May be null if \p sizeFilled is used for size query. + * \param[in] bufferSize Size of the input buffer + * \param[out] sizeFilled Size actually filled. May be null if \p buffer is not null. + * + * + * \return An error code indicating the type of error, if any. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name is null, both \p buffer and \p sizeFilled are null or \p buffer is non-null and bufferSize is 0 + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not String + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + * + * \retval ::VmbErrorMoreData The given buffer size was too small + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureStringGet ( const VmbHandle_t handle, + const char* name, + char* buffer, + VmbUint32_t bufferSize, + VmbUint32_t* sizeFilled ); + +/** + * \brief Set the value of a string feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the string feature + * \param[in] value Value to set + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from feature callback + * + * \retval ::VmbErrorBadParameter \p name or \p value are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not String + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorInvalidValue If length of value exceeded the maximum length + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureStringSet ( const VmbHandle_t handle, + const char* name, + const char* value ); + +/** + * \brief Get the maximum length of a string feature. + * + * The length reported does not include the terminating 0 char. + * + * Note: For some features the maximum size is not fixed and may change. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the string feature + * \param[out] maxLength Maximum length of this string feature + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name or \p maxLength are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorWrongType The type of feature \p name is not String + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureStringMaxlengthQuery ( const VmbHandle_t handle, + const char* name, + VmbUint32_t* maxLength ); + +/** + * \} \} + */ + +/** + * \name Boolean Feature Access + * \{ + * \defgroup BoolAccess Boolean Feature Access + * \{ + */ + +/** + * \brief Get the value of a boolean feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the boolean feature + * \param[out] value Value to be read + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name or \p value are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound If feature is not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Boolean + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureBoolGet ( const VmbHandle_t handle, + const char* name, + VmbBool_t * value ); + +/** + * \brief Set the value of a boolean feature. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the boolean feature + * \param[in] value Value to write + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name is null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound If the feature is not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Boolean + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + * + * \retval ::VmbErrorInvalidValue If value is not within valid bounds + * + * \retval ::VmbErrorInvalidCall If called from feature callback + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureBoolSet ( const VmbHandle_t handle, + const char* name, + VmbBool_t value ); + +/** + * \} \} + */ + +/** + * \name Command Feature Access + * \{ + * \defgroup CmdAccess Command Feature Access + * \{ + */ + +/** + * \brief Run a feature command. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the command feature + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorInvalidCall If called from a feature callback or chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name is null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound Feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Command + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureCommandRun ( const VmbHandle_t handle, + const char* name ); + +/** + * \brief Check if a feature command is done. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the command feature + * \param[out] isDone State of the command. + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorBadParameter If \p name or \p isDone are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound Feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Command + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureCommandIsDone ( const VmbHandle_t handle, + const char* name, + VmbBool_t * isDone ); + +/** + * \} \} + */ + +/** + * \name Raw Feature Access + * \{ + * \defgroup RawAccess Raw Feature Access + * \{ + */ + +/** + * \brief Read the memory contents of an area given by a feature name. + * + * This feature type corresponds to a top-level "Register" feature in GenICam. + * Data transfer is split up by the transport layer if the feature length is too large. + * You can get the size of the memory area addressed by the feature name by ::VmbFeatureRawLengthQuery(). + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the raw feature + * \param[out] buffer Buffer to fill + * \param[in] bufferSize Size of the buffer to be filled + * \param[out] sizeFilled Number of bytes actually filled + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p name, \p buffer or \p sizeFilled are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound Feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Register + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureRawGet ( const VmbHandle_t handle, + const char* name, + char* buffer, + VmbUint32_t bufferSize, + VmbUint32_t* sizeFilled ); + +/** + * \brief Write to a memory area given by a feature name. + * + * This feature type corresponds to a first-level "Register" node in the XML file. + * Data transfer is split up by the transport layer if the feature length is too large. + * You can get the size of the memory area addressed by the feature name by ::VmbFeatureRawLengthQuery(). + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the raw feature + * \param[in] buffer Data buffer to use + * \param[in] bufferSize Size of the buffer + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from feature callback or a chunk access callback + * + * \retval ::VmbErrorBadParameter \p name or \p buffer are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound Feature was not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Register + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureRawSet ( const VmbHandle_t handle, + const char* name, + const char* buffer, + VmbUint32_t bufferSize ); + +/** + * \brief Get the length of a raw feature for memory transfers. + * + * This feature type corresponds to a first-level "Register" node in the XML file. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the raw feature + * \param[out] length Length of the raw feature area (in bytes) + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter If \p name or \p length are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound Feature not found + * + * \retval ::VmbErrorWrongType The type of feature \p name is not Register + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorNotImplemented The feature isn't implemented + * + * \retval ::VmbErrorNotAvailable The feature isn't available currently + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureRawLengthQuery ( const VmbHandle_t handle, + const char* name, + VmbUint32_t* length ); + +/** + * \} \} + */ + +/** + * \name Feature Invalidation + * \{ + * \defgroup FeatureInvalidation Feature Invalidation + * \{ + */ + +/** + * \brief Register a VmbInvalidationCallback callback for feature invalidation signaling. + * + * Any feature change, either of its value or of its access state, may be tracked + * by registering an invalidation callback. + * Registering multiple callbacks for one feature invalidation event is possible because + * only the combination of handle, name, and callback is used as key. If the same + * combination of handle, name, and callback is registered a second time, the callback remains + * registered and the context is overwritten with \p userContext. + * + * \param[in] handle Handle for an entity that emits events + * \param[in] name Name of the event + * \param[in] callback Callback to be run when invalidation occurs + * \param[in] userContext User context passed to function + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorBadParameter If \p name or \p callback are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound No feature with \p name was found for the module associated with \p handle + * + * \retval ::VmbErrorNotImplemented The feature \p name is not implemented + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureInvalidationRegister ( VmbHandle_t handle, + const char* name, + VmbInvalidationCallback callback, + void* userContext ); + +/** + * \brief Unregister a previously registered feature invalidation callback. + * + * Since multiple callbacks may be registered for a feature invalidation event, + * a combination of handle, name, and callback is needed for unregistering, too. + * + * \param[in] handle Handle for an entity that emits events + * \param[in] name Name of the event + * \param[in] callback Callback to be removed + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorBadParameter If \p name or \p callback are null + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound No feature with \p name was found for the module associated with \p handle or there was no listener to unregister + * + * \retval ::VmbErrorNotImplemented The feature \p name is not implemented + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + */ +IMEXPORTC VmbError_t VMB_CALL VmbFeatureInvalidationUnregister ( VmbHandle_t handle, + const char* name, + VmbInvalidationCallback callback ); + +/** + * \} \} + */ + +/** + * \name Image preparation and acquisition + * \{ + * \defgroup Capture Image preparation and acquisition + * \{ + */ + +/** +* \brief Get the necessary payload size for buffer allocation. +* +* Returns the payload size necessary for buffer allocation as queried from the Camera. +* If the stream module provides a PayloadSize feature, this value will be returned instead. +* If a camera handle is passed, the payload size refers to the stream with index 0. +* +* \param[in] handle Camera or stream handle +* \param[out] payloadSize Payload Size +* +* +* \return An error code indicating success or the type of error that occurred. +* +* \retval ::VmbErrorSuccess If no error +* +* \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command +* +* \retval ::VmbErrorBadHandle The given handle is not valid +* +* \retval ::VmbErrorBadParameter \p payloadSize is null +*/ +IMEXPORTC VmbError_t VMB_CALL VmbPayloadSizeGet(VmbHandle_t handle, + VmbUint32_t* payloadSize); + +/** + * \brief Announce frames to the API that may be queued for frame capturing later. + * + * Allows some preparation for frames like DMA preparation depending on the transport layer. + * The order in which the frames are announced is not taken into consideration by the API. + * If frame.buffer is null, the allocation is done by the transport layer. + * + * \param[in] handle Camera or stream handle + * \param[in] frame Frame buffer to announce + * \param[in] sizeofFrame Size of the frame structure + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorStructSize The given struct size is not valid for this version of the API + * + * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given camera handle is not valid + * + * \retval ::VmbErrorBadParameter \p frame is null + * + * \retval ::VmbErrorAlready The frame has already been announced + * + * \retval ::VmbErrorBusy The underlying transport layer does not support announcing frames during acquisition + * + * \retval ::VmbErrorMoreData The given buffer size is invalid (usually 0) + */ +IMEXPORTC VmbError_t VMB_CALL VmbFrameAnnounce ( VmbHandle_t handle, + const VmbFrame_t* frame, + VmbUint32_t sizeofFrame ); + + +/** + * \brief Revoke a frame from the API. + * + * The referenced frame is removed from the pool of frames for capturing images. + * + * \param[in] handle Handle for a camera or stream + * \param[in] frame Frame buffer to be removed from the list of announced frames + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorBadParameter The given frame pointer is not valid + * + * \retval ::VmbErrorBusy The underlying transport layer does not support revoking frames during acquisition + * + * \retval ::VmbErrorNotFound The given frame could not be found for the stream + * + * \retval ::VmbErrorInUse The frame is currently still in use (e.g. in a running frame callback) + */ +IMEXPORTC VmbError_t VMB_CALL VmbFrameRevoke ( VmbHandle_t handle, + const VmbFrame_t* frame ); + + +/** + * \brief Revoke all frames assigned to a certain stream or camera. + * + * In case of an failure some of the frames may have been revoked. To prevent this it is recommended to call + * ::VmbCaptureQueueFlush for the same handle before invoking this function. + * + * \param[in] handle Handle for a stream or camera + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle \p handle is not valid + * + * \retval ::VmbErrorInUse One of the frames of the stream is still in use + */ +IMEXPORTC VmbError_t VMB_CALL VmbFrameRevokeAll ( VmbHandle_t handle ); + + +/** + * \brief Prepare the API for incoming frames. + * + * \param[in] handle Handle for a camera or a stream + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid; this includes the camera no longer being open + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorMoreData The buffer size of the announced frames is insufficient + * + * \retval ::VmbErrorInsufficientBufferCount The operation requires more buffers to be announced; see the StreamAnnounceBufferMinimum stream feature + * + * \retval ::VmbErrorAlready Capturing was already started + */ +IMEXPORTC VmbError_t VMB_CALL VmbCaptureStart ( VmbHandle_t handle ); + + +/** + * \brief Stop the API from being able to receive frames. + * + * Consequences of VmbCaptureEnd(): + * The frame callback will not be called anymore + * + * \note This function waits for the completion of the last callback for the current capture. + * If the callback does not return in finite time, this function may not return in finite time either. + * + * \param[in] handle Handle for a stream or camera + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle \p handle is not valid + */ +IMEXPORTC VmbError_t VMB_CALL VmbCaptureEnd ( VmbHandle_t handle ); + + +/** + * \brief Queue frames that may be filled during frame capturing. + * + * The given frame is put into a queue that will be filled sequentially. + * The order in which the frames are filled is determined by the order in which they are queued. + * If the frame was announced with ::VmbFrameAnnounce() before, the application + * has to ensure that the frame is also revoked by calling ::VmbFrameRevoke() or + * ::VmbFrameRevokeAll() when cleaning up. + * + * \warning \p callback should to return in finite time. Otherwise ::VmbCaptureEnd and + * operations resulting in the stream being closed may not return. + * + * \param[in] handle Handle of a camera or stream + * \param[in] frame Pointer to an already announced frame + * \param[in] callback Callback to be run when the frame is complete. Null is OK. + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorBadParameter If \p frame is null + * + * \retval ::VmbErrorBadHandle No stream related to \p handle could be found + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInternalFault The buffer or bufferSize members of \p frame have been set to null or zero respectively + * + * \retval ::VmbErrorNotFound The frame is not a frame announced for the given stream + * + * \retval ::VmbErrorAlready The frame is currently queued + */ +IMEXPORTC VmbError_t VMB_CALL VmbCaptureFrameQueue ( VmbHandle_t handle, + const VmbFrame_t* frame, + VmbFrameCallback callback ); + +/** + * \brief Wait for a queued frame to be filled (or dequeued). + * + * The frame needs to be queued and not filled for the function to complete successfully. + * + * If a camera handle is passed, the first stream of the camera is used. + * + * \param[in] handle Handle of a camera or stream + * \param[in] frame Pointer to an already announced and queued frame + * \param[in] timeout Timeout (in milliseconds) + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorBadParameter If \p frame or the buffer of \p frame are null or the the buffer size of \p frame is 0 + * + * \retval ::VmbErrorBadHandle No stream related to \p handle could be found + * + * \retval ::VmbErrorNotFound The frame is not one currently queued for the stream + * + * \retval ::VmbErrorAlready The frame has already been dequeued or VmbCaptureFrameWait has been called already for this frame + * + * \retval ::VmbErrorInUse If the frame was queued with a frame callback + * + * \retval ::VmbErrorTimeout Call timed out + * + * \retval ::VmbErrorIncomplete Capture is not active when the function is called + */ +IMEXPORTC VmbError_t VMB_CALL VmbCaptureFrameWait ( const VmbHandle_t handle, + const VmbFrame_t* frame, + VmbUint32_t timeout); + + +/** + * \brief Flush the capture queue. + * + * Control of all the currently queued frames will be returned to the user, + * leaving no frames in the capture queue. + * After this call, no frame notification will occur until frames are queued again + * + * Frames need to be revoked separately, if desired. + * + * This function can only succeeds, if no capture is currently active. + * If ::VmbCaptureStart has been called for the stream, but no successful call to ::VmbCaptureEnd + * happened, the function fails with error code ::VmbErrorInUse. + * + * \param[in] handle The handle of the camera or stream to flush. + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorBadHandle No stream related to \p handle could be found. + * + * \retval ::VmbErrorInUse There is currently an active capture + */ +IMEXPORTC VmbError_t VMB_CALL VmbCaptureQueueFlush(VmbHandle_t handle); + +/** + * \} \} + */ + +/** + * \name Transport Layer Enumeration & Information + * \{ + * \defgroup TransportLayer Transport Layer Enumeration & Information + * \{ + */ + +/** + * \brief List all the transport layers that are used by the API. + * + * Note: This function is usually called twice: once with an empty array to query the length + * of the list, and then again with an array of the correct length. + * + * \param[in,out] transportLayerInfo Array of VmbTransportLayerInfo_t, allocated by the caller. + * The transport layer list is copied here. May be null. + * \param[in] listLength Number of entries in the caller's transportLayerInfo array. + * \param[in,out] numFound Number of transport layers found. May be more than listLength. + * \param[in] sizeofTransportLayerInfo Size of one ::VmbTransportLayerInfo_t entry (ignored if \p transportLayerInfo is null). + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInternalFault An internal fault occurred + * + * \retval ::VmbErrorNotImplemented One of the transport layers does not provide the required information + * + * \retval ::VmbErrorBadParameter \p numFound is null + * + * \retval ::VmbErrorStructSize The given struct size is not valid for this API version + * + * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries + */ +IMEXPORTC VmbError_t VMB_CALL VmbTransportLayersList ( VmbTransportLayerInfo_t* transportLayerInfo, + VmbUint32_t listLength, + VmbUint32_t* numFound, + VmbUint32_t sizeofTransportLayerInfo); + +/** + * \} \} +*/ + +/** + * \name Interface Enumeration & Information + * \{ + * \defgroup Interface Interface Enumeration & Information + * \{ + */ + +/** + * \brief List all the interfaces that are currently visible to the API. + * + * Note: All the interfaces known via GenICam transport layers are listed by this + * command and filled into the provided array. Interfaces may correspond to + * adapter cards or frame grabber cards. + * This function is usually called twice: once with an empty array to query the length + * of the list, and then again with an array of the correct length. + * + * \param[in,out] interfaceInfo Array of ::VmbInterfaceInfo_t, allocated by the caller. + * The interface list is copied here. May be null. + * + * \param[in] listLength Number of entries in the callers interfaceInfo array + * + * \param[in,out] numFound Number of interfaces found. Can be more than listLength + * + * \param[in] sizeofInterfaceInfo Size of one ::VmbInterfaceInfo_t entry + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p numFound is null + * + * \retval ::VmbErrorStructSize The given struct size is not valid for this API version + * + * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries + */ +IMEXPORTC VmbError_t VMB_CALL VmbInterfacesList ( VmbInterfaceInfo_t* interfaceInfo, + VmbUint32_t listLength, + VmbUint32_t* numFound, + VmbUint32_t sizeofInterfaceInfo ); + +/** + * \} \} + */ + +/** + * \name Direct Access + * \{ + * \defgroup DirectAccess Direct Access + * \{ + */ + +//----- Memory/Register access -------------------------------------------- + +/** + * \brief Read an array of bytes. + * + * \param[in] handle Handle for an entity that allows memory access + * \param[in] address Address to be used for this read operation + * \param[in] bufferSize Size of the data buffer to read + * \param[out] dataBuffer Buffer to be filled + * \param[out] sizeComplete Size of the data actually read + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + */ +IMEXPORTC VmbError_t VMB_CALL VmbMemoryRead ( const VmbHandle_t handle, + VmbUint64_t address, + VmbUint32_t bufferSize, + char* dataBuffer, + VmbUint32_t* sizeComplete ); + +/** + * \brief Write an array of bytes. + * + * \param[in] handle Handle for an entity that allows memory access + * \param[in] address Address to be used for this read operation + * \param[in] bufferSize Size of the data buffer to write + * \param[in] dataBuffer Data to write + * \param[out] sizeComplete Number of bytes successfully written; if an + * error occurs this is less than bufferSize + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorMoreData Not all data were written; see sizeComplete value for the number of bytes written + */ +IMEXPORTC VmbError_t VMB_CALL VmbMemoryWrite ( const VmbHandle_t handle, + VmbUint64_t address, + VmbUint32_t bufferSize, + const char* dataBuffer, + VmbUint32_t* sizeComplete ); + +/** + * \} \} + */ + +/** + * \name Load & Save Settings + * \{ + * \defgroup LoadSaveSettings Load & Save Settings + * \{ + */ + +/** + * \brief Write the current features related to a module to a xml file + * + * Camera must be opened beforehand and function needs corresponding handle. + * With given filename parameter path and name of XML file can be determined. + * Additionally behaviour of function can be set with providing 'persistent struct'. + * + * \param[in] handle Handle for an entity that allows register access + * \param[in] filePath The path to the file to save the settings to; relative paths are relative to the current working directory + * \param[in] settings Settings struct; if null the default settings are used + * (persist features except LUT for the remote device, maximum 5 iterations, logging only errors) + * \param[in] sizeofSettings Size of settings struct + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorBadParameter If \p filePath is or the settings struct is invalid + * + * \retval ::VmbErrorStructSize If sizeofSettings the struct size does not match the size of the struct expected by the API + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorNotFound The provided handle is insufficient to identify all the modules that should be saved + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorIO There was an issue writing the file. + */ +IMEXPORTC VmbError_t VMB_CALL VmbSettingsSave(VmbHandle_t handle, + const VmbFilePathChar_t* filePath, + const VmbFeaturePersistSettings_t* settings, + VmbUint32_t sizeofSettings); + +/** + * \brief Load all feature values from xml file to device-related modules. + * + * The modules must be opened beforehand. If the handle is non-null it must be a valid handle other than the Vmb API handle. + * Additionally behaviour of function can be set with providing \p settings . Note that even in case of an failure some or all of the features + * may have been set for some of the modules. + * + * The error code ::VmbErrorRetriesExceeded only indicates that the number of retries was insufficient + * to restore the features. Even if the features could not be restored for one of the modules, restoring the features is not aborted but the process + * continues for other modules, if present. + * + * \param[in] handle Handle related to the modules to write the values to; + * may be null to indicate that modules should be identified based on the information provided in the input file + * + * \param[in] filePath The path to the file to load the settings from; relative paths are relative to the current working directory + * \param[in] settings Settings struct; pass null to use the default settings. If the \p maxIterations field is 0, the number of + * iterations is determined by the value loaded from the xml file + * \param[in] sizeofSettings Size of the settings struct + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess If no error + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback + * + * \retval ::VmbErrorStructSize If sizeofSettings the struct size does not match the size of the struct expected by the API + * + * \retval ::VmbErrorWrongType \p handle is neither null nor a transport layer, interface, local device, remote device or stream handle + * + * \retval ::VmbErrorBadHandle The given handle is not valid + * + * \retval ::VmbErrorAmbiguous The modules to restore the settings for cannot be uniquely identified based on the information available + * + * \retval ::VmbErrorNotFound The provided handle is insufficient to identify all the modules that should be restored + * + * \retval ::VmbErrorRetriesExceeded Some or all of the features could not be restored with the max iterations specified + * + * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode + * + * \retval ::VmbErrorBadParameter If \p filePath is null or the settings struct is invalid + * + * \retval ::VmbErrorIO There was an issue with reading the file. + */ +IMEXPORTC VmbError_t VMB_CALL VmbSettingsLoad(VmbHandle_t handle, + const VmbFilePathChar_t* filePath, + const VmbFeaturePersistSettings_t* settings, + VmbUint32_t sizeofSettings); + +/** + * \} \} + */ + +/** + * \name Chunk Data + * \{ + * \defgroup ChunkData Chunk Data + * \{ + */ + +/** + * \brief Access chunk data for a frame. + * + * This function can only succeed if the given frame has been filled by the API. + * + * \param[in] frame A pointer to a filled frame that is announced + * \param[in] chunkAccessCallback A callback to access the chunk data from + * \param[in] userContext A pointer to pass to the callback + * + * + * \return An error code indicating success or the type of error that occurred. + * + * \retval ::VmbErrorSuccess The call was successful + * + * \retval ::VmbErrorInvalidCall If called from a chunk access callback or a feature callback + * + * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command + * + * \retval ::VmbErrorBadParameter \p frame or \p chunkAccessCallback are null + * + * \retval ::VmbErrorInUse The frame state does not allow for retrieval of chunk data + * (e.g. the frame could have been reenqueued before the chunk access could happen). + * + * \retval ::VmbErrorNotFound The frame is currently not announced for a stream + * + * \retval ::VmbErrorDeviceNotOpen If the device the frame was received from is no longer open + * + * \retval ::VmbErrorNoChunkData \p frame does not contain chunk data + * + * \retval ::VmbErrorParsingChunkData The chunk data does not adhere to the expected format + * + * \retval ::VmbErrorUserCallbackException The callback threw an exception + * + * \retval ::VmbErrorFeaturesUnavailable The feature description for the remote device is unavailable + * + * \retval ::VmbErrorCustom The minimum a user defined error code returned by the callback + */ +IMEXPORTC VmbError_t VMB_CALL VmbChunkDataAccess(const VmbFrame_t* frame, + VmbChunkAccessCallback chunkAccessCallback, + void* userContext); + +/** + * \} \} \} + */ +#ifdef __cplusplus +} +#endif + +#endif // VMBC_H_INCLUDE_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCTypeDefinitions.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCTypeDefinitions.h new file mode 100644 index 000000000..b010d5be6 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCTypeDefinitions.h @@ -0,0 +1,610 @@ +/*============================================================================= + Copyright (C) 2012 - 2021 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + +------------------------------------------------------------------------------- + + File: VmbCTypeDefinitions.h + +------------------------------------------------------------------------------- + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ + +/** + * \file + * \brief Struct definitions for the VmbC API. + */ + +#ifndef VMBC_TYPE_DEFINITIONS_H_INCLUDE_ +#define VMBC_TYPE_DEFINITIONS_H_INCLUDE_ + +#include +#include + +#include + +#if defined (_WIN32) +#if defined AVT_VMBAPI_C_EXPORTS // DLL exports +#define IMEXPORTC // We export via the .def file +#elif defined AVT_VMBAPI_C_LIB // static LIB +#define IMEXPORTC +#else // import +#define IMEXPORTC __declspec(dllimport) +#endif + +#ifndef _WIN64 + // Calling convention +#define VMB_CALL __stdcall +#else + // Calling convention +#define VMB_CALL +#endif +#elif defined (__GNUC__) && (__GNUC__ >= 4) && defined (__ELF__) + // SO exports (requires compiler option -fvisibility=hidden) +#ifdef AVT_VMBAPI_C_EXPORTS +#define IMEXPORTC __attribute__((visibility("default"))) +#else +#define IMEXPORTC +#endif + +#ifdef __i386__ + // Calling convention +#define VMB_CALL __attribute__((stdcall)) +#else + // Calling convention +#define VMB_CALL +#endif +#elif defined (__APPLE__) +#define IMEXPORTC __attribute__((visibility("default"))) + // Calling convention +#define VMB_CALL +#else +#error Unknown platform, file needs adaption +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \name Transport layer + * \{ + */ + + /** +* \brief Camera or transport layer type (for instance U3V or GEV). +*/ +typedef enum VmbTransportLayerType +{ + VmbTransportLayerTypeUnknown = 0, //!< Interface is not known to this version of the API + VmbTransportLayerTypeGEV = 1, //!< GigE Vision + VmbTransportLayerTypeCL = 2, //!< Camera Link + VmbTransportLayerTypeIIDC = 3, //!< IIDC 1394 + VmbTransportLayerTypeUVC = 4, //!< USB video class + VmbTransportLayerTypeCXP = 5, //!< CoaXPress + VmbTransportLayerTypeCLHS = 6, //!< Camera Link HS + VmbTransportLayerTypeU3V = 7, //!< USB3 Vision Standard + VmbTransportLayerTypeEthernet = 8, //!< Generic Ethernet + VmbTransportLayerTypePCI = 9, //!< PCI / PCIe + VmbTransportLayerTypeCustom = 10, //!< Non standard + VmbTransportLayerTypeMixed = 11, //!< Mixed (transport layer only) +} VmbTransportLayerType; + +/** + * \brief Type for an Interface; for values see ::VmbTransportLayerType. + */ +typedef VmbUint32_t VmbTransportLayerType_t; + +/** + * \brief Transport layer information. + * + * Holds read-only information about a transport layer. + */ +typedef struct VmbTransportLayerInfo +{ + /** + * \name Out + * \{ + */ + + const char* transportLayerIdString; //!< Unique id of the transport layer + const char* transportLayerName; //!< Name of the transport layer + const char* transportLayerModelName; //!< Model name of the transport layer + const char* transportLayerVendor; //!< Vendor of the transport layer + const char* transportLayerVersion; //!< Version of the transport layer + const char* transportLayerPath; //!< Full path of the transport layer + VmbHandle_t transportLayerHandle; //!< Handle of the transport layer for feature access + VmbTransportLayerType_t transportLayerType; //!< The type of the transport layer + + /** + * \} + */ +} VmbTransportLayerInfo_t; + +/** + * \} + */ + +/** + * \name Interface + * \{ + */ + +/** + * \brief Interface information. + * + * Holds read-only information about an interface. + */ +typedef struct VmbInterfaceInfo +{ + /** + * \name Out + * \{ + */ + + const char* interfaceIdString; //!< Identifier of the interface + const char* interfaceName; //!< Interface name, given by the transport layer + VmbHandle_t interfaceHandle; //!< Handle of the interface for feature access + VmbHandle_t transportLayerHandle; //!< Handle of the related transport layer for feature access + VmbTransportLayerType_t interfaceType; //!< The technology of the interface + + /** + * \} + */ +} VmbInterfaceInfo_t; + +/** + * \} + */ + +/** + * \name Camera + * \{ + */ + + /** + * \brief Access mode for cameras. + * + * Used in ::VmbCameraInfo_t as flags, so multiple modes can be + * announced, while in ::VmbCameraOpen(), no combination must be used. + */ +typedef enum VmbAccessModeType +{ + VmbAccessModeNone = 0, //!< No access + VmbAccessModeFull = 1, //!< Read and write access + VmbAccessModeRead = 2, //!< Read-only access + VmbAccessModeUnknown = 4, //!< Access type unknown + VmbAccessModeExclusive = 8, //!< Read and write access without permitting access for other consumers +} VmbAccessModeType; + +/** + * \brief Type for an AccessMode; for values see ::VmbAccessModeType. + */ +typedef VmbUint32_t VmbAccessMode_t; + +/** + * \brief Camera information. + * + * Holds read-only information about a camera. + */ +typedef struct VmbCameraInfo +{ + /** + * \name Out + * \{ + */ + + const char* cameraIdString; //!< Identifier of the camera + const char* cameraIdExtended; //!< globally unique identifier for the camera + const char* cameraName; //!< The display name of the camera + const char* modelName; //!< Model name + const char* serialString; //!< Serial number + VmbHandle_t transportLayerHandle; //!< Handle of the related transport layer for feature access + VmbHandle_t interfaceHandle; //!< Handle of the related interface for feature access + VmbHandle_t localDeviceHandle; //!< Handle of the related GenTL local device. NULL if the camera is not opened + VmbHandle_t const* streamHandles; //!< Handles of the streams provided by the camera. NULL if the camera is not opened + VmbUint32_t streamCount; //!< Number of stream handles in the streamHandles array + VmbAccessMode_t permittedAccess; //!< Permitted access modes, see ::VmbAccessModeType + + /** + * \} + */ +} VmbCameraInfo_t; + +/** + * \} + */ + +/** + * \name Feature + * \{ + */ + +/** + * \brief Supported feature data types. + */ +typedef enum VmbFeatureDataType +{ + VmbFeatureDataUnknown = 0, //!< Unknown feature type + VmbFeatureDataInt = 1, //!< 64-bit integer feature + VmbFeatureDataFloat = 2, //!< 64-bit floating point feature + VmbFeatureDataEnum = 3, //!< Enumeration feature + VmbFeatureDataString = 4, //!< String feature + VmbFeatureDataBool = 5, //!< Boolean feature + VmbFeatureDataCommand = 6, //!< Command feature + VmbFeatureDataRaw = 7, //!< Raw (direct register access) feature + VmbFeatureDataNone = 8, //!< Feature with no data +} VmbFeatureDataType; + +/** + * \brief Data type for a Feature; for values see ::VmbFeatureDataType. + */ +typedef VmbUint32_t VmbFeatureData_t; + +/** + * \brief Feature visibility. + */ +typedef enum VmbFeatureVisibilityType +{ + VmbFeatureVisibilityUnknown = 0, //!< Feature visibility is not known + VmbFeatureVisibilityBeginner = 1, //!< Feature is visible in feature list (beginner level) + VmbFeatureVisibilityExpert = 2, //!< Feature is visible in feature list (expert level) + VmbFeatureVisibilityGuru = 3, //!< Feature is visible in feature list (guru level) + VmbFeatureVisibilityInvisible = 4, //!< Feature is visible in the feature list, but should be hidden in GUI applications +} VmbFeatureVisibilityType; + +/** + * \brief Type for Feature visibility; for values see ::VmbFeatureVisibilityType. + */ +typedef VmbUint32_t VmbFeatureVisibility_t; + +/** + * \brief Feature flags. + */ +typedef enum VmbFeatureFlagsType +{ + VmbFeatureFlagsNone = 0, //!< No additional information is provided + VmbFeatureFlagsRead = 1, //!< Static info about read access. Current status depends on access mode, check with ::VmbFeatureAccessQuery() + VmbFeatureFlagsWrite = 2, //!< Static info about write access. Current status depends on access mode, check with ::VmbFeatureAccessQuery() + VmbFeatureFlagsVolatile = 8, //!< Value may change at any time + VmbFeatureFlagsModifyWrite = 16, //!< Value may change after a write +} VmbFeatureFlagsType; + +/** + * \brief Type for Feature flags; for values see ::VmbFeatureFlagsType. + */ +typedef VmbUint32_t VmbFeatureFlags_t; + +/** + * \brief Feature information. + * + * Holds read-only information about a feature. + */ +typedef struct VmbFeatureInfo +{ + /** + * \name Out + * \{ + */ + + const char* name; //!< Name used in the API + const char* category; //!< Category this feature can be found in + const char* displayName; //!< Feature name to be used in GUIs + const char* tooltip; //!< Short description, e.g. for a tooltip + const char* description; //!< Longer description + const char* sfncNamespace; //!< Namespace this feature resides in + const char* unit; //!< Measuring unit as given in the XML file + const char* representation; //!< Representation of a numeric feature + VmbFeatureData_t featureDataType; //!< Data type of this feature + VmbFeatureFlags_t featureFlags; //!< Access flags for this feature + VmbUint32_t pollingTime; //!< Predefined polling time for volatile features + VmbFeatureVisibility_t visibility; //!< GUI visibility + VmbBool_t isStreamable; //!< Indicates if a feature can be stored to / loaded from a file + VmbBool_t hasSelectedFeatures; //!< Indicates if the feature selects other features + + /** + * \} + */ +} VmbFeatureInfo_t; + +/** + * \brief Info about possible entries of an enumeration feature. + */ +typedef struct VmbFeatureEnumEntry +{ + /** + * \name Out + * \{ + */ + + const char* name; //!< Name used in the API + const char* displayName; //!< Enumeration entry name to be used in GUIs + const char* tooltip; //!< Short description, e.g. for a tooltip + const char* description; //!< Longer description + VmbInt64_t intValue; //!< Integer value of this enumeration entry + const char* sfncNamespace; //!< Namespace this feature resides in + VmbFeatureVisibility_t visibility; //!< GUI visibility + + /** + * \} + */ +} VmbFeatureEnumEntry_t; + +/** + * \} + */ + +/** + * \name Frame + * \{ + */ + +/** + * \brief Status of a frame transfer. + */ +typedef enum VmbFrameStatusType +{ + VmbFrameStatusComplete = 0, //!< Frame has been completed without errors + VmbFrameStatusIncomplete = -1, //!< Frame could not be filled to the end + VmbFrameStatusTooSmall = -2, //!< Frame buffer was too small + VmbFrameStatusInvalid = -3, //!< Frame buffer was invalid +} VmbFrameStatusType; + +/** + * \brief Type for the frame status; for values see ::VmbFrameStatusType. + */ +typedef VmbInt32_t VmbFrameStatus_t; + +/** + * \brief Frame flags. + */ +typedef enum VmbFrameFlagsType +{ + VmbFrameFlagsNone = 0, //!< No additional information is provided + VmbFrameFlagsDimension = 1, //!< VmbFrame_t::width and VmbFrame_t::height are provided + VmbFrameFlagsOffset = 2, //!< VmbFrame_t::offsetX and VmbFrame_t::offsetY are provided (ROI) + VmbFrameFlagsFrameID = 4, //!< VmbFrame_t::frameID is provided + VmbFrameFlagsTimestamp = 8, //!< VmbFrame_t::timestamp is provided + VmbFrameFlagsImageData = 16, //!< VmbFrame_t::imageData is provided + VmbFrameFlagsPayloadType = 32, //!< VmbFrame_t::payloadType is provided + VmbFrameFlagsChunkDataPresent = 64, //!< VmbFrame_t::chunkDataPresent is set based on info provided by the transport layer +} VmbFrameFlagsType; + +/** + * \brief Type for Frame flags; for values see ::VmbFrameFlagsType. + */ +typedef VmbUint32_t VmbFrameFlags_t; + +/** + * \brief Frame payload type. + */ +typedef enum VmbPayloadType +{ + VmbPayloadTypeUnknown = 0, //!< Unknown payload type + VmbPayloadTypeImage = 1, //!< image data + VmbPayloadTypeRaw = 2, //!< raw data + VmbPayloadTypeFile = 3, //!< file data + VmbPayloadTypeJPEG = 5, //!< JPEG data as described in the GigEVision 2.0 specification + VmbPayloadTypJPEG2000 = 6, //!< JPEG 2000 data as described in the GigEVision 2.0 specification + VmbPayloadTypeH264 = 7, //!< H.264 data as described in the GigEVision 2.0 specification + VmbPayloadTypeChunkOnly = 8, //!< Chunk data exclusively + VmbPayloadTypeDeviceSpecific = 9, //!< Device specific data format + VmbPayloadTypeGenDC = 11, //!< GenDC data +} VmbPayloadType; + +/** + * \brief Type representing the payload type of a frame. For values see ::VmbPayloadType. + */ +typedef VmbUint32_t VmbPayloadType_t; + +/** + * \brief Type used to represent a dimension value, e.g. the image height. + */ +typedef VmbUint32_t VmbImageDimension_t; + +/** + * \brief Frame delivered by the camera. + */ +typedef struct VmbFrame +{ + /** + * \name In + * \{ + */ + + void* buffer; //!< Comprises image and potentially chunk data + VmbUint32_t bufferSize; //!< The size of the data buffer + void* context[4]; //!< 4 void pointers that can be employed by the user (e.g. for storing handles) + + /** + * \} + */ + + /** + * \name Out + * \{ + */ + + VmbFrameStatus_t receiveStatus; //!< The resulting status of the receive operation + VmbUint64_t frameID; //!< Unique ID of this frame in this stream + VmbUint64_t timestamp; //!< The timestamp set by the camera + VmbUint8_t* imageData; //!< The start of the image data, if present, or null + VmbFrameFlags_t receiveFlags; //!< Flags indicating which additional frame information is available + VmbPixelFormat_t pixelFormat; //!< Pixel format of the image + VmbImageDimension_t width; //!< Width of an image + VmbImageDimension_t height; //!< Height of an image + VmbImageDimension_t offsetX; //!< Horizontal offset of an image + VmbImageDimension_t offsetY; //!< Vertical offset of an image + VmbPayloadType_t payloadType; //!< The type of payload + VmbBool_t chunkDataPresent; //!< True if the transport layer reported chunk data to be present in the buffer + + /** + * \} + */ +} VmbFrame_t; + +/** + * \} + */ + +/** + * \name Save/LoadSettings + * \{ + */ + +/** + * \brief Type of features that are to be saved (persisted) to the XML file when using ::VmbSettingsSave + */ +typedef enum VmbFeaturePersistType +{ + VmbFeaturePersistAll = 0, //!< Save all features to XML, including look-up tables (if possible) + VmbFeaturePersistStreamable = 1, //!< Save only features marked as streamable, excluding look-up tables + VmbFeaturePersistNoLUT = 2 //!< Save all features except look-up tables (default) +} VmbFeaturePersistType; + +/** + * \brief Type for feature persistence; for values see ::VmbFeaturePersistType. + */ +typedef VmbUint32_t VmbFeaturePersist_t; + +/** + * \brief Parameters determining the operation mode of ::VmbSettingsSave and ::VmbSettingsLoad. + */ +typedef enum VmbModulePersistFlagsType +{ + VmbModulePersistFlagsNone = 0x00, //!< Persist/Load features for no module. + VmbModulePersistFlagsTransportLayer = 0x01, //!< Persist/Load the transport layer features. + VmbModulePersistFlagsInterface = 0x02, //!< Persist/Load the interface features. + VmbModulePersistFlagsRemoteDevice = 0x04, //!< Persist/Load the remote device features. + VmbModulePersistFlagsLocalDevice = 0x08, //!< Persist/Load the local device features. + VmbModulePersistFlagsStreams = 0x10, //!< Persist/Load the features of stream modules. + VmbModulePersistFlagsAll = 0xff //!< Persist/Load features for all modules. +} VmbModulePersistFlagsType; + +/** + * \brief Type for module persist flags; for values see VmbModulePersistFlagsType + * + * Use a combination of ::VmbModulePersistFlagsType constants + */ +typedef VmbUint32_t VmbModulePersistFlags_t; + +/** + * \brief A level to use for logging + */ +typedef enum VmbLogLevel +{ + VmbLogLevelNone = 0, //!< Nothing is logged regardless of the severity of the issue + VmbLogLevelError, //!< Only errors are logged + VmbLogLevelDebug, //!< Only error and debug messages are logged + VmbLogLevelWarn, //!< Only error, debug and warn messages are logged + VmbLogLevelTrace, //!< all messages are logged + VmbLogLevelAll = VmbLogLevelTrace, //!< all messages are logged +} VmbLogLevel; + +/** + * \brief The type used for storing the log level + * + * Use a constant from ::VmbLogLevel + */ +typedef VmbUint32_t VmbLogLevel_t; + +/** + * \brief Parameters determining the operation mode of ::VmbSettingsSave and ::VmbSettingsLoad + */ +typedef struct VmbFeaturePersistSettings +{ + /** + * \name In + * \{ + */ + + VmbFeaturePersist_t persistType; //!< Type of features that are to be saved + VmbModulePersistFlags_t modulePersistFlags; //!< Flags specifying the modules to persist/load + VmbUint32_t maxIterations; //!< Number of iterations when loading settings + VmbLogLevel_t loggingLevel; //!< Determines level of detail for load/save settings logging + + /** + * \} + */ +} VmbFeaturePersistSettings_t; + +/** + * \} + */ + +/** + * \name Callbacks + * \{ + */ + +/** + * \brief Invalidation callback type for a function that gets called in a separate thread + * and has been registered with ::VmbFeatureInvalidationRegister(). + * + * While the callback is run, all feature data is atomic. After the callback finishes, + * the feature data may be updated with new values. + * + * Do not spend too much time in this thread; it prevents the feature values + * from being updated from any other thread or the lower-level drivers. + * + * \param[in] handle Handle for an entity that exposes features + * \param[in] name Name of the feature + * \param[in] userContext Pointer to the user context, see ::VmbFeatureInvalidationRegister + */ +typedef void (VMB_CALL* VmbInvalidationCallback)(const VmbHandle_t handle, const char* name, void* userContext); + +/** + * \brief Frame Callback type for a function that gets called in a separate thread + * if a frame has been queued with ::VmbCaptureFrameQueue. + * + * \warning Any operations closing the stream including ::VmbShutdown and ::VmbCameraClose in addition to + * ::VmbCaptureEnd block until any currently active callbacks return. If the callback does not + * return in finite time, the program may not return. + * + * \param[in] cameraHandle Handle of the camera the frame belongs to + * \param[in] streamHandle Handle of the stream the frame belongs to + * \param[in] frame The received frame + */ +typedef void (VMB_CALL* VmbFrameCallback)(const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, VmbFrame_t* frame); + +/** + * \brief Function pointer type to access chunk data + * + * This function should complete as quickly as possible, since it blocks other updates on the + * remote device. + * + * This function should not throw exceptions, even if VmbC is used from C++. Any exception + * thrown will only result in an error code indicating that an exception was thrown. + * + * \param[in] featureAccessHandle A special handle that can be used for accessing features; + * the handle is only valid during the call of the function. + * \param[in] userContext The value the user passed to ::VmbChunkDataAccess. + * + * \return An error to be returned from ::VmbChunkDataAccess in the absence of other errors; + * A custom exit code >= ::VmbErrorCustom can be returned to indicate a failure via + * ::VmbChunkDataAccess return code + */ +typedef VmbError_t(VMB_CALL* VmbChunkAccessCallback)(VmbHandle_t featureAccessHandle, void* userContext); + +/** + * \} + */ + +#ifdef __cplusplus +} +#endif + +#endif // VMBC_TYPE_DEFINITIONS_H_INCLUDE_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCommonTypes.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCommonTypes.h new file mode 100644 index 000000000..7e3615472 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCommonTypes.h @@ -0,0 +1,444 @@ +/*============================================================================= + Copyright (C) 2012 - 2021 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + +------------------------------------------------------------------------------- + + File: VmbCommonTypes.h + +------------------------------------------------------------------------------- + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ + +/** + * \file + * \brief Main header file for the common types of the APIs. + * + * This file describes all necessary definitions for types used within + * the Vmb APIs. These type definitions are designed to be + * portable from other languages and other operating systems. + */ + +#ifndef VMBCOMMONTYPES_H_INCLUDE_ +#define VMBCOMMONTYPES_H_INCLUDE_ + +#ifdef _WIN32 +# include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \name Basic Types + * \{ + */ + +#if defined (_MSC_VER) + + /** + * \brief 8-bit signed integer. + */ + typedef __int8 VmbInt8_t; + + /** + * \brief 8-bit unsigned integer. + */ + typedef unsigned __int8 VmbUint8_t; + + /** + * \brief 16-bit signed integer. + */ + typedef __int16 VmbInt16_t; + + /** + * \brief 16-bit unsigned integer. + */ + typedef unsigned __int16 VmbUint16_t; + + /** + * \brief 32-bit signed integer. + */ + typedef __int32 VmbInt32_t; + + /** + * \brief 32-bit unsigned integer. + */ + typedef unsigned __int32 VmbUint32_t; + + /** + * \brief 64-bit signed integer. + */ + typedef __int64 VmbInt64_t; + + /** + * \brief 64-bit unsigned integer. + */ + typedef unsigned __int64 VmbUint64_t; + +#else + + /** + * \brief 8-bit signed integer. + */ + typedef signed char VmbInt8_t; + + /** + * \brief 8-bit unsigned integer. + */ + typedef unsigned char VmbUint8_t; + + /** + * \brief 16-bit signed integer. + */ + typedef short VmbInt16_t; + + /** + * \brief 16-bit unsigned integer. + */ + typedef unsigned short VmbUint16_t; + + /** + * \brief 32-bit signed integer. + */ + typedef int VmbInt32_t; + + /** + * \brief 32-bit unsigned integer. + */ + typedef unsigned int VmbUint32_t; + + /** + * \brief 64-bit signed integer. + */ + typedef long long VmbInt64_t; + + /** + * \brief 64-bit unsigned integer. + */ + typedef unsigned long long VmbUint64_t; + +#endif + + /** + * \brief Handle, e.g. for a camera. + */ + typedef void* VmbHandle_t; + +#if defined(__cplusplus) || defined(__bool_true_false_are_defined) + + /** + * \brief Standard type for boolean values. + */ + typedef bool VmbBool_t; + +#else + + /** + * \brief Boolean type (equivalent to char). + * + * For values see ::VmbBoolVal + */ + typedef char VmbBool_t; + +#endif + + /** + * \brief enum for bool values. + */ + typedef enum VmbBoolVal + { + VmbBoolTrue = 1, + VmbBoolFalse = 0, + } VmbBoolVal; + + /** + * \brief char type. + */ + typedef unsigned char VmbUchar_t; + +#ifdef _WIN32 + + /** + * \brief Character type used for file paths (Windows uses wchar_t not char). + */ + typedef wchar_t VmbFilePathChar_t; + + /** + * \brief macro for converting a c string literal into a system dependent string literal + * + * Adds L as prefix on Windows and is replaced by the unmodified value on other operating systems. + * + * \code{.c} + * const VmbFilePathChar_t* path = VMB_FILE_PATH_LITERAL("./some/path/tl.cti"); + * \endcode + */ +# define VMB_FILE_PATH_LITERAL(value) L##value + +#else + + /** + * Character type used for file paths + */ + typedef char VmbFilePathChar_t; + + /** + * \brief macro for converting a c string literal into a system dependent string literal + * + * Adds L as prefix on Windows and is replaced by the unmodified value on other operating systems. + * + * \code{.c} + * const VmbFilePathChar_t* path = VMB_FILE_PATH_LITERAL("./some/path/tl.cti"); + * \endcode + */ +# define VMB_FILE_PATH_LITERAL(value) value +#endif + +/** + * \} + */ + +/** + * \name Error Codes + * \{ + */ + + /** + * \brief Error codes, returned by most functions. + */ + typedef enum VmbErrorType + { + VmbErrorSuccess = 0, //!< No error + VmbErrorInternalFault = -1, //!< Unexpected fault in VmbC or driver + VmbErrorApiNotStarted = -2, //!< ::VmbStartup() was not called before the current command + VmbErrorNotFound = -3, //!< The designated instance (camera, feature etc.) cannot be found + VmbErrorBadHandle = -4, //!< The given handle is not valid + VmbErrorDeviceNotOpen = -5, //!< Device was not opened for usage + VmbErrorInvalidAccess = -6, //!< Operation is invalid with the current access mode + VmbErrorBadParameter = -7, //!< One of the parameters is invalid (usually an illegal pointer) + VmbErrorStructSize = -8, //!< The given struct size is not valid for this version of the API + VmbErrorMoreData = -9, //!< More data available in a string/list than space is provided + VmbErrorWrongType = -10, //!< Wrong feature type for this access function + VmbErrorInvalidValue = -11, //!< The value is not valid; either out of bounds or not an increment of the minimum + VmbErrorTimeout = -12, //!< Timeout during wait + VmbErrorOther = -13, //!< Other error + VmbErrorResources = -14, //!< Resources not available (e.g. memory) + VmbErrorInvalidCall = -15, //!< Call is invalid in the current context (e.g. callback) + VmbErrorNoTL = -16, //!< No transport layers are found + VmbErrorNotImplemented = -17, //!< API feature is not implemented + VmbErrorNotSupported = -18, //!< API feature is not supported + VmbErrorIncomplete = -19, //!< The current operation was not completed (e.g. a multiple registers read or write) + VmbErrorIO = -20, //!< Low level IO error in transport layer + VmbErrorValidValueSetNotPresent = -21, //!< The valid value set could not be retrieved, since the feature does not provide this property + VmbErrorGenTLUnspecified = -22, //!< Unspecified GenTL runtime error + VmbErrorUnspecified = -23, //!< Unspecified runtime error + VmbErrorBusy = -24, //!< The responsible module/entity is busy executing actions + VmbErrorNoData = -25, //!< The function has no data to work on + VmbErrorParsingChunkData = -26, //!< An error occurred parsing a buffer containing chunk data + VmbErrorInUse = -27, //!< Something is already in use + VmbErrorUnknown = -28, //!< Error condition unknown + VmbErrorXml = -29, //!< Error parsing XML + VmbErrorNotAvailable = -30, //!< Something is not available + VmbErrorNotInitialized = -31, //!< Something is not initialized + VmbErrorInvalidAddress = -32, //!< The given address is out of range or invalid for internal reasons + VmbErrorAlready = -33, //!< Something has already been done + VmbErrorNoChunkData = -34, //!< A frame expected to contain chunk data does not contain chunk data + VmbErrorUserCallbackException = -35, //!< A callback provided by the user threw an exception + VmbErrorFeaturesUnavailable = -36, //!< The XML for the module is currently not loaded; the module could be in the wrong state or the XML could not be retrieved or could not be parsed properly + VmbErrorTLNotFound = -37, //!< A required transport layer could not be found or loaded + VmbErrorAmbiguous = -39, //!< An entity cannot be uniquely identified based on the information provided + VmbErrorRetriesExceeded = -40, //!< Something could not be accomplished with a given number of retries + VmbErrorInsufficientBufferCount = -41, //!< The operation requires more buffers + VmbErrorCustom = 1, //!< The minimum error code to use for user defined error codes to avoid conflict with existing error codes + } VmbErrorType; + + /** + * \brief Type for an error returned by API methods; for values see ::VmbErrorType. + */ + typedef VmbInt32_t VmbError_t; + +/** + * \} + */ + +/** + * \name Version + * \{ + */ + + /** + * \brief Version information. + */ + typedef struct VmbVersionInfo + { + /** + * \name Out + * \{ + */ + + VmbUint32_t major; //!< Major version number + VmbUint32_t minor; //!< Minor version number + VmbUint32_t patch; //!< Patch version number + + /** + * \} + */ + } VmbVersionInfo_t; + +/** + * \} + */ + + /** + * \name Pixel information + * \{ + */ + + /** + * \brief Indicates if pixel is monochrome or RGB. + */ + typedef enum VmbPixelType + { + VmbPixelMono = 0x01000000, //!< Monochrome pixel + VmbPixelColor = 0x02000000 //!< Pixel bearing color information + } VmbPixelType; + + /** + * \brief Indicates number of bits for a pixel. Needed for building values of ::VmbPixelFormatType. + */ + typedef enum VmbPixelOccupyType + { + VmbPixelOccupy8Bit = 0x00080000, //!< Pixel effectively occupies 8 bits + VmbPixelOccupy10Bit = 0x000A0000, //!< Pixel effectively occupies 10 bits + VmbPixelOccupy12Bit = 0x000C0000, //!< Pixel effectively occupies 12 bits + VmbPixelOccupy14Bit = 0x000E0000, //!< Pixel effectively occupies 14 bits + VmbPixelOccupy16Bit = 0x00100000, //!< Pixel effectively occupies 16 bits + VmbPixelOccupy24Bit = 0x00180000, //!< Pixel effectively occupies 24 bits + VmbPixelOccupy32Bit = 0x00200000, //!< Pixel effectively occupies 32 bits + VmbPixelOccupy48Bit = 0x00300000, //!< Pixel effectively occupies 48 bits + VmbPixelOccupy64Bit = 0x00400000, //!< Pixel effectively occupies 64 bits + } VmbPixelOccupyType; + + /** + * \brief Pixel format types. + * As far as possible, the Pixel Format Naming Convention (PFNC) has been followed, allowing a few deviations. + * If data spans more than one byte, it is always LSB aligned, except if stated differently. + */ + typedef enum VmbPixelFormatType + { + // mono formats + VmbPixelFormatMono8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0001, //!< Monochrome, 8 bits (PFNC: Mono8) + VmbPixelFormatMono10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0003, //!< Monochrome, 10 bits in 16 bits (PFNC: Mono10) + VmbPixelFormatMono10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0046, //!< Monochrome, 10 bits in 16 bits (PFNC: Mono10p) + VmbPixelFormatMono12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0005, //!< Monochrome, 12 bits in 16 bits (PFNC: Mono12) + VmbPixelFormatMono12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x0006, //!< Monochrome, 2x12 bits in 24 bits (GEV:Mono12Packed) + VmbPixelFormatMono12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0047, //!< Monochrome, 2x12 bits in 24 bits (PFNC: MonoPacked) + VmbPixelFormatMono14 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0025, //!< Monochrome, 14 bits in 16 bits (PFNC: Mono14) + VmbPixelFormatMono16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0007, //!< Monochrome, 16 bits (PFNC: Mono16) + + // bayer formats + VmbPixelFormatBayerGR8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0008, //!< Bayer-color, 8 bits, starting with GR line (PFNC: BayerGR8) + VmbPixelFormatBayerRG8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0009, //!< Bayer-color, 8 bits, starting with RG line (PFNC: BayerRG8) + VmbPixelFormatBayerGB8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x000A, //!< Bayer-color, 8 bits, starting with GB line (PFNC: BayerGB8) + VmbPixelFormatBayerBG8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x000B, //!< Bayer-color, 8 bits, starting with BG line (PFNC: BayerBG8) + VmbPixelFormatBayerGR10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000C, //!< Bayer-color, 10 bits in 16 bits, starting with GR line (PFNC: BayerGR10) + VmbPixelFormatBayerRG10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000D, //!< Bayer-color, 10 bits in 16 bits, starting with RG line (PFNC: BayerRG10) + VmbPixelFormatBayerGB10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000E, //!< Bayer-color, 10 bits in 16 bits, starting with GB line (PFNC: BayerGB10) + VmbPixelFormatBayerBG10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000F, //!< Bayer-color, 10 bits in 16 bits, starting with BG line (PFNC: BayerBG10) + VmbPixelFormatBayerGR12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0010, //!< Bayer-color, 12 bits in 16 bits, starting with GR line (PFNC: BayerGR12) + VmbPixelFormatBayerRG12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0011, //!< Bayer-color, 12 bits in 16 bits, starting with RG line (PFNC: BayerRG12) + VmbPixelFormatBayerGB12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0012, //!< Bayer-color, 12 bits in 16 bits, starting with GB line (PFNC: BayerGB12) + VmbPixelFormatBayerBG12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0013, //!< Bayer-color, 12 bits in 16 bits, starting with BG line (PFNC: BayerBG12) + VmbPixelFormatBayerGR12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002A, //!< Bayer-color, 2x12 bits in 24 bits, starting with GR line (GEV:BayerGR12Packed) + VmbPixelFormatBayerRG12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002B, //!< Bayer-color, 2x12 bits in 24 bits, starting with RG line (GEV:BayerRG12Packed) + VmbPixelFormatBayerGB12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002C, //!< Bayer-color, 2x12 bits in 24 bits, starting with GB line (GEV:BayerGB12Packed) + VmbPixelFormatBayerBG12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002D, //!< Bayer-color, 2x12 bits in 24 bits, starting with BG line (GEV:BayerBG12Packed) + VmbPixelFormatBayerGR10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0056, //!< Bayer-color, 10 bits continuous packed, starting with GR line (PFNC: BayerGR10p) + VmbPixelFormatBayerRG10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0058, //!< Bayer-color, 10 bits continuous packed, starting with RG line (PFNC: BayerRG10p) + VmbPixelFormatBayerGB10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0054, //!< Bayer-color, 10 bits continuous packed, starting with GB line (PFNC: BayerGB10p) + VmbPixelFormatBayerBG10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0052, //!< Bayer-color, 10 bits continuous packed, starting with BG line (PFNC: BayerBG10p) + VmbPixelFormatBayerGR12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0057, //!< Bayer-color, 12 bits continuous packed, starting with GR line (PFNC: BayerGR12p) + VmbPixelFormatBayerRG12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0059, //!< Bayer-color, 12 bits continuous packed, starting with RG line (PFNC: BayerRG12p) + VmbPixelFormatBayerGB12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0055, //!< Bayer-color, 12 bits continuous packed, starting with GB line (PFNC: BayerGB12p) + VmbPixelFormatBayerBG12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0053, //!< Bayer-color, 12 bits continuous packed, starting with BG line (PFNC: BayerBG12p) + VmbPixelFormatBayerGR16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x002E, //!< Bayer-color, 16 bits, starting with GR line (PFNC: BayerGR16) + VmbPixelFormatBayerRG16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x002F, //!< Bayer-color, 16 bits, starting with RG line (PFNC: BayerRG16) + VmbPixelFormatBayerGB16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0030, //!< Bayer-color, 16 bits, starting with GB line (PFNC: BayerGB16) + VmbPixelFormatBayerBG16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0031, //!< Bayer-color, 16 bits, starting with BG line (PFNC: BayerBG16) + + // rgb formats + VmbPixelFormatRgb8 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0014, //!< RGB, 8 bits x 3 (PFNC: RGB8) + VmbPixelFormatBgr8 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0015, //!< BGR, 8 bits x 3 (PFNC: BGR8) + VmbPixelFormatRgb10 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0018, //!< RGB, 12 bits in 16 bits x 3 (PFNC: RGB12) + VmbPixelFormatBgr10 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0019, //!< RGB, 12 bits in 16 bits x 3 (PFNC: RGB12) + VmbPixelFormatRgb12 = VmbPixelColor | VmbPixelOccupy48Bit | 0x001A, //!< RGB, 12 bits in 16 bits x 3 (PFNC: RGB12) + VmbPixelFormatBgr12 = VmbPixelColor | VmbPixelOccupy48Bit | 0x001B, //!< RGB, 12 bits in 16 bits x 3 (PFNC: RGB12) + VmbPixelFormatRgb14 = VmbPixelColor | VmbPixelOccupy48Bit | 0x005E, //!< RGB, 14 bits in 16 bits x 3 (PFNC: RGB12) + VmbPixelFormatBgr14 = VmbPixelColor | VmbPixelOccupy48Bit | 0x004A, //!< RGB, 14 bits in 16 bits x 3 (PFNC: RGB12) + VmbPixelFormatRgb16 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0033, //!< RGB, 16 bits x 3 (PFNC: RGB16) + VmbPixelFormatBgr16 = VmbPixelColor | VmbPixelOccupy48Bit | 0x004B, //!< RGB, 16 bits x 3 (PFNC: RGB16) + + // rgba formats + VmbPixelFormatArgb8 = VmbPixelColor | VmbPixelOccupy32Bit | 0x0016, //!< ARGB, 8 bits x 4 (PFNC: RGBa8) + VmbPixelFormatRgba8 = VmbPixelFormatArgb8, //!< RGBA, 8 bits x 4, legacy name + VmbPixelFormatBgra8 = VmbPixelColor | VmbPixelOccupy32Bit | 0x0017, //!< BGRA, 8 bits x 4 (PFNC: BGRa8) + VmbPixelFormatRgba10 = VmbPixelColor | VmbPixelOccupy64Bit | 0x005F, //!< RGBA, 8 bits x 4, legacy name + VmbPixelFormatBgra10 = VmbPixelColor | VmbPixelOccupy64Bit | 0x004C, //!< RGBA, 8 bits x 4, legacy name + VmbPixelFormatRgba12 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0061, //!< RGBA, 8 bits x 4, legacy name + VmbPixelFormatBgra12 = VmbPixelColor | VmbPixelOccupy64Bit | 0x004E, //!< RGBA, 8 bits x 4, legacy name + VmbPixelFormatRgba14 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0063, //!< RGBA, 8 bits x 4, legacy name + VmbPixelFormatBgra14 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0050, //!< RGBA, 8 bits x 4, legacy name + VmbPixelFormatRgba16 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0064, //!< RGBA, 8 bits x 4, legacy name + VmbPixelFormatBgra16 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0051, //!< RGBA, 8 bits x 4, legacy name + + // yuv/ycbcr formats + VmbPixelFormatYuv411 = VmbPixelColor | VmbPixelOccupy12Bit | 0x001E, //!< YUV 4:1:1 with 8 bits (PFNC: YUV411_8_UYYVYY, GEV:YUV411Packed) + VmbPixelFormatYuv422 = VmbPixelColor | VmbPixelOccupy16Bit | 0x001F, //!< YUV 4:2:2 with 8 bits (PFNC: YUV422_8_UYVY, GEV:YUV422Packed) + VmbPixelFormatYuv444 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0020, //!< YUV 4:4:4 with 8 bits (PFNC: YUV8_UYV, GEV:YUV444Packed) + VmbPixelFormatYuv422_8 = VmbPixelColor | VmbPixelOccupy16Bit | 0x0032, //!< YUV 4:2:2 with 8 bits Channel order YUYV (PFNC: YUV422_8) + VmbPixelFormatYCbCr8_CbYCr = VmbPixelColor | VmbPixelOccupy24Bit | 0x003A, //!< YCbCr 4:4:4 with 8 bits (PFNC: YCbCr8_CbYCr) - identical to VmbPixelFormatYuv444 + VmbPixelFormatYCbCr422_8 = VmbPixelColor | VmbPixelOccupy16Bit | 0x003B, //!< YCbCr 4:2:2 8-bit YCbYCr (PFNC: YCbCr422_8) + VmbPixelFormatYCbCr411_8_CbYYCrYY = VmbPixelColor | VmbPixelOccupy12Bit | 0x003C, //!< YCbCr 4:1:1 with 8 bits (PFNC: YCbCr411_8_CbYYCrYY) - identical to VmbPixelFormatYuv411 + VmbPixelFormatYCbCr601_8_CbYCr = VmbPixelColor | VmbPixelOccupy24Bit | 0x003D, //!< YCbCr601 4:4:4 8-bit CbYCrt (PFNC: YCbCr601_8_CbYCr) + VmbPixelFormatYCbCr601_422_8 = VmbPixelColor | VmbPixelOccupy16Bit | 0x003E, //!< YCbCr601 4:2:2 8-bit YCbYCr (PFNC: YCbCr601_422_8) + VmbPixelFormatYCbCr601_411_8_CbYYCrYY = VmbPixelColor | VmbPixelOccupy12Bit | 0x003F, //!< YCbCr601 4:1:1 8-bit CbYYCrYY (PFNC: YCbCr601_411_8_CbYYCrYY) + VmbPixelFormatYCbCr709_8_CbYCr = VmbPixelColor | VmbPixelOccupy24Bit | 0x0040, //!< YCbCr709 4:4:4 8-bit CbYCr (PFNC: YCbCr709_8_CbYCr) + VmbPixelFormatYCbCr709_422_8 = VmbPixelColor | VmbPixelOccupy16Bit | 0x0041, //!< YCbCr709 4:2:2 8-bit YCbYCr (PFNC: YCbCr709_422_8) + VmbPixelFormatYCbCr709_411_8_CbYYCrYY = VmbPixelColor | VmbPixelOccupy12Bit | 0x0042, //!< YCbCr709 4:1:1 8-bit CbYYCrYY (PFNC: YCbCr709_411_8_CbYYCrYY) + VmbPixelFormatYCbCr422_8_CbYCrY = VmbPixelColor | VmbPixelOccupy16Bit | 0x0043, //!< YCbCr 4:2:2 with 8 bits (PFNC: YCbCr422_8_CbYCrY) - identical to VmbPixelFormatYuv422 + VmbPixelFormatYCbCr601_422_8_CbYCrY = VmbPixelColor | VmbPixelOccupy16Bit | 0x0044, //!< YCbCr601 4:2:2 8-bit CbYCrY (PFNC: YCbCr601_422_8_CbYCrY) + VmbPixelFormatYCbCr709_422_8_CbYCrY = VmbPixelColor | VmbPixelOccupy16Bit | 0x0045, //!< YCbCr709 4:2:2 8-bit CbYCrY (PFNC: YCbCr709_422_8_CbYCrY) + VmbPixelFormatYCbCr411_8 = VmbPixelColor | VmbPixelOccupy12Bit | 0x005A, //!< YCbCr 4:1:1 8-bit YYCbYYCr (PFNC: YCbCr411_8) + VmbPixelFormatYCbCr8 = VmbPixelColor | VmbPixelOccupy24Bit | 0x005B, //!< YCbCr 4:4:4 8-bit YCbCr (PFNC: YCbCr8) + + VmbPixelFormatLast, + } VmbPixelFormatType; + + /** + * \brief Type for the pixel format; for values see ::VmbPixelFormatType. + */ + typedef VmbUint32_t VmbPixelFormat_t; + +/** + * \} + */ + +#ifdef __cplusplus +} +#endif + +#endif // VMBCOMMONTYPES_H_INCLUDE_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbConstants.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbConstants.h new file mode 100644 index 000000000..95ebeb690 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbConstants.h @@ -0,0 +1,85 @@ +/*============================================================================= + Copyright (C) 2021 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + +------------------------------------------------------------------------------- + + File: VmbConstants.h + +------------------------------------------------------------------------------- + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ + +/** + * \file + * \brief File containing constants used in the Vmb C API. + */ + +#ifndef VMBCONSTANTS_H_INCLUDE_ +#define VMBCONSTANTS_H_INCLUDE_ + +#ifdef _WIN32 +/** + * \brief the character used to separate file paths in the parameter of ::VmbStartup + */ +#define VMB_PATH_SEPARATOR_CHAR L';' + +/** + * \brief the string used to separate file paths in the parameter of ::VmbStartup + */ +#define VMB_PATH_SEPARATOR_STRING L";" +#else +/** + * \brief the character used to separate file paths in the parameter of ::VmbStartup + */ +#define VMB_PATH_SEPARATOR_CHAR ':' + +/** + * \brief the string used to separate file paths in the parameter of ::VmbStartup + */ +#define VMB_PATH_SEPARATOR_STRING ":" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup SfncNamespaces Sfnc Namespace Constants + * \{ + */ + +/** + * \brief The C string identifying the namespace of features not defined in the SFNC + * standard. + */ +#define VMB_SFNC_NAMESPACE_CUSTOM "Custom" + +/** + * \brief The C string identifying the namespace of features defined in the SFNC + * standard. + */ +#define VMB_SFNC_NAMESPACE_STANDARD "Standard" + +/** + * \} + */ + +#ifdef __cplusplus +} +#endif + +#endif // VMBCONSTANTS_H_INCLUDE_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransform.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransform.h new file mode 100644 index 000000000..77d497eca --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransform.h @@ -0,0 +1,336 @@ +/*============================================================================= + Copyright (C) 2012 - 2021 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + +------------------------------------------------------------------------------- + + File: VmbTransform.h + + Description: Definition of image transform functions for the Vmb APIs. + +------------------------------------------------------------------------------- + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ + +/** + * \file + */ +#ifndef VMB_TRANSFORM_H_ +#define VMB_TRANSFORM_H_ +#ifndef VMB_TRANSFORM +#define VMB_TRANSFORM +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef VMBIMAGETRANSFORM_API +# ifndef VMB_NO_EXPORT +# ifdef VMB_EXPORTS +# if defined(__ELF__) && (defined(__clang__) || defined(__GNUC__)) +# define VMBIMAGETRANSFORM_API __attribute__((visibility("default"))) +# elif defined( __APPLE__ ) || defined(__MACH__) +# define VMBIMAGETRANSFORM_API __attribute__((visibility("default"))) +# else +# ifndef _WIN64 +# define VMBIMAGETRANSFORM_API __declspec(dllexport) __stdcall +# else +# define VMBIMAGETRANSFORM_API __stdcall +# endif +# endif +# else +# if defined (__ELF__) && (defined(__clang__) || defined(__GNUC__)) +# define VMBIMAGETRANSFORM_API +# elif defined( __APPLE__ ) || defined(__MACH__) +# define VMBIMAGETRANSFORM_API +# else +# define VMBIMAGETRANSFORM_API __declspec(dllimport) __stdcall +# endif +# endif +# else +# define VMBIMAGETRANSFORM_API +# endif +#endif + +/** + * \brief Inquire the library version. + * + * \param[out] value Contains the library version (Major,Minor,Sub,Build). + * + * This function can be called at anytime, even before the library is initialized. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter \p value is null. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbGetImageTransformVersion ( VmbUint32_t* value ); + +/** + * \brief Get information about processor supported features. + * + * This should be called before using any SIMD (MMX,SSE) optimized functions. + * + * \param[out] technoInfo Returns the supported SIMD technologies. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter If \p technoInfo is null. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbGetTechnoInfo( VmbTechInfo_t* technoInfo ); + +/** + * \brief Translate an Vmb error code to a human-readable string. + * + * \param[in] errorCode The error code to get a readable string for. + * \param[out] info Pointer to a zero terminated string the error description is written to. + * \param[in] maxInfoLength The size of the \p info buffer. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter \p info is null, or if maxInfoLength is 0. + * + * \retval ::VmbErrorMoreData If \p maxInfoLength is too small to hold the complete information. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbGetErrorInfo(VmbError_t errorCode, + VmbANSIChar_t* info, + VmbUint32_t maxInfoLength ); + +/** + * \brief Get information about the currently loaded Vmb ImageTransform API. + * + * + * \p infoType may be one of the following values: + * - ::VmbAPIInfoAll: Returns all information about the API + * - ::VmbAPIInfoPlatform: Returns information about the platform the API was built for (x86 or x64) + * - ::VmbAPIInfoBuild: Returns info about the API built (debug or release) + * - ::VmbAPIInfoTechnology: Returns info about the supported technologies the API was built for (OpenMP or OpenCL) + * + * \param[in] infoType Type of information to return + * \param[out] info Pointer to a zero terminated string that + * \param[in] maxInfoLength The length of the \p info buffer + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter \p info is null. + * + * \retval ::VmbErrorMoreData If chars are insufficient \p maxInfoLength to hold the complete information. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbGetApiInfoString(VmbAPIInfo_t infoType, + VmbANSIChar_t* info, + VmbUint32_t maxInfoLength ); + +/** + * \brief Set transformation options to a predefined debayering mode. + * + * The default mode is 2x2 debayering. Debayering modes only work for image widths and heights + * divisible by two. + * + * \param[in] debayerMode The mode used for debayering the raw source image. + * + * \param[in,out] transformInfo Parameter that contains information about special + * transform functionality + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter \p transformInfo is null. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbSetDebayerMode(VmbDebayerMode_t debayerMode, + VmbTransformInfo* transformInfo ); + +/** + * \brief Set transformation options to a 3x3 color matrix transformation. + * + * \param[in] matrix Color correction matrix. + * + * \param[in,out] transformInfo Parameter that is filled with information + * about special transform functionality. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter If \p matrix or \p transformInfo are null. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbSetColorCorrectionMatrix3x3(const VmbFloat_t* matrix, + VmbTransformInfo* transformInfo ); + +/** + * \brief Initialize the give VmbTransformInfo with gamma correction information. + * + * \param[in] gamma Float gamma correction to set + * \param[in,out] transformInfo Transform info to set gamma correction to + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter \p transformInfo is null. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbSetGammaCorrection(VmbFloat_t gamma, + VmbTransformInfo* transformInfo ); + +/** + * \brief Set the pixel related info of a VmbImage to the values appropriate for the given pixel format. + * + * A VmbPixelFormat_t can be obtained from Vmb C/C++ APIs frame. + * For displaying images, it is suggested to use ::VmbSetImageInfoFromString() or to look up + * a matching VmbPixelFormat_t. + * + * \param[in] pixelFormat The pixel format describes the pixel format to be used. + * \param[in] width The width of the image in pixels. + * \param[in] height The height of the image in pixels. + * \param[in,out] image A pointer to the image struct to write the info to. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter If \p image is null or one of the members of \p image is invalid. + * + * \retval ::VmbErrorStructSize If the Size member of the image is incorrect. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbSetImageInfoFromPixelFormat(VmbPixelFormat_t pixelFormat, + VmbUint32_t width, + VmbUint32_t height, + VmbImage* image); + +/** + * \brief Set image info member values in VmbImage from string. + * + * This function does not read or write to VmbImage::Data member. + * + * \param[in] imageFormat The string containing the image format. This parameter is case insensitive. + * \param[in] width The width of the image in pixels. + * \param[in] height The height of the image in pixels. + * \param[in,out] image A pointer to the image struct to write the info to. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter \p imageFormat or \p image are null. + * + * \retval ::VmbErrorStructSize The Size member of \p image contains an invalid value. + * + * \retval ::VmbErrorResources The function ran out of memory while processing. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbSetImageInfoFromString(const VmbANSIChar_t* imageFormat, + VmbUint32_t width, + VmbUint32_t height, + VmbImage* image); + +/** + * \brief Set output image dependent on the input image, user specifies pixel layout and bit depth of the out format. + * + * \param[in] inputPixelFormat Input Vmb pixel format + * \param[in] width width of the output image + * \param[in] height height of the output image + * \param[in] outputPixelLayout pixel component layout for output image + * \param[in] bitsPerPixel bit depth of output 8 and 16 supported + * \param[out] outputImage The output image to write the compatible format to. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter \p outputImage is null. + * + * \retval ::VmbErrorStructSize The Size member of \p outputImage contains an invalid size. + * + * \retval ::VmbErrorNotImplemented No suitable transformation is implemented. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbSetImageInfoFromInputParameters(VmbPixelFormat_t inputPixelFormat, + VmbUint32_t width, + VmbUint32_t height, + VmbPixelLayout_t outputPixelLayout, + VmbUint32_t bitsPerPixel, + VmbImage* outputImage); + +/** + * \brief Set output image compatible to input image with given layout and bit depth. + * The output image will have same dimensions as the input image. + * + * \param[in] inputImage The input image with fully initialized image info elements. + * \param[in] outputPixelLayout The desired layout for the output image. + * \param[in] bitsPerPixel The desided bit depth for output image. 8 bit and 16 bit are supported. + * \param[out] outputImage The output image to write the compatible format to. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter \p inputImage or \p outputImage are null, + * or the PixelInfo member of the ImageInfo member of the \p inputImage does not correspond to a supported pixel format. + * + * \retval ::VmbErrorStructSize The Size member of \p outputImage contains an invalid size. + * + * \retval ::VmbErrorNotImplemented No suitable transformation is implemented. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbSetImageInfoFromInputImage(const VmbImage* inputImage, + VmbPixelLayout_t outputPixelLayout, + VmbUint32_t bitsPerPixel, + VmbImage* outputImage); + +/** + * \brief Transform an image from one pixel format to another providing additional transformation options, if necessary. + * + * The transformation is defined by the provided images and the \p parameter. + * + * Create the source and destination image info structure with VmbSetImageInfoFromPixelFormat + * or VmbSetimageInfoFromString and keep those structures as template. + * For calls to transform, simply attach the image to the Data member. + * The optional parameters, when set, are constraints on the transform. + * + * \param[in] source The pointer to source image. + * \param[in,out] destination The pointer to destination image. + * \param[in] parameter An array of transform parameters; may be null. + * \param[in] parameterCount The number of transform parameters. + * + * \return An error code indicating success or the type of error. + * + * \retval ::VmbErrorSuccess The call was successful. + * + * \retval ::VmbErrorBadParameter if any image pointer or their "Data" members is NULL, or + * if "Width" or "Height" don't match between source and destination, or + * if one of the parameters for the conversion does not fit + * + * \retval ::VmbErrorStructSize The Size member of \p source or \p destination contain an invalid value. + * + * \retval ::VmbErrorNotImplemented The transformation from the format of \p source to the format of \p destination is not implemented. + */ +VmbError_t VMBIMAGETRANSFORM_API VmbImageTransform(const VmbImage* source, + VmbImage* destination, + const VmbTransformInfo* parameter, + VmbUint32_t parameterCount); + +#ifdef __cplusplus +} +#endif + +#endif // VMB_TRANSFORM_H_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransformTypes.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransformTypes.h new file mode 100644 index 000000000..c2438470c --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransformTypes.h @@ -0,0 +1,1018 @@ +/*============================================================================= + Copyright (C) 2012 - 2021 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + +------------------------------------------------------------------------------- + + File: VmbTransformTypes.h + + Description: Definition of types used in the Vmb Image Transform library. + +------------------------------------------------------------------------------- + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ + +/** + * \file + */ +#ifndef VMB_TRANSFORM_TYPES_H_ +#define VMB_TRANSFORM_TYPES_H_ + +#include + +/** + * \brief the type of character to use for strings. + */ +typedef char VmbANSIChar_t; + +/** + * \brief The floating point type to use for matrices. + */ +typedef float VmbFloat_t; + +/** + * \brief Enumeration for the Bayer pattern. + */ +typedef enum VmbBayerPattern +{ + VmbBayerPatternRGGB=0, //!< RGGB pattern, red pixel comes first + VmbBayerPatternGBRG, //!< RGGB pattern, green pixel of blue row comes first + VmbBayerPatternGRBG, //!< RGGB pattern, green pixel of red row comes first + VmbBayerPatternBGGR, //!< RGGB pattern, blue pixel comes first + VmbBayerPatternCYGM=128, //!< CYGM pattern, cyan pixel comes first in the first row, green in the second row (of the sensor) + VmbBayerPatternGMCY, //!< CYGM pattern, green pixel comes first in the first row, cyan in the second row (of the sensor) + VmbBayerPatternCYMG, //!< CYGM pattern, cyan pixel comes first in the first row, magenta in the second row (of the sensor) + VmbBayerPatternMGCY, //!< CYGM pattern, magenta pixel comes first in the first row, cyan in the second row (of the sensor) + VmbBayerPatternLAST=255 +} VmbBayerPattern; + +/** + * \brief Type for an error returned by API methods; for values see ::VmbBayerPattern. + */ +typedef VmbUint32_t VmbBayerPattern_t; + +/** + * \brief Enumeration for the endianness. + */ +typedef enum VmbEndianness +{ + VmbEndiannessLittle=0, //!< Little endian data format + VmbEndiannessBig, //!< Big endian data format + VmbEndiannessLast=255 +} VmbEndianness; + +/** + * \brief Type for the endianness; for values see ::VmbEndianness. + */ +typedef VmbUint32_t VmbEndianness_t; + +/** + * \brief Enumeration for the image alignment. + */ +typedef enum VmbAlignment +{ + VmbAlignmentMSB=0, //!< Data is MSB aligned (pppp pppp pppp ....) + VmbAlignmentLSB, //!< Data is LSB aligned (.... pppp pppp pppp) + VmbAlignmentLAST=255 +} VmbAlignment; + +/** + * \brief Enumeration for the image alignment; for values see ::VmbAlignment + */ +typedef VmbUint32_t VmbAlignment_t; + +/** + * \name Library Info + * \defgroup Library Info + * \{ + */ + +/** + * \brief States of the multi media technology support for operating system and processor. + */ +typedef struct VmbSupportState_t +{ + VmbBool_t Processor; //!< technology supported by the processor + VmbBool_t OperatingSystem; //!< technology supported by the OS +} VmbSupportState_t; + +/** + * \brief States of the support for different multimedia technologies + */ +typedef struct VmbTechInfo_t +{ + VmbSupportState_t IntelMMX; //!< INTEL first gen MultiMedia eXtension + VmbSupportState_t IntelSSE; //!< INTEL Streaming SIMD Extension + VmbSupportState_t IntelSSE2; //!< INTEL Streaming SIMD Extension 2 + VmbSupportState_t IntelSSE3; //!< INTEL Streaming SIMD Extension 3 + VmbSupportState_t IntelSSSE3; //!< INTEL Supplemental Streaming SIMD Extension 3 + VmbSupportState_t AMD3DNow; //!< AMD 3DNow +} VmbTechInfo_t; + +/** + * \brief API info types + */ +typedef enum VmbAPIInfo +{ + VmbAPIInfoAll, //!< All the info (platform, build type and technologies) + VmbAPIInfoPlatform, //!< Platform the api was build for + VmbAPIInfoBuild, //!< build type (debug or release) + VmbAPIInfoTechnology, //!< info about special technologies uses in building the API + VmbAPIInfoLast +} VmbAPIInfo; + +/** + * \brief API info type; for values see ::VmbAPIInfo + */ +typedef VmbUint32_t VmbAPIInfo_t; + +/** + * \} + */ + +/** + * \name Pixel Access Structs + * \defgroup Pixel Access Structs + * \{ + */ + +/** + * \brief Structure for accessing data in 12-bit transfer mode. + * + * Two pixel are coded into 3 bytes. + */ +typedef struct Vmb12BitPackedPair_t +{ + VmbUint8_t m_nVal8_1 ; //!< High byte of the first Pixel + VmbUint8_t m_nVal8_1Low : 4; //!< Low nibble of the first pixel + VmbUint8_t m_nVal8_2Low : 4; //!< Low nibble of the second pixel + VmbUint8_t m_nVal8_2 ; //!< High byte of the second pixel +} Vmb12BitPackedPair_t; + +/** + * \brief Struct for accessing data of a 8 bit grayscale image stored as unsigned integer. + * + * This corresponds to ::VmbPixelFormatMono8. + */ +typedef struct VmbMono8_t +{ +#ifdef __cplusplus + typedef VmbUint8_t value_type; +#endif + VmbUint8_t Y; //!< gray part +} VmbMono8_t; + +/** + * \brief Struct for accessing data of a 8 bit grayscale image stored as signed integer. + */ +typedef struct VmbMono8s_t +{ +#ifdef __cplusplus + typedef VmbInt8_t value_type; +#endif + VmbInt8_t Y; //!< gray part +} VmbMono8s_t; + +/** + * \brief Struct for accessing pixel data of a 10 bit mono padded buffer. + * + * The pixel data is LSB aligned and little endianness encoded on little endian systems. + * + * The pixel data is MSB aligned and big endianness encoded on big endian systems. + * + * On little endian systems this corresponds to ::VmbPixelFormatMono10. + */ +typedef struct VmbMono10_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t Y; //!< gray part +} VmbMono10_t; + +/** + * \brief Struct for accessing pixel data of a 12 bit mono padded buffer. + * + * The pixel data is LSB aligned and little endianness encoded on little endian systems. + * + * The pixel data is MSB aligned and big endianness encoded on big endian systems. + * + * On little endian systems this corresponds to ::VmbPixelFormatMono12. + */ +typedef struct VmbMono12_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t Y; //!< gray part +} VmbMono12_t; + +/** + * \brief Struct for accessing pixel data of a 14 bit mono padded buffer. + * + * The pixel data is LSB aligned and little endianness encoded on little endian systems. + * + * The pixel data is MSB aligned and big endianness encoded on big endian systems. + * + * On little endian systems this corresponds to ::VmbPixelFormatMono14. + */ +typedef struct VmbMono14_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t Y; //!< gray part +} VmbMono14_t; + +/** + * \brief Struct for accessing 16 bit grayscale image stored as unsigned integer. + * + * The pixel data is LSB aligned and little endianness encoded on little endian systems. + * + * The pixel data is MSB aligned and big endianness encoded on big endian systems. + * + * On little endian systems this corresponds to ::VmbPixelFormatMono16. + */ +typedef struct VmbMono16_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t Y; //!< gray part +} VmbMono16_t; + +/** + * \brief Struct for accessing 16 bit grayscale image stored as signed integer. + */ +typedef struct VmbMono16s_t +{ +#ifdef __cplusplus + typedef VmbInt16_t value_type; +#endif + VmbInt16_t Y; //!< gray part +} VmbMono16s_t; + +/** + * \brief Structure for accessing RGB data using 8 bit per channel. + * + * This corresponds to ::VmbPixelFormatRgb8 + */ +typedef struct VmbRGB8_t +{ +#ifdef __cplusplus + typedef VmbUint8_t value_type; +#endif + VmbUint8_t R; //!< red part + VmbUint8_t G; //!< green part + VmbUint8_t B; //!< blue part +} VmbRGB8_t; + +/** + * \brief Structure for accessing RGB data using 10 bit per channel padded to 16 bit; 48 bits per pixel are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatRgb10 on little endian systems. + */ +typedef struct VmbRGB10_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t R; //!< red part + VmbUint16_t G; //!< green part + VmbUint16_t B; //!< blue part +} VmbRGB10_t; + +/** + * \brief Structure for accessing RGB data using 12 bit per channel padded to 16 bit; 48 bits per pixel are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatRgb12 on little endian systems. + */ +typedef struct VmbRGB12_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t R; //!< red part + VmbUint16_t G; //!< green part + VmbUint16_t B; //!< blue part +} VmbRGB12_t; + +/** + * \brief Structure for accessing RGB data using 14 bit per channel padded to 16 bit; 48 bits per pixel are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatRgb14 on little endian systems. + */ +typedef struct VmbRGB14_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t R; //!< red part + VmbUint16_t G; //!< green part + VmbUint16_t B; //!< blue part +} VmbRGB14_t; + +/** + * \brief Struct for accessing RGB pixels stored as 16 bit unsigend integer per channel. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatRgb16 on little endian systems. + */ +typedef struct VmbRGB16_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t R; //!< red part + VmbUint16_t G; //!< green part + VmbUint16_t B; //!< blue part +} VmbRGB16_t; + +/** + * \brief Structure for accessing BGR data using 8 bit per channel. + * + * Corresponds to ::VmbPixelFormatBgr8 + */ +typedef struct VmbBGR8_t +{ +#ifdef __cplusplus + typedef VmbUint8_t value_type; +#endif + VmbUint8_t B; //!< blue part + VmbUint8_t G; //!< green part + VmbUint8_t R; //!< red part +} VmbBGR8_t; + +/** + * \brief Structure for accessing BGR data using 10 bit per channel padded to 16 bit; 48 bits per pixel are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatBgr10 on little endian systems. + */ +typedef struct VmbBGR10_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t B; //!< blue part + VmbUint16_t G; //!< green part + VmbUint16_t R; //!< red part +} VmbBGR10_t; + +/** + * \brief Structure for accessing BGR data using 12 bit per channel padded to 16 bit; 48 bits per pixel are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatBgr12 on little endian systems. + */ +typedef struct VmbBGR12_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t B; //!< blue part + VmbUint16_t G; //!< green part + VmbUint16_t R; //!< red part +} VmbBGR12_t; + +/** + * \brief Structure for accessing BGR data using 14 bit per channel padded to 16 bit; 48 bits per pixel are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatBgr14 on little endian systems. + */ +typedef struct VmbBGR14_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t B; //!< blue part + VmbUint16_t G; //!< green part + VmbUint16_t R; //!< red part +} VmbBGR14_t; + +/** + * \brief Structure for accessing BGR data using 16 bit per channel; 48 bits per pixel are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatBgr16 on little endian systems. + */ +typedef struct VmbBGR16_t +{ +#ifdef __cplusplus + typedef VmbUint16_t value_type; +#endif + VmbUint16_t B; //!< blue part + VmbUint16_t G; //!< green part + VmbUint16_t R; //!< red part +} VmbBGR16_t; + +/** + * \brief Structure for accessing RGBA data using 8 bit per channel. + */ +typedef struct VmbRGBA8_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint8_t value_type; +#endif + VmbUint8_t R; //!< red part + VmbUint8_t G; //!< green part + VmbUint8_t B; //!< blue part + VmbUint8_t A; //!< unused +} VmbRGBA8_t; + +/** + * \brief Alias for ::VmbRGBA8_t + */ +typedef VmbRGBA8_t VmbRGBA32_t; + +/** + * \brief Structure for accessing BGRA data using 8 bit per channel. + * + * This corresponds to ::VmbPixelFormatBgra8 + */ +typedef struct VmbBGRA8_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint8_t value_type; +#endif + VmbUint8_t B; //!< blue part + VmbUint8_t G; //!< green part + VmbUint8_t R; //!< red part + VmbUint8_t A; //!< unused +} VmbBGRA8_t; + +/** + * \brief Alias for ::VmbBGRA8_t + */ +typedef VmbBGRA8_t VmbBGRA32_t; + +/** + * \brief Struct for accessing ARGB values stored using a 8 bit unsigned integer per channel. + * + * Corresponds to ::VmbPixelFormatArgb8 + */ +typedef struct VmbARGB8_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint8_t value_type; +#endif + VmbUint8_t A; //!< unused + VmbUint8_t R; //!< red part + VmbUint8_t G; //!< green part + VmbUint8_t B; //!< blue part +} VmbARGB8_t; + +/** + * \brief Alias for ::VmbARGB8_t + */ +typedef VmbARGB8_t VmbARGB32_t; + +/** + * \brief Structure for accessing BGRA data using a 8 bit unsigned integer per channel. + */ +typedef struct VmbABGR8_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint8_t value_type; +#endif + VmbUint8_t A; //!< unused + VmbUint8_t B; //!< blue part + VmbUint8_t G; //!< green part + VmbUint8_t R; //!< red part +} VmbABGR8_t; + +/** + * \brief Alias for ::VmbABGR8_t + */ +typedef VmbABGR8_t VmbABGR32_t; + +/** + * \brief Structure for accessing RGBA data using 10 bit per channel padded to 16 bit; 64 bit are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatRgba10 on little endian systems. + */ +typedef struct VmbRGBA10_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint16_t value_type; +#endif + VmbUint16_t R; //!< red part + VmbUint16_t G; //!< green part + VmbUint16_t B; //!< blue part + VmbUint16_t A; //!< unused +} VmbRGBA10_t; + +/** + * \brief Structure for accessing BGRA data using 10 bit per channel padded to 16 bit; 64 bit are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatBgra10 on little endian systems. + */ +typedef struct VmbBGRA10_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint16_t value_type; +#endif + VmbUint16_t B; //!< blue part + VmbUint16_t G; //!< green part + VmbUint16_t R; //!< red part + VmbUint16_t A; //!< unused +} VmbBGRA10_t; + +/** + * \brief Structure for accessing RGBA data using 12 bit per channel padded to 16 bit; 64 bit are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatRgba12 on little endian systems. + */ +typedef struct VmbRGBA12_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint16_t value_type; +#endif + VmbUint16_t R; //!< red part + VmbUint16_t G; //!< green part + VmbUint16_t B; //!< blue part + VmbUint16_t A; //!< unused +} VmbRGBA12_t; + +/** + * \brief Structure for accessing RGBA data using 14 bit per channel padded to 16 bit; 64 bit are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatRgba14 on little endian systems. + */ +typedef struct VmbRGBA14_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint16_t value_type; +#endif + VmbUint16_t R; //!< red part + VmbUint16_t G; //!< green part + VmbUint16_t B; //!< blue part + VmbUint16_t A; //!< unused +} VmbRGBA14_t; + +/** + * \brief Structure for accessing BGRA data using 12 bit per channel padded to 16 bit; 64 bit are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatBgra12 on little endian systems. + */ +typedef struct VmbBGRA12_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint16_t value_type; +#endif + VmbUint16_t B; //!< blue part + VmbUint16_t G; //!< green part + VmbUint16_t R; //!< red part + VmbUint16_t A; //!< unused +} VmbBGRA12_t; + +/** + * \brief Structure for accessing BGRA data using 14 bit per channel padded to 16 bit; 64 bit are used in total. + * + * Each channel is LSB aligned and little endianness encoded on little endian systems. + * + * Each channel is MSB aligned and big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatBgra14 on little endian systems. + */ +typedef struct VmbBGRA14_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint16_t value_type; +#endif + VmbUint16_t B; //!< blue part + VmbUint16_t G; //!< green part + VmbUint16_t R; //!< red part + VmbUint16_t A; //!< unused +} VmbBGRA14_t; + +/** + * \brief Structure for accessing RGBA data using 16 bit per channel. + * + * Each channel is little endianness encoded on little endian systems. + * + * Each channel is big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatRgba16 on little endian systems. + */ +typedef struct VmbRGBA16_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint16_t value_type; +#endif + VmbUint16_t R; //!< red part + VmbUint16_t G; //!< green part + VmbUint16_t B; //!< blue part + VmbUint16_t A; //!< unused +} VmbRGBA16_t; + +/** + * \brief Alias for ::VmbRGBA16_t + */ +typedef VmbRGBA16_t VmbRGBA64_t; + +/** + * \brief Structure for accessing BGRA data using 16 bit per channel. + * + * Each channel is little endianness encoded on little endian systems. + * + * Each channel is big endianness encoded on big endian systems. + * + * Corresponds to ::VmbPixelFormatBgra16 on little endian systems. + */ +typedef struct VmbBGRA16_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint16_t value_type; +#endif + VmbUint16_t B; //!< blue part + VmbUint16_t G; //!< green part + VmbUint16_t R; //!< red part + VmbUint16_t A; //!< unused +} VmbBGRA16_t; + +/** + * \brief Alias for ::VmbBGRA64_t + */ +typedef VmbBGRA16_t VmbBGRA64_t; + +/** + * \brief Structure for accessing data in the YUV 4:4:4 format (YUV) prosilica component order. + * + * Corresponds to ::VmbPixelFormatYuv444 + */ +typedef struct VmbYUV444_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint8_t value_type; +#endif + VmbUint8_t U; //!< U + VmbUint8_t Y; //!< Luma + VmbUint8_t V; //!< V +} VmbYUV444_t; + +/** + * \brief Structure for accessing data in the YUV 4:2:2 format (UYVY) + * + * This struct provides data for 2 pixels (Y0, U, V) and (Y1, U, V) + * + * Corresponds to ::VmbPixelFormatYuv422 + */ +typedef struct VmbYUV422_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint8_t value_type; +#endif + VmbUint8_t U; //!< the U part for both pixels + VmbUint8_t Y0; //!< the intensity of the first pixel + VmbUint8_t V; //!< the V part for both pixels + VmbUint8_t Y1; //!< the intensity of the second pixel +} VmbYUV422_t; + +/** + * \brief Structure for accessing data in the YUV 4:1:1 format (UYYVYY) + * + * This struct provides data for 2 pixels (Y0, U, V), (Y1, U, V), (Y2, U, V) and (Y3, U, V) + * + * Corresponds to ::VmbPixelFormatYuv411 + */ +typedef struct VmbYUV411_t +{ +#ifdef __cplusplus + /** + * \brief The data type used to store one channel. + */ + typedef VmbUint8_t value_type; +#endif + VmbUint8_t U; //!< the U part for all four pixels + VmbUint8_t Y0; //!< the intensity of the first pixel + VmbUint8_t Y1; //!< the intensity of the second pixel + VmbUint8_t V; //!< the V part for all four pixels + VmbUint8_t Y2; //!< the intensity of the third pixel + VmbUint8_t Y3; //!< the intensity of the fourth pixel +} VmbYUV411_t; + +/** + * \} + */ + +/** + * \brief Image pixel layout information. + */ +typedef enum VmbPixelLayout +{ + VmbPixelLayoutMono, //!< Monochrome pixel data; pixels are padded, if necessary. + VmbPixelLayoutMonoPacked, //!< Monochrome pixel data; pixels some bytes contain data for more than one pixel. + VmbPixelLayoutRaw, //!< Some Bayer pixel format where pixels each byte contains only data for a single pixel. + VmbPixelLayoutRawPacked, //!< Some Bayer pixel format where some bytes contain data for more than one pixel. + VmbPixelLayoutRGB, //!< Non-packed RGB data in channel order R, G, B + VmbPixelLayoutBGR, //!< Non-packed RGB data in channel order B, G, R + VmbPixelLayoutRGBA, //!< Non-packed RGBA data in channel order R, G, B, A + VmbPixelLayoutBGRA, //!< Non-packed RGBA data in channel order B, G, R, A + VmbPixelLayoutYUV411_UYYVYY, //!< YUV data; pixel order for 4 pixels is U, Y0, Y1, V, Y2, Y3 + VmbPixelLayoutYUV411_YYUYYV, //!< YUV data; pixel order for 4 pixels is Y0, Y1, U, Y2, Y3, V + VmbPixelLayoutYUV422_UYVY, //!< YUV data; pixel order for 2 pixels is U, Y0, V, Y1 + VmbPixelLayoutYUV422_YUYV, //!< YUV data; pixel order for 2 pixels is Y0, U, Y1, V + VmbPixelLayoutYUV444_UYV, //!< YUV data; pixel order is U, Y, V + VmbPixelLayoutYUV444_YUV, //!< YUV data; pixel order is Y, U, V + VmbPixelLayoutMonoP, //!< Monochrome pixel data; pixels are padded, if necessary. \todo What is the difference to VmbPixelLayoutMono? + VmbPixelLayoutMonoPl, //!< \todo unused, remove? + VmbPixelLayoutRawP, //!< Some Bayer pixel format where pixels each byte contains only data for a single pixel. \todo What's the difference to VmbPixelLayoutRawPacked? + VmbPixelLayoutRawPl, //!< \todo unused, remove? + VmbPixelLayoutYYCbYYCr411 = VmbPixelLayoutYUV411_YYUYYV, //!< Alias for ::VmbPixelLayoutYUV411_YYUYYV + VmbPixelLayoutCbYYCrYY411 = VmbPixelLayoutYUV411_UYYVYY, //!< Alias for ::VmbPixelLayoutYUV411_UYYVYY + VmbPixelLayoutYCbYCr422 = VmbPixelLayoutYUV422_YUYV, //!< Alias for ::VmbPixelLayoutYUV422_YUYV + VmbPixelLayoutCbYCrY422 = VmbPixelLayoutYUV422_UYVY, //!< Alias for ::VmbPixelLayoutYUV422_UYVY + VmbPixelLayoutYCbCr444 = VmbPixelLayoutYUV444_YUV, //!< Alias for ::VmbPixelLayoutYUV444_YUV + VmbPixelLayoutCbYCr444 = VmbPixelLayoutYUV444_UYV, //!< Alias for ::VmbPixelLayoutYUV444_UYV + + VmbPixelLayoutLAST, +} VmbPixelLayout; + +/** + * \brief Image pixel layout information; for values see ::VmbPixelLayout + */ +typedef VmbUint32_t VmbPixelLayout_t; + +/** + * \brief Image color space information. + */ +typedef enum VmbColorSpace +{ + VmbColorSpaceUndefined, + VmbColorSpaceITU_BT709, //!< \todo color space description + VmbColorSpaceITU_BT601, //!< \todo color space description + +} VmbColorSpace; + +/** + * \brief Image color space information; for values see ::VmbColorSpace + */ +typedef VmbUint32_t VmbColorSpace_t; + +/** + * \brief Image pixel information + */ +typedef struct VmbPixelInfo +{ + VmbUint32_t BitsPerPixel; //!< The number of bits used to store the data for one pixel + VmbUint32_t BitsUsed; //!< The number of bits that actually contain data. + VmbAlignment_t Alignment; //!< Indicates, if the most significant or the least significant bit is filled for pixel formats not using all bits of the buffer to store data. + VmbEndianness_t Endianness; //!< Endianness of the pixel data + VmbPixelLayout_t PixelLayout; //!< Channel order, and in case of YUV formats relative order. + VmbBayerPattern_t BayerPattern; //!< The bayer pattern + VmbColorSpace_t Reserved; //!< Unused member reserved for future use. +} VmbPixelInfo; + +/** + * \brief Struct containing information about the image data in the Data member of a ::VmbImage. + */ +typedef struct VmbImageInfo +{ + VmbUint32_t Width; //!< The width of the image in pixels + VmbUint32_t Height; //!< The height of the image in pixels + VmbInt32_t Stride; //!< \todo description; do we actually use this + VmbPixelInfo PixelInfo; //!< Information about the pixel format +} VmbImageInfo; + +/** + * \brief vmb image type + */ +typedef struct VmbImage +{ + VmbUint32_t Size; //!< The size of this struct; If set incorrectly, API functions will return ::VmbErrorStructSize + void* Data; //!< The image data + VmbImageInfo ImageInfo; //!< Information about pixel format, size, and stride of the image. + +} VmbImage; + +/** + * \brief Transform info for special debayering modes. + */ +typedef enum VmbDebayerMode +{ + VmbDebayerMode2x2, //!< \todo description + VmbDebayerMode3x3, //!< \todo description + VmbDebayerModeLCAA, //!< \todo description + VmbDebayerModeLCAAV, //!< \todo description + VmbDebayerModeYUV422, //!< \todo description +} VmbDebayerMode; + +/** + * \brief Transform info for special debayering mode; for values see ::VmbDebayerMode + */ +typedef VmbUint32_t VmbDebayerMode_t; + +/** + * \name Transformation Parameters + * \defgroup Transformation Parameters + * \{ + */ + +/** + * \brief Transform parameter types. + */ +typedef enum VmbTransformType +{ + VmbTransformTypeNone, //!< Invalid type + VmbTransformTypeDebayerMode, //!< Debayering mode + VmbTransformTypeColorCorrectionMatrix, //!< Color correction matrix + VmbTransformTypeGammaCorrection, //!< Gamma correction + VmbTransformTypeOffset, //!< Offset + VmbTransformTypeGain, //!< Gain +} VmbTransformType; + +/** + * \brief Transform parameter type; for avalues see ::VmbTransformType + */ +typedef VmbUint32_t VmbTransformType_t; + +/** + * \brief Struct definition for holding the debayering mode. + * + * The struct is used to pass the data to ::VmbImageTransform via transform parameter. + * It corresponds to the ::VmbTransformTypeDebayerMode parameter type. + */ +typedef struct VmbTransformParameteDebayer +{ + VmbDebayerMode_t Method; //!< The DeBayering method to use. +} VmbTransformParameterDebayer; + + +/** + * \brief Transform info for color correction using a 3x3 matrix multiplication. + * + * The struct is used to pass the data to ::VmbImageTransform via transform parameter. + * It corresponds to the ::VmbTransformTypeColorCorrectionMatrix parameter type. + * + * \todo what does each index represent; how to get from 2d to 1d? + */ +typedef struct VmbTransformParameterMatrix3x3 +{ + VmbFloat_t Matrix[9]; //!< The color correction matrix to use for the transformation. +} VmbTransformParameterMatrix3x3; + +/** + * \brief Struct definition for a gamma value. + * + * This is currently not supported by ::VmbImageTransform. + * It corresponds to the ::VmbTransformTypeGammaCorrection parameter type. + */ +typedef struct VmbTransformParameterGamma +{ + VmbFloat_t Gamma; //!< The gamma value to use for the transformation +} VmbTransformParameterGamma; + +/** + * \brief Struct definition for holding the offset to pass via transform parameter. + * + * The struct is used to pass the data to ::VmbImageTransform via transform parameter. + * It corresponds to the ::VmbTransformTypeOffset parameter type. + */ +typedef struct VmbTransformParameterOffset +{ + VmbInt32_t Offset; //!< The offset to use for the transformation. +} VmbTransformParameterOffset; + +/** + * \brief Struct definition for holding the gain value. + * + * The struct is used to pass the data to ::VmbImageTransform via transform parameter. + * It corresponds to the ::VmbTransformTypeGain parameter type. + */ +typedef struct VmbTransformParameterGain +{ + VmbUint32_t Gain; //!< The gain to use for the transformation +} VmbTransformParameterGain; + +/** + * \brief Union for possible transformation parameter types. + * + * Each possible data type corresponds to a constant of ::VmbTransformType. + */ +typedef union VmbTransformParameter +{ + VmbTransformParameterMatrix3x3 Matrix3x3; //!< A matrix with 3 rows and 3 columns. + VmbTransformParameterDebayer Debayer; //!< A debayering mode + VmbTransformParameterGamma Gamma; //!< A gamma value + VmbTransformParameterOffset Offset; //!< \todo offset (is this even used?) + VmbTransformParameterGain Gain; //!< A gain value +} VmbTransformParameter; + +/** + * \} + */ + +/** + * \brief Transform info interface structure. + */ +typedef struct VmbTransformInfo +{ + VmbTransformType_t TransformType; //!< The type of the information stored in the Parameter member. + VmbTransformParameter Parameter; //!< The parameter data. +} VmbTransformInfo; + +#endif // VMB_TRANSFORM_TYPES_H_ diff --git a/micromanager.sln b/micromanager.sln index f994b2d34..f96e0037f 100644 --- a/micromanager.sln +++ b/micromanager.sln @@ -468,6 +468,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AtikCamera", "DeviceAdapter EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MPBLaser", "DeviceAdapters\MPBLaser\MPBLaser.vcxproj", "{5E193242-B386-49EF-B592-9ED3552D273D}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AlliedVisionCamera", "DeviceAdapters\AlliedVisionCamera\AlliedVisionCamera.vcxproj", "{12E75CB0-4B48-4D7C-BB26-D928F18488C2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -1406,6 +1408,10 @@ Global {5E193242-B386-49EF-B592-9ED3552D273D}.Debug|x64.Build.0 = Debug|x64 {5E193242-B386-49EF-B592-9ED3552D273D}.Release|x64.ActiveCfg = Release|x64 {5E193242-B386-49EF-B592-9ED3552D273D}.Release|x64.Build.0 = Release|x64 + {12E75CB0-4B48-4D7C-BB26-D928F18488C2}.Debug|x64.ActiveCfg = Debug|x64 + {12E75CB0-4B48-4D7C-BB26-D928F18488C2}.Debug|x64.Build.0 = Debug|x64 + {12E75CB0-4B48-4D7C-BB26-D928F18488C2}.Release|x64.ActiveCfg = Release|x64 + {12E75CB0-4B48-4D7C-BB26-D928F18488C2}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From b533ed5d1c20721afb8757d86d3574e90b03ef5e Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Thu, 29 Jun 2023 20:56:08 +0200 Subject: [PATCH 02/43] Property page support Changes: - Property page support - draft version - Binning support - Exposure time support Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 677 ++++++++++++++++-- .../AlliedVisionCamera/AlliedVisionCamera.h | 138 +++- .../SDK/Loader/LibLoader.cpp | 16 +- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 16 +- 4 files changed, 742 insertions(+), 105 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 3df9abb8e..2d1e71923 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -16,6 +16,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ +#define NOMINMAX // @@ -74,8 +76,6 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) m_frames{}, m_buffer{}, m_bufferSize{0}, - m_imageWidth{}, - m_imageHeight{}, m_isAcquisitionRunning{false} { // [Rule] Create properties here (pre-init only) InitializeDefaultErrorMessages(); @@ -131,9 +131,25 @@ const unsigned char* AlliedVisionCamera::GetImageBuffer() { return reinterpret_cast(m_buffer[0]); } -unsigned AlliedVisionCamera::GetImageWidth() const { return m_imageWidth; } +unsigned AlliedVisionCamera::GetImageWidth() const { + char value[MM::MaxStrLength]; + int ret = GetProperty(g_Width, value); + if (ret != DEVICE_OK) { + return 0; + } -unsigned AlliedVisionCamera::GetImageHeight() const { return m_imageHeight; } + return atoi(value); +} + +unsigned AlliedVisionCamera::GetImageHeight() const { + char value[MM::MaxStrLength]; + int ret = GetProperty(g_Height, value); + if (ret != DEVICE_OK) { + return 0; + } + + return atoi(value); +} unsigned AlliedVisionCamera::GetImageBytesPerPixel() const { // TODO implement @@ -200,46 +216,204 @@ int AlliedVisionCamera::SnapImage() { } long AlliedVisionCamera::GetImageBufferSize() const { return m_bufferSize; } + unsigned AlliedVisionCamera::GetBitDepth() const { // TODO implement return 8; } + int AlliedVisionCamera::GetBinning() const { - // TODO implement - return 1; + char value[MM::MaxStrLength]; + int ret = GetProperty(MM::g_Keyword_Binning, value); + if (ret != DEVICE_OK) { + return 0; + } + + return atoi(value); } + int AlliedVisionCamera::SetBinning(int binSize) { - // TODO implement - return VmbErrorSuccess; + return SetProperty(MM::g_Keyword_Binning, + CDeviceUtils::ConvertToString(binSize)); } -void AlliedVisionCamera::SetExposure(double exp_ms) { - // TODO implement + +int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, + MM::ActionType eAct) { + // Get horizonal binning + VmbFeatureInfo_t featureInfoHorizontal; + VmbError_t err = g_api->VmbFeatureInfoQuery_t( + m_handle, g_BinningHorizontalFeature, &featureInfoHorizontal, + sizeof(featureInfoHorizontal)); + if (VmbErrorSuccess != err) { + return err; + } + + // Get vertical binning + VmbFeatureInfo_t featureInfoVertical; + err = g_api->VmbFeatureInfoQuery_t(m_handle, g_BinningVerticalFeature, + &featureInfoVertical, + sizeof(featureInfoVertical)); + if (VmbErrorSuccess != err) { + return err; + } + + VmbInt64_t minHorizontal, maxHorizontal, minVertical, maxVertical, min, max; + std::string value, valueHorizontal, valueVertical; + bool rMode, wMode; + std::vector strValues; + + // Cast to Property to have an access to setting read/write mode + MM::Property* pChildProperty = (MM::Property*)pProp; + + // Get read/write mode - assume binning horizontal and vertical has the same + // mode + err = g_api->VmbFeatureAccessQuery_t(m_handle, g_BinningVerticalFeature, + &rMode, &wMode); + if (VmbErrorSuccess != err) { + return err; + } + + switch (eAct) { + case MM::ActionType::BeforeGet: + // Get horizontal binning value + err = getFeatureValue(&featureInfoHorizontal, g_BinningHorizontalFeature, + valueHorizontal); + if (VmbErrorSuccess != err) { + return err; + } + // Get vertical binning value + err = getFeatureValue(&featureInfoVertical, g_BinningVerticalFeature, + valueVertical); + if (VmbErrorSuccess != err) { + return err; + } + + // Get min value from these two + min = + std::min(atoi(valueHorizontal.c_str()), atoi(valueVertical.c_str())); + pProp->Set(std::to_string(min).c_str()); + + // Update binning limits + err = g_api->VmbFeatureIntRangeQuery_t( + m_handle, g_BinningHorizontalFeature, &minHorizontal, &maxHorizontal); + if (VmbErrorSuccess != err) { + return err; + } + + err = g_api->VmbFeatureIntRangeQuery_t(m_handle, g_BinningVerticalFeature, + &minVertical, &maxVertical); + if (VmbErrorSuccess != err) { + return err; + } + min = std::max(minHorizontal, minVertical); + max = std::min(maxHorizontal, maxVertical); + + for (VmbInt64_t i = min; i <= max; i++) { + strValues.push_back(std::to_string(i)); + } + SetAllowedValues(pProp->GetName().c_str(), strValues); + // Update access mode + pChildProperty->SetReadOnly(rMode && !wMode); + break; + case MM::ActionType::AfterSet: + pProp->Get(value); + err = setFeatureValue(&featureInfoHorizontal, g_BinningHorizontalFeature, + value); + if (VmbErrorSuccess != err) { + return err; + } + err = setFeatureValue(&featureInfoVertical, g_BinningVerticalFeature, + value); + break; + default: + // nothing + break; + } + + // TODO return uManager error + return err; } + double AlliedVisionCamera::GetExposure() const { - // TODO implement - return 8058.96; + char strExposure[MM::MaxStrLength]; + int ret = GetProperty(MM::g_Keyword_Exposure, strExposure); + if (ret != DEVICE_OK) { + return 0.0; + } + + return strtod(strExposure, nullptr); } + +void AlliedVisionCamera::SetExposure(double exp_ms) { + SetProperty(MM::g_Keyword_Exposure, CDeviceUtils::ConvertToString(exp_ms)); + GetCoreCallback()->OnExposureChanged(this, exp_ms); +} + +int AlliedVisionCamera::OnExposure(MM::PropertyBase* pProp, + MM::ActionType eAct) { + const auto propertyName = pProp->GetName(); + VmbFeatureInfo_t featureInfo; + VmbError_t err = g_api->VmbFeatureInfoQuery_t( + m_handle, g_ExposureFeature, &featureInfo, sizeof(featureInfo)); + if (VmbErrorSuccess != err) { + return err; + } + + std::string value; + bool rMode, wMode; + err = g_api->VmbFeatureAccessQuery_t(m_handle, propertyName.c_str(), &rMode, + &wMode); + MM::Property* pChildProperty = (MM::Property*)pProp; + + switch (eAct) { + case MM::ActionType::BeforeGet: + // Update limits + setAllowedValues(&featureInfo); + // Update access mode + pChildProperty->SetReadOnly(rMode && !wMode); + // Update value + err = getFeatureValue(&featureInfo, g_ExposureFeature, value); + pProp->Set(value.c_str()); + break; + case MM::ActionType::AfterSet: + pProp->Get(value); + err = setFeatureValue(&featureInfo, g_ExposureFeature, value); + break; + default: + // nothing + break; + } + + // TODO return uManager error + return err; +} + int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) { // TODO implement return VmbErrorSuccess; } + int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, unsigned& ySize) { // TODO implement return VmbErrorSuccess; } + int AlliedVisionCamera::ClearROI() { // TODO implement return 0; } + int AlliedVisionCamera::IsExposureSequenceable(bool& isSequenceable) const { // TODO implement return VmbErrorSuccess; } + void AlliedVisionCamera::GetName(char* name) const { CDeviceUtils::CopyLimitedString(name, m_cameraName.c_str()); } + bool AlliedVisionCamera::IsCapturing() { return m_isAcquisitionRunning; } void AlliedVisionCamera::setApiErrorMessages() { @@ -255,7 +429,6 @@ void AlliedVisionCamera::setApiErrorMessages() { VmbError_t AlliedVisionCamera::getCamerasList() { VmbUint32_t camNum; - // Get the number of connected cameras first VmbError_t err = g_api->VmbCamerasList_t(nullptr, 0, &camNum, 0); if (VmbErrorSuccess == err) { @@ -278,17 +451,7 @@ VmbError_t AlliedVisionCamera::getCamerasList() { } VmbError_t AlliedVisionCamera::resizeImageBuffer() { - auto err = g_api->VmbFeatureIntGet_t(m_handle, "Width", &m_imageWidth); - if (err != VmbErrorSuccess) { - return err; - } - - err = g_api->VmbFeatureIntGet_t(m_handle, "Height", &m_imageHeight); - if (err != VmbErrorSuccess) { - return err; - } - - err = g_api->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); + VmbError_t err = g_api->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); if (err != VmbErrorSuccess) { return err; } @@ -298,77 +461,108 @@ VmbError_t AlliedVisionCamera::resizeImageBuffer() { m_buffer[i] = new VmbUint8_t[m_bufferSize]; } - return VmbErrorSuccess; + return err; } -int AlliedVisionCamera::OnPixelTypeChanged(MM::PropertyBase* pProp, - MM::ActionType eAct) { +int AlliedVisionCamera::OnPixelType(MM::PropertyBase* pProp, + MM::ActionType eAct) { // TODO implement - resizeImageBuffer(); return 0; } -int AlliedVisionCamera::OnBinningChanged(MM::PropertyBase* pProp, - MM::ActionType eAct) { - // TODO implement - resizeImageBuffer(); - return 0; -} +int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, + MM::ActionType eAct) { + const auto propertyName = pProp->GetName(); + VmbFeatureInfo_t featureInfo; + VmbError_t err = g_api->VmbFeatureInfoQuery_t( + m_handle, propertyName.c_str(), &featureInfo, sizeof(featureInfo)); + if (VmbErrorSuccess != err) { + return err; + } -VmbError_t AlliedVisionCamera::createPropertyFromFeature( - const VmbFeatureInfo_t* feature) { - // TODO - // Implemnet onProperyChanged for some properties and buffer resize - // Implement readOnly/WriteOnly reading - if (feature == nullptr) { - return VmbErrorInvalidValue; + std::string value{}; + bool rMode, wMode; + err = g_api->VmbFeatureAccessQuery_t(m_handle, propertyName.c_str(), &rMode, + &wMode); + MM::Property* pChildProperty = (MM::Property*)pProp; + switch (eAct) { + case MM::ActionType::BeforeGet: + // Update limits + setAllowedValues(&featureInfo); + // Update access mode + pChildProperty->SetReadOnly(rMode && !wMode); + // Update value + //TODO error handling + getFeatureValue(&featureInfo, propertyName.c_str(), value); + pProp->Set(value.c_str()); + break; + case MM::ActionType::AfterSet: + // Update value + pProp->Get(value); + // TODO error handling + setFeatureValue(&featureInfo, propertyName.c_str(), value); + break; + default: + // nothing + break; } + return err; +} + +VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, + const char* featureName, + std::string& value) { VmbError_t err = VmbErrorSuccess; - switch (feature->featureDataType) { + switch (featureInfo->featureDataType) { case VmbFeatureDataBool: { - VmbBool_t value; - err = g_api->VmbFeatureBoolGet_t(m_handle, feature->name, &value); - if (VmbErrorSuccess == err) { - CreateIntegerProperty(feature->name, value, true, nullptr); + VmbBool_t out; + err = g_api->VmbFeatureBoolGet_t(m_handle, featureName, &out); + if (err != VmbErrorSuccess) { + break; } + value = std::to_string(out); break; } case VmbFeatureDataEnum: { - char const* value = nullptr; - err = g_api->VmbFeatureEnumGet_t(m_handle, feature->name, &value); - if (VmbErrorSuccess == err) { - CreateStringProperty(feature->name, value, true, nullptr); + const char* out = nullptr; + err = g_api->VmbFeatureEnumGet_t(m_handle, featureName, &out); + if (err != VmbErrorSuccess) { + break; } + value = std::string(out); break; } case VmbFeatureDataFloat: { - double value; - err = g_api->VmbFeatureFloatGet_t(m_handle, feature->name, &value); - if (err == VmbErrorSuccess) { - CreateFloatProperty(feature->name, value, true, nullptr); + double out; + err = g_api->VmbFeatureFloatGet_t(m_handle, featureName, &out); + if (err != VmbErrorSuccess) { + break; } + value = std::to_string(out); break; } case VmbFeatureDataInt: { - VmbInt64_t value; - err = g_api->VmbFeatureIntGet_t(m_handle, feature->name, &value); - if (err == VmbErrorSuccess) { - CreateIntegerProperty(feature->name, value, true, nullptr); + VmbInt64_t out; + err = g_api->VmbFeatureIntGet_t(m_handle, featureName, &out); + if (err != VmbErrorSuccess) { + break; } + value = std::to_string(out); break; } case VmbFeatureDataString: { VmbUint32_t size = 0; - err = g_api->VmbFeatureStringGet_t(m_handle, feature->name, nullptr, 0, + err = g_api->VmbFeatureStringGet_t(m_handle, featureName, nullptr, 0, &size); if (VmbErrorSuccess == err && size > 0) { std::shared_ptr buff = std::shared_ptr(new char[size]); - err = g_api->VmbFeatureStringGet_t(m_handle, feature->name, buff.get(), + err = g_api->VmbFeatureStringGet_t(m_handle, featureName, buff.get(), size, &size); - if (VmbErrorSuccess == err) { - CreateStringProperty(feature->name, buff.get(), true, nullptr); + if (err != VmbErrorSuccess) { + break; } + value = std::string(buff.get()); } break; } @@ -377,7 +571,333 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( case VmbFeatureDataRaw: case VmbFeatureDataNone: default: - err = VmbErrorFeaturesUnavailable; + // nothing + break; + } + return err; +} + +VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, + const char* featureName, + std::string& value) { + VmbError_t err = VmbErrorSuccess; + std::stringstream ss(value); + + switch (featureInfo->featureDataType) { + case VmbFeatureDataBool: { + VmbBool_t out; + ss >> out; + err = g_api->VmbFeatureBoolSet_t(m_handle, featureName, out); + break; + } + case VmbFeatureDataEnum: { + err = g_api->VmbFeatureEnumSet_t(m_handle, featureName, value.c_str()); + break; + } + case VmbFeatureDataFloat: { + double out; + ss >> out; + err = g_api->VmbFeatureFloatSet_t(m_handle, featureName, out); + break; + } + case VmbFeatureDataInt: { + VmbInt64_t out; + ss >> out; + err = g_api->VmbFeatureIntSet_t(m_handle, featureName, out); + break; + } + case VmbFeatureDataString: { + err = g_api->VmbFeatureStringSet_t(m_handle, featureName, value.c_str()); + break; + } + case VmbFeatureDataCommand: + case VmbFeatureDataUnknown: + case VmbFeatureDataRaw: + case VmbFeatureDataNone: + default: + // nothing + break; + } + return err; +} + +VmbError_t AlliedVisionCamera::createPropertyFromFeature( + const VmbFeatureInfo_t* feature, MM::ActionFunctor* callback, + const char* propertyName, bool skipVmbCallback) { + if (feature == nullptr) { + return VmbErrorInvalidValue; + } + + auto featureName = feature->name; + auto propName = (propertyName != nullptr) ? propertyName : featureName; + VmbError_t err = VmbErrorSuccess; + + if (!skipVmbCallback) { + // Vmb callback for given feature + auto vmbCallback = [](VmbHandle_t handle, const char* name, + void* userContext) { + AlliedVisionCamera* camera = + reinterpret_cast(userContext); + camera->UpdateProperty(name); + }; + // Register VMb callback + err = g_api->VmbFeatureInvalidationRegister_t(m_handle, featureName, + vmbCallback, this); + if (err != VmbErrorSuccess) { + return err; + } + } + + if (HasProperty(propName)) { + // Already exist + return err; + } + + switch (feature->featureDataType) { + case VmbFeatureDataBool: { + CreateIntegerProperty(propName, 0, true, callback); + break; + } + case VmbFeatureDataEnum: { + CreateStringProperty(propName, "", true, callback); + break; + } + case VmbFeatureDataFloat: { + CreateFloatProperty(propName, 0.0, true, callback); + break; + } + case VmbFeatureDataInt: { + CreateIntegerProperty(propName, 0, true, callback); + break; + } + case VmbFeatureDataString: { + CreateStringProperty(propName, "", true, callback); + break; + } + case VmbFeatureDataCommand: + case VmbFeatureDataUnknown: + case VmbFeatureDataRaw: + case VmbFeatureDataNone: + default: + // nothing + break; + } + + return err; +} + +VmbError_t AlliedVisionCamera::createCoreProperties() { + VmbError_t err = VmbErrorSuccess; + //=== Create PIXEL_TYPE from PIXEL_FORMAT + { + VmbFeatureInfo_t feature; + err = g_api->VmbFeatureInfoQuery_t(m_handle, g_PixelFormatFeature, &feature, + sizeof(VmbFeatureInfo_t)); + if (err != VmbErrorSuccess) { + return err; + } + // uManager callback + CPropertyAction* callback = + new CPropertyAction(this, &AlliedVisionCamera::OnPixelType); + err = createPropertyFromFeature(&feature, callback, MM::g_Keyword_PixelType, + true); + if (err != VmbErrorSuccess) { + return err; + } + + err = setAllowedValues(&feature, MM::g_Keyword_PixelType); + if (err != VmbErrorSuccess) { + return err; + } + + // Vmb callback + auto vmbCallback = [](VmbHandle_t handle, const char* name, + void* userContext) { + AlliedVisionCamera* camera = + reinterpret_cast(userContext); + camera->UpdateProperty(MM::g_Keyword_PixelType); + }; + err = g_api->VmbFeatureInvalidationRegister_t( + m_handle, g_PixelFormatFeature, vmbCallback, this); + if (err != VmbErrorSuccess) { + return err; + } + } + + //=== Create EXPOSURE from EXPOSURE_TIME + { + VmbFeatureInfo_t feature; + err = g_api->VmbFeatureInfoQuery_t(m_handle, g_ExposureFeature, &feature, + sizeof(VmbFeatureInfo_t)); + if (err != VmbErrorSuccess) { + return err; + } + + // uManager callback + CPropertyAction* callback = + new CPropertyAction(this, &AlliedVisionCamera::OnExposure); + err = createPropertyFromFeature(&feature, callback, MM::g_Keyword_Exposure, + true); + if (err != VmbErrorSuccess) { + return err; + } + + err = setAllowedValues(&feature, MM::g_Keyword_Exposure); + if (err != VmbErrorSuccess) { + return err; + } + + // Vmb callback + auto vmbCallback = [](VmbHandle_t handle, const char* name, + void* userContext) { + AlliedVisionCamera* camera = + reinterpret_cast(userContext); + camera->UpdateProperty(MM::g_Keyword_Exposure); + }; + + err = g_api->VmbFeatureInvalidationRegister_t(m_handle, g_ExposureFeature, + vmbCallback, this); + if (err != VmbErrorSuccess) { + return err; + } + } + + //=== Create BINNING from BINNING_HORIZONTAL and BINNING_VERTICAL + { + VmbFeatureInfo_t feature; + err = g_api->VmbFeatureInfoQuery_t(m_handle, g_BinningHorizontalFeature, + &feature, sizeof(VmbFeatureInfo_t)); + if (err != VmbErrorSuccess) { + return err; + } + + // uManager callback + CPropertyAction* callback = + new CPropertyAction(this, &AlliedVisionCamera::OnBinning); + err = createPropertyFromFeature(&feature, callback, MM::g_Keyword_Binning, + true); + if (err != VmbErrorSuccess) { + return err; + } + + // Set limits for BINNING + VmbInt64_t minHorizontal, maxHorizontal, minVertical, maxVertical; + err = g_api->VmbFeatureIntRangeQuery_t(m_handle, g_BinningHorizontalFeature, + &minHorizontal, &maxHorizontal); + if (VmbErrorSuccess != err) { + return err; + } + + err = g_api->VmbFeatureIntRangeQuery_t(m_handle, g_BinningVerticalFeature, + &minVertical, &maxVertical); + if (VmbErrorSuccess != err) { + return err; + } + auto min = std::max(minHorizontal, minVertical); + auto max = std::min(maxHorizontal, maxVertical); + + std::vector strValues; + for (VmbInt64_t i = min; i <= max; i++) { + strValues.push_back(std::to_string(i)); + } + + SetAllowedValues(MM::g_Keyword_Binning, strValues); + + // Vmb callback for horizontal binning + auto vmbCallbackHorizontal = [](VmbHandle_t handle, const char* name, + void* userContext) { + AlliedVisionCamera* camera = + reinterpret_cast(userContext); + camera->UpdateProperty(MM::g_Keyword_Binning); + }; + + err = g_api->VmbFeatureInvalidationRegister_t( + m_handle, g_BinningHorizontalFeature, vmbCallbackHorizontal, this); + if (err != VmbErrorSuccess) { + return err; + } + + // Vmb callback for vertical binning + auto vmbCallbackVertical = [](VmbHandle_t handle, const char* name, + void* userContext) { + AlliedVisionCamera* camera = + reinterpret_cast(userContext); + camera->UpdateProperty(MM::g_Keyword_Binning); + }; + + err = g_api->VmbFeatureInvalidationRegister_t( + m_handle, g_BinningVerticalFeature, vmbCallbackVertical, this); + if (err != VmbErrorSuccess) { + return err; + } + } + + return err; +} + +VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, + const char* propertyName) { + if (feature == nullptr) { + return VmbErrorInvalidValue; + } + + auto propName = (propertyName != nullptr) ? propertyName : feature->name; + VmbError_t err = VmbErrorSuccess; + + switch (feature->featureDataType) { + case VmbFeatureDataBool: { + // TODO check if possible values needs to be set here + break; + } + case VmbFeatureDataFloat: { + double min = 0; + double max = 0; + err = g_api->VmbFeatureFloatRangeQuery_t(m_handle, feature->name, &min, + &max); + if (VmbErrorSuccess != err) { + return err; + } + + err = SetPropertyLimits(propName, min, max); + break; + } + case VmbFeatureDataEnum: { + std::array values; + std::vector strValues; + VmbUint32_t valuesNum = 0; + err = g_api->VmbFeatureEnumRangeQuery_t( + m_handle, feature->name, values.data(), MM::MaxStrLength, &valuesNum); + if (VmbErrorSuccess != err) { + return err; + } + + for (size_t i = 0; i < valuesNum; i++) { + strValues.push_back(values[i]); + } + SetAllowedValues(propName, strValues); + + break; + } + case VmbFeatureDataInt: { + VmbInt64_t min = 0; + VmbInt64_t max = 0; + err = + g_api->VmbFeatureIntRangeQuery_t(m_handle, feature->name, &min, &max); + if (VmbErrorSuccess != err) { + return err; + } + + err = SetPropertyLimits(propName, min, max); + break; + } + case VmbFeatureDataString: { + break; + } + case VmbFeatureDataRaw: + case VmbFeatureDataCommand: + case VmbFeatureDataNone: + default: + // nothing break; } @@ -394,24 +914,31 @@ VmbError_t AlliedVisionCamera::setupProperties() { std::shared_ptr features = std::shared_ptr(new VmbFeatureInfo_t[featureCount]); - err = g_api->VmbFeaturesList_t(m_handle, features.get(), featureCount, &featureCount, sizeof(VmbFeatureInfo_t)); - if (err != VmbErrorSuccess) { return err; } + // TODO handle error + err = createCoreProperties(); + const VmbFeatureInfo_t* end = features.get() + featureCount; for (VmbFeatureInfo_t* feature = features.get(); feature != end; ++feature) { - std::stringstream ss; - ss << "/// Feature Name: " << feature->name << "\n"; - ss << "/// Display Name: " << feature->displayName << "\n"; - ss << "/// Tooltip: " << feature->tooltip << "\n"; - ss << "/// Description: " << feature->description << "\n"; - ss << "/// SNFC Namespace: " << feature->sfncNamespace << "\n"; - LogMessage(ss.str().c_str()); - createPropertyFromFeature(feature); + auto featureName = std::string(feature->name); + // Skip these features as they are mapped to the Core Properties + if (featureName == std::string(g_PixelFormatFeature) || + featureName == std::string(g_BinningHorizontalFeature) || + featureName == std::string(g_BinningVerticalFeature) || + featureName == std::string(g_ExposureFeature)) { + continue; + } + + // uManager callback + CPropertyAction* callback = + new CPropertyAction(this, &AlliedVisionCamera::onProperty); + // TODO handle error + err = createPropertyFromFeature(feature, callback); } } @@ -512,8 +1039,8 @@ void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { md.put("Camera", m_cameraName); // TODO implement parameters - auto err = GetCoreCallback()->InsertImage(this, buffer, m_imageWidth, - m_imageHeight, 1, 1, + auto err = GetCoreCallback()->InsertImage(this, buffer, GetImageWidth(), + GetImageHeight(), 1, 1, md.Serialize().c_str()); if (err == DEVICE_BUFFER_OVERFLOW) { diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index a6b208606..8e3866c05 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -20,25 +20,39 @@ #define ALLIEDVISIONCAMERA_H #include +#include +#include #include "DeviceBase.h" #include "Loader/LibLoader.h" /** * @brief Pointer to the Vimba API -*/ + */ static std::unique_ptr g_api; +/////////////////////////////////////////////////////////////////////////////// +// STATIC FEATURE NAMES (FROM VIMBA) +/////////////////////////////////////////////////////////////////////////////// +static constexpr const char* g_PixelFormatFeature = "PixelFormat"; +static constexpr const char* g_ExposureFeature = "ExposureTime"; +static constexpr const char* g_BinningHorizontalFeature = "BinningHorizontal"; +static constexpr const char* g_BinningVerticalFeature = "BinningVertical"; +static constexpr const char* g_Width = "Width"; +static constexpr const char* g_Height = "Height"; + /** * @brief Main Allied Vision Camera class -*/ + */ class AlliedVisionCamera : public CCameraBase { + /////////////////////////////////////////////////////////////////////////////// // PUBLIC + /////////////////////////////////////////////////////////////////////////////// public: /** * @brief Contructor of Allied Vision Camera * @param[in] deviceName Device name - */ + */ AlliedVisionCamera(const char* deviceName); /** * @brief Allied Vision Camera destructor @@ -48,10 +62,12 @@ class AlliedVisionCamera : public CCameraBase { /** * @brief Get connected camera list * @return VmbError_t - */ + */ static VmbError_t getCamerasList(); - // API Methods + /////////////////////////////////////////////////////////////////////////////// + // uMANAGER API METHODS + /////////////////////////////////////////////////////////////////////////////// int Initialize() override; int Shutdown() override; const unsigned char* GetImageBuffer() override; @@ -77,56 +93,122 @@ class AlliedVisionCamera : public CCameraBase { int StopSequenceAcquisition() override; bool IsCapturing() override; - // Callbacks - int OnPixelTypeChanged(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnBinningChanged(MM::PropertyBase* pProp, MM::ActionType eAct); - - // Static variables - static constexpr const VmbUint8_t MAX_FRAMES = 7; - + /////////////////////////////////////////////////////////////////////////////// + // uMANAGER CALLBACKS + /////////////////////////////////////////////////////////////////////////////// + int OnPixelType(MM::PropertyBase* pProp, + MM::ActionType eAct); //!<< PixelType property callback + int OnBinning(MM::PropertyBase* pProp, + MM::ActionType eAct); //!<< Binning property callback + int OnExposure(MM::PropertyBase* pProp, + MM::ActionType eAct); //!<< Exposure property callback + int onProperty(MM::PropertyBase* pProp, + MM::ActionType eAct); //!<< General property callback + + /////////////////////////////////////////////////////////////////////////////// // PRIVATE + /////////////////////////////////////////////////////////////////////////////// private: + // Static variables + static constexpr const VmbUint8_t MAX_FRAMES = + 7; //!<< Max frame number in the buffer + /** * @brief Setup error messages for Vimba API - */ + */ void setApiErrorMessages(); /** * @brief Resize all buffers for image frames * @return VmbError_t - */ + */ VmbError_t resizeImageBuffer(); /** * @brief Setup uManager properties from Vimba features * @return VmbError_t - */ + */ VmbError_t setupProperties(); /** * @brief Helper method to create single uManager property from Vimba feature - * @param[in] feature Pointer to the Vimba feature + * @param[in] feature Pointer to the Vimba feature + * @return VmbError_t + */ + /** + * @brief Helper method to create single uManager property from Vimba feature + * @param[in] feature Pointer to the Vimba feature + * @param[in] callback uManager callback for given property + * @param[in] propertyName uManager propery name (if differs from + * feature name). By default nullptr + * @param[in] skipVmbCallback If set to true, VmbCallback will not be + * added to this feature. By default false + * @return VmbError_t + */ + VmbError_t createPropertyFromFeature(const VmbFeatureInfo_t* feature, + MM::ActionFunctor* callback, + const char* propertyName = nullptr, + bool skipVmbCallback = false); + + /** + * @brief Helper method to create core properties from feature. * @return VmbError_t - */ - VmbError_t createPropertyFromFeature(const VmbFeatureInfo_t* feature); + * + * It is used to create properties which names does not match to the Vimba + * feature. As example these are Binning, Exposure, PixelType + */ + VmbError_t createCoreProperties(); + + /** + * @brief Helper method to set allowed values for given property, based on + * its feature type + * @param[in] feature Vimba feature name + * @param[in] propertyName uManager propery name (if differs from + * feature name). By default nullptr + * @return + */ + VmbError_t setAllowedValues(const VmbFeatureInfo_t* feature, + const char* propertyName = nullptr); /** * @brief Insert ready frame to the uManager * @param[in] frame Pointer to the frame - */ + */ void insertFrame(VmbFrame_t* frame); - // MEMBERS - VmbHandle_t m_handle; // m_frames; // m_buffer; // m_frames; // m_buffer; // Date: Fri, 7 Jul 2023 17:49:46 +0200 Subject: [PATCH 03/43] Property browser and refactoring Changes: - Code refactoring - Property browser fixes and improvements Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 968 +++++++++--------- .../AlliedVisionCamera/AlliedVisionCamera.h | 69 +- .../AlliedVisionCamera.vcxproj | 2 + .../AlliedVisionCamera.vcxproj.filters | 6 + .../AlliedVisionCamera/PropertyItem.cpp | 5 + .../AlliedVisionCamera/PropertyItem.h | 43 + .../SDK/Loader/LibLoader.cpp | 10 +- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 17 +- 8 files changed, 596 insertions(+), 524 deletions(-) create mode 100644 DeviceAdapters/AlliedVisionCamera/PropertyItem.cpp create mode 100644 DeviceAdapters/AlliedVisionCamera/PropertyItem.h diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 2d1e71923..07afa78b6 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -30,6 +30,23 @@ #include "ModuleInterface.h" #include "VmbC/VmbC.h" +/////////////////////////////////////////////////////////////////////////////// +// STATIC VALUES +/////////////////////////////////////////////////////////////////////////////// +const std::unordered_map + AlliedVisionCamera::m_featureToProperty = { + {g_PixelFormatFeature, MM::g_Keyword_PixelType}, + {g_ExposureFeature, MM::g_Keyword_Exposure}, + {g_BinningHorizontalFeature, MM::g_Keyword_Binning}, + {g_BinningVerticalFeature, MM::g_Keyword_Binning}}; + +const std::unordered_multimap + AlliedVisionCamera::m_propertyToFeature = { + {MM::g_Keyword_PixelType, g_PixelFormatFeature}, + {MM::g_Keyword_Exposure, g_ExposureFeature}, + {MM::g_Keyword_Binning, g_BinningHorizontalFeature}, + {MM::g_Keyword_Binning, g_BinningVerticalFeature}}; + /////////////////////////////////////////////////////////////////////////////// // Exported MMDevice API /////////////////////////////////////////////////////////////////////////////// @@ -107,6 +124,7 @@ int AlliedVisionCamera::Initialize() { } // Init properties and buffer + // TODO handle error setupProperties(); resizeImageBuffer(); @@ -127,92 +145,172 @@ int AlliedVisionCamera::Shutdown() { return DEVICE_OK; } -const unsigned char* AlliedVisionCamera::GetImageBuffer() { - return reinterpret_cast(m_buffer[0]); +void AlliedVisionCamera::setApiErrorMessages() { + SetErrorText(VmbErrorApiNotStarted, "Vimba X API not started"); + SetErrorText(VmbErrorNotFound, "Device cannot be found"); + SetErrorText(VmbErrorDeviceNotOpen, "Device cannot be opened"); + SetErrorText(VmbErrorBadParameter, + "Invalid parameter passed to the function"); + SetErrorText(VmbErrorNotImplemented, "Feature not implemented"); + SetErrorText(VmbErrorNotSupported, "Feature not supported"); + SetErrorText(VmbErrorUnknown, "Unknown error"); + SetErrorText(VmbErrorInvalidValue, + "The value is not valid: either out of bounds or not an " + "increment of the minimum"); } -unsigned AlliedVisionCamera::GetImageWidth() const { - char value[MM::MaxStrLength]; - int ret = GetProperty(g_Width, value); - if (ret != DEVICE_OK) { - return 0; +VmbError_t AlliedVisionCamera::setupProperties() { + VmbUint32_t featureCount = 0; + VmbError_t err = g_api->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, + sizeof(VmbFeatureInfo_t)); + if (err != VmbErrorSuccess || !featureCount) { + return err; } - return atoi(value); -} - -unsigned AlliedVisionCamera::GetImageHeight() const { - char value[MM::MaxStrLength]; - int ret = GetProperty(g_Height, value); - if (ret != DEVICE_OK) { - return 0; + std::shared_ptr features = + std::shared_ptr(new VmbFeatureInfo_t[featureCount]); + err = g_api->VmbFeaturesList_t(m_handle, features.get(), featureCount, + &featureCount, sizeof(VmbFeatureInfo_t)); + if (err != VmbErrorSuccess) { + return err; } - return atoi(value); -} + const VmbFeatureInfo_t* end = features.get() + featureCount; + for (VmbFeatureInfo_t* feature = features.get(); feature != end; ++feature) { + // uManager callback + CPropertyAction* callback = + new CPropertyAction(this, &AlliedVisionCamera::onProperty); -unsigned AlliedVisionCamera::GetImageBytesPerPixel() const { - // TODO implement - return 1; + err = createPropertyFromFeature(feature, callback); + if (err != VmbErrorSuccess) { + LogMessageCode(err); + continue; + } + } } -int AlliedVisionCamera::SnapImage() { - if (m_isAcquisitionRunning) { - return DEVICE_CAMERA_BUSY_ACQUIRING; - } - resizeImageBuffer(); +VmbError_t AlliedVisionCamera::getCamerasList() { + VmbUint32_t camNum; + // Get the number of connected cameras first + VmbError_t err = g_api->VmbCamerasList_t(nullptr, 0, &camNum, 0); + if (VmbErrorSuccess == err) { + VmbCameraInfo_t* camInfo = new VmbCameraInfo_t[camNum]; - VmbFrame_t frame; - frame.buffer = m_buffer[0]; - frame.bufferSize = m_bufferSize; + // Get the cameras + err = g_api->VmbCamerasList_t(camInfo, camNum, &camNum, sizeof *camInfo); - VmbError_t err = - g_api->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); - if (err != VmbErrorSuccess) { - return err; - } + if (err == VmbErrorSuccess) { + for (VmbUint32_t i = 0; i < camNum; ++i) { + RegisterDevice(camInfo[i].cameraIdString, MM::CameraDevice, + camInfo[i].cameraName); + } + } - err = g_api->VmbCaptureStart_t(m_handle); - if (err != VmbErrorSuccess) { - return err; + delete[] camInfo; } - err = g_api->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); + return err; +} + +VmbError_t AlliedVisionCamera::resizeImageBuffer() { + VmbError_t err = g_api->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); - if (err != VmbErrorSuccess) { - return err; + for (size_t i = 0; i < MAX_FRAMES; i++) { + delete[] m_buffer[i]; + m_buffer[i] = new VmbUint8_t[m_bufferSize]; } - err = g_api->VmbCaptureFrameWait_t(m_handle, &frame, 3000); - if (err != VmbErrorSuccess) { - return err; + return err; +} + +VmbError_t AlliedVisionCamera::createPropertyFromFeature( + const VmbFeatureInfo_t* feature, MM::ActionFunctor* callback) { + if (feature == nullptr) { + return VmbErrorInvalidValue; } - err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); + auto featureName = feature->name; + VmbError_t err = VmbErrorSuccess; + std::string propName = {}; + mapFeatureNameToPropertyName(featureName, propName); + + // Vimba callback + auto vmbCallback = [](VmbHandle_t handle, const char* name, + void* userContext) { + AlliedVisionCamera* camera = + reinterpret_cast(userContext); + std::string propertyName; + camera->mapFeatureNameToPropertyName(name, propertyName); + camera->UpdateProperty(propertyName.c_str()); + }; + + // Add property to the list + m_propertyItems.insert({propName, {propName}}); + + // Register VMb callback + err = g_api->VmbFeatureInvalidationRegister_t(m_handle, featureName, + vmbCallback, this); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbCaptureEnd_t(m_handle); - if (err != VmbErrorSuccess) { - return err; + switch (feature->featureDataType) { + case VmbFeatureDataInt: { + err = CreateIntegerProperty(propName.c_str(), 0, true, callback); + break; + } + case VmbFeatureDataBool: + case VmbFeatureDataEnum: + case VmbFeatureDataCommand: + case VmbFeatureDataString: { + err = CreateStringProperty(propName.c_str(), "", true, callback); + break; + } + case VmbFeatureDataFloat: { + err = CreateFloatProperty(propName.c_str(), 0.0, true, callback); + break; + } + case VmbFeatureDataUnknown: + case VmbFeatureDataRaw: + case VmbFeatureDataNone: + default: + // nothing + break; } - err = g_api->VmbCaptureQueueFlush_t(m_handle); - if (err != VmbErrorSuccess) { - return err; + return err; +} + +const unsigned char* AlliedVisionCamera::GetImageBuffer() { + return reinterpret_cast(m_buffer[0]); +} + +unsigned AlliedVisionCamera::GetImageWidth() const { + char value[MM::MaxStrLength]; + int ret = GetProperty(g_Width, value); + if (ret != DEVICE_OK) { + return 0; } - err = g_api->VmbFrameRevokeAll_t(m_handle); - if (err != VmbErrorSuccess) { - return err; + return atoi(value); +} + +unsigned AlliedVisionCamera::GetImageHeight() const { + char value[MM::MaxStrLength]; + int ret = GetProperty(g_Height, value); + if (ret != DEVICE_OK) { + return 0; } - return err; + return atoi(value); +} + +unsigned AlliedVisionCamera::GetImageBytesPerPixel() const { + // TODO implement + return 1; } long AlliedVisionCamera::GetImageBufferSize() const { return m_bufferSize; } @@ -237,103 +335,6 @@ int AlliedVisionCamera::SetBinning(int binSize) { CDeviceUtils::ConvertToString(binSize)); } -int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, - MM::ActionType eAct) { - // Get horizonal binning - VmbFeatureInfo_t featureInfoHorizontal; - VmbError_t err = g_api->VmbFeatureInfoQuery_t( - m_handle, g_BinningHorizontalFeature, &featureInfoHorizontal, - sizeof(featureInfoHorizontal)); - if (VmbErrorSuccess != err) { - return err; - } - - // Get vertical binning - VmbFeatureInfo_t featureInfoVertical; - err = g_api->VmbFeatureInfoQuery_t(m_handle, g_BinningVerticalFeature, - &featureInfoVertical, - sizeof(featureInfoVertical)); - if (VmbErrorSuccess != err) { - return err; - } - - VmbInt64_t minHorizontal, maxHorizontal, minVertical, maxVertical, min, max; - std::string value, valueHorizontal, valueVertical; - bool rMode, wMode; - std::vector strValues; - - // Cast to Property to have an access to setting read/write mode - MM::Property* pChildProperty = (MM::Property*)pProp; - - // Get read/write mode - assume binning horizontal and vertical has the same - // mode - err = g_api->VmbFeatureAccessQuery_t(m_handle, g_BinningVerticalFeature, - &rMode, &wMode); - if (VmbErrorSuccess != err) { - return err; - } - - switch (eAct) { - case MM::ActionType::BeforeGet: - // Get horizontal binning value - err = getFeatureValue(&featureInfoHorizontal, g_BinningHorizontalFeature, - valueHorizontal); - if (VmbErrorSuccess != err) { - return err; - } - // Get vertical binning value - err = getFeatureValue(&featureInfoVertical, g_BinningVerticalFeature, - valueVertical); - if (VmbErrorSuccess != err) { - return err; - } - - // Get min value from these two - min = - std::min(atoi(valueHorizontal.c_str()), atoi(valueVertical.c_str())); - pProp->Set(std::to_string(min).c_str()); - - // Update binning limits - err = g_api->VmbFeatureIntRangeQuery_t( - m_handle, g_BinningHorizontalFeature, &minHorizontal, &maxHorizontal); - if (VmbErrorSuccess != err) { - return err; - } - - err = g_api->VmbFeatureIntRangeQuery_t(m_handle, g_BinningVerticalFeature, - &minVertical, &maxVertical); - if (VmbErrorSuccess != err) { - return err; - } - min = std::max(minHorizontal, minVertical); - max = std::min(maxHorizontal, maxVertical); - - for (VmbInt64_t i = min; i <= max; i++) { - strValues.push_back(std::to_string(i)); - } - SetAllowedValues(pProp->GetName().c_str(), strValues); - // Update access mode - pChildProperty->SetReadOnly(rMode && !wMode); - break; - case MM::ActionType::AfterSet: - pProp->Get(value); - err = setFeatureValue(&featureInfoHorizontal, g_BinningHorizontalFeature, - value); - if (VmbErrorSuccess != err) { - return err; - } - err = setFeatureValue(&featureInfoVertical, g_BinningVerticalFeature, - value); - break; - default: - // nothing - break; - } - - // TODO return uManager error - return err; -} - double AlliedVisionCamera::GetExposure() const { char strExposure[MM::MaxStrLength]; int ret = GetProperty(MM::g_Keyword_Exposure, strExposure); @@ -349,45 +350,6 @@ void AlliedVisionCamera::SetExposure(double exp_ms) { GetCoreCallback()->OnExposureChanged(this, exp_ms); } -int AlliedVisionCamera::OnExposure(MM::PropertyBase* pProp, - MM::ActionType eAct) { - const auto propertyName = pProp->GetName(); - VmbFeatureInfo_t featureInfo; - VmbError_t err = g_api->VmbFeatureInfoQuery_t( - m_handle, g_ExposureFeature, &featureInfo, sizeof(featureInfo)); - if (VmbErrorSuccess != err) { - return err; - } - - std::string value; - bool rMode, wMode; - err = g_api->VmbFeatureAccessQuery_t(m_handle, propertyName.c_str(), &rMode, - &wMode); - MM::Property* pChildProperty = (MM::Property*)pProp; - - switch (eAct) { - case MM::ActionType::BeforeGet: - // Update limits - setAllowedValues(&featureInfo); - // Update access mode - pChildProperty->SetReadOnly(rMode && !wMode); - // Update value - err = getFeatureValue(&featureInfo, g_ExposureFeature, value); - pProp->Set(value.c_str()); - break; - case MM::ActionType::AfterSet: - pProp->Get(value); - err = setFeatureValue(&featureInfo, g_ExposureFeature, value); - break; - default: - // nothing - break; - } - - // TODO return uManager error - return err; -} - int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) { // TODO implement @@ -416,51 +378,116 @@ void AlliedVisionCamera::GetName(char* name) const { bool AlliedVisionCamera::IsCapturing() { return m_isAcquisitionRunning; } -void AlliedVisionCamera::setApiErrorMessages() { - SetErrorText(VmbErrorApiNotStarted, "Vimba X API not started"); - SetErrorText(VmbErrorNotFound, "Device cannot be found"); - SetErrorText(VmbErrorDeviceNotOpen, "Device cannot be opened"); - SetErrorText(VmbErrorBadParameter, - "Invalid parameter passed to the function"); - SetErrorText(VmbErrorNotImplemented, "Feature not implemented"); - SetErrorText(VmbErrorNotSupported, "Feature not supported"); - SetErrorText(VmbErrorUnknown, "Unknown error"); -} +int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, + MM::ActionType eAct) { + // Get horizonal binning + VmbFeatureInfo_t featureInfoHorizontal; + VmbError_t err = g_api->VmbFeatureInfoQuery_t( + m_handle, g_BinningHorizontalFeature, &featureInfoHorizontal, + sizeof(featureInfoHorizontal)); + if (VmbErrorSuccess != err) { + return err; + } -VmbError_t AlliedVisionCamera::getCamerasList() { - VmbUint32_t camNum; - // Get the number of connected cameras first - VmbError_t err = g_api->VmbCamerasList_t(nullptr, 0, &camNum, 0); - if (VmbErrorSuccess == err) { - VmbCameraInfo_t* camInfo = new VmbCameraInfo_t[camNum]; + // Get vertical binning + VmbFeatureInfo_t featureInfoVertical; + err = g_api->VmbFeatureInfoQuery_t(m_handle, g_BinningVerticalFeature, + &featureInfoVertical, + sizeof(featureInfoVertical)); + if (VmbErrorSuccess != err) { + return err; + } - // Get the cameras - err = g_api->VmbCamerasList_t(camInfo, camNum, &camNum, sizeof *camInfo); + // Get read/write mode - assume binning horizontal and vertical has the same + // mode + bool rMode, wMode, readOnly, featureAvailable; + err = g_api->VmbFeatureAccessQuery_t(m_handle, g_BinningVerticalFeature, + &rMode, &wMode); + if (VmbErrorSuccess != err) { + return err; + } - if (err == VmbErrorSuccess) { - for (VmbUint32_t i = 0; i < camNum; ++i) { - RegisterDevice(camInfo[i].cameraIdString, MM::CameraDevice, - camInfo[i].cameraName); + featureAvailable = (rMode || wMode); + if (!featureAvailable) { + return err; + } + + readOnly = featureAvailable && (rMode && !wMode); + + // Get values of property and features + std::string propertyValue, featureHorizontalValue, featureVerticalValue; + pProp->Get(propertyValue); + err = getFeatureValue(&featureInfoHorizontal, g_BinningHorizontalFeature, + featureHorizontalValue); + if (VmbErrorSuccess != err) { + return err; + } + err = getFeatureValue(&featureInfoVertical, g_BinningVerticalFeature, + featureVerticalValue); + if (VmbErrorSuccess != err) { + return err; + } + + std::string featureValue = + std::to_string(std::min(atoi(featureHorizontalValue.c_str()), + atoi(featureVerticalValue.c_str()))); + + MM::Property* pChildProperty = (MM::Property*)pProp; + std::vector strValues; + VmbInt64_t minHorizontal, maxHorizontal, minVertical, maxVertical, min, max; + + switch (eAct) { + case MM::ActionType::BeforeGet: + // Update property + if (propertyValue != featureValue) { + pProp->Set(featureValue.c_str()); } - } + // Update property's access mode + pChildProperty->SetReadOnly(readOnly); + // Update property's limits and allowed values + if (!readOnly) { + // Update binning limits + err = g_api->VmbFeatureIntRangeQuery_t(m_handle, + g_BinningHorizontalFeature, + &minHorizontal, &maxHorizontal); + if (VmbErrorSuccess != err) { + return err; + } - delete[] camInfo; - } + err = g_api->VmbFeatureIntRangeQuery_t( + m_handle, g_BinningVerticalFeature, &minVertical, &maxVertical); + if (VmbErrorSuccess != err) { + return err; + } - return err; -} + //[IMPORTANT] For binning, increment step is ignored -VmbError_t AlliedVisionCamera::resizeImageBuffer() { - VmbError_t err = g_api->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); - if (err != VmbErrorSuccess) { - return err; - } + min = std::max(minHorizontal, minVertical); + max = std::min(maxHorizontal, maxVertical); - for (size_t i = 0; i < MAX_FRAMES; i++) { - delete[] m_buffer[i]; - m_buffer[i] = new VmbUint8_t[m_bufferSize]; + for (VmbInt64_t i = min; i <= max; i++) { + strValues.push_back(std::to_string(i)); + } + err = SetAllowedValues(pProp->GetName().c_str(), strValues); + } + break; + case MM::ActionType::AfterSet: + if (propertyValue != featureValue) { + VmbError_t errHor = setFeatureValue( + &featureInfoHorizontal, g_BinningHorizontalFeature, propertyValue); + VmbError_t errVer = setFeatureValue( + &featureInfoVertical, g_BinningVerticalFeature, propertyValue); + if (VmbErrorSuccess != errHor || VmbErrorSuccess != errVer) { + //[IMPORTANT] For binning, adjust value is ignored + } + } + break; + default: + // nothing + break; } + //// TODO return uManager error return err; } @@ -472,39 +499,96 @@ int AlliedVisionCamera::OnPixelType(MM::PropertyBase* pProp, int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, MM::ActionType eAct) { + // Init + std::vector featureNames = {}; + VmbError_t err = VmbErrorSuccess; + MM::Property* pChildProperty = (MM::Property*)pProp; const auto propertyName = pProp->GetName(); - VmbFeatureInfo_t featureInfo; - VmbError_t err = g_api->VmbFeatureInfoQuery_t( - m_handle, propertyName.c_str(), &featureInfo, sizeof(featureInfo)); - if (VmbErrorSuccess != err) { - return err; - } - std::string value{}; - bool rMode, wMode; - err = g_api->VmbFeatureAccessQuery_t(m_handle, propertyName.c_str(), &rMode, - &wMode); - MM::Property* pChildProperty = (MM::Property*)pProp; - switch (eAct) { - case MM::ActionType::BeforeGet: - // Update limits - setAllowedValues(&featureInfo); - // Update access mode - pChildProperty->SetReadOnly(rMode && !wMode); - // Update value - //TODO error handling - getFeatureValue(&featureInfo, propertyName.c_str(), value); - pProp->Set(value.c_str()); - break; - case MM::ActionType::AfterSet: - // Update value - pProp->Get(value); - // TODO error handling - setFeatureValue(&featureInfo, propertyName.c_str(), value); - break; - default: - // nothing - break; + // Check property mapping + mapPropertyNameToFeatureNames(propertyName.c_str(), featureNames); + + if (propertyName == std::string(MM::g_Keyword_Binning)) { + // Binning requires special handling and combining two features into one + // property + OnBinning(pProp, eAct); + } else { + // Retrive each feature + for (const auto& featureName : featureNames) { + // Get Feature Info + VmbFeatureInfo_t featureInfo; + err = g_api->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), + &featureInfo, sizeof(featureInfo)); + if (VmbErrorSuccess != err) { + return err; + } + + // Get Access Mode + bool rMode, wMode, readOnly, featureAvailable; + err = g_api->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), + &rMode, &wMode); + if (VmbErrorSuccess != err) { + return err; + } + + featureAvailable = (rMode || wMode); + if (!featureAvailable) { + return err; + } + + readOnly = featureAvailable && (rMode && !wMode); + + // Get values + std::string propertyValue, featureValue; + pProp->Get(propertyValue); + err = getFeatureValue(&featureInfo, featureName.c_str(), featureValue); + if (VmbErrorSuccess != err) { + return err; + } + + // Handle property value change + switch (eAct) { + case MM::ActionType::BeforeGet: //!< Update property from feature + // Update property + if (propertyValue != featureValue) { + pProp->Set(featureValue.c_str()); + } + + // Update property's access mode + pChildProperty->SetReadOnly(readOnly); + // Update property's limits and allowed values + if (!readOnly) { + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) { + return err; + } + } + break; + case MM::ActionType::AfterSet: //!< Update feature from property + if (propertyValue != featureValue) { + err = setFeatureValue(&featureInfo, featureName.c_str(), + propertyValue); + if (err != VmbErrorSuccess) { + if (featureInfo.featureDataType == + VmbFeatureDataType::VmbFeatureDataFloat || + featureInfo.featureDataType == + VmbFeatureDataType::VmbFeatureDataInt) { + auto propertyItem = m_propertyItems.at(propertyName); + std::string adjustedValue = + adjustValue(propertyItem.m_min, propertyItem.m_max, + propertyItem.m_step, std::stod(propertyValue)); + pProp->Set(adjustedValue.c_str()); + (void)setFeatureValue(&featureInfo, featureName.c_str(), + adjustedValue); + } + } + } + break; + default: + // nothing + break; + } + } } return err; @@ -521,7 +605,7 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, if (err != VmbErrorSuccess) { break; } - value = std::to_string(out); + value = (out ? g_True : g_False); break; } case VmbFeatureDataEnum: { @@ -567,6 +651,7 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, break; } case VmbFeatureDataCommand: + // TODO case VmbFeatureDataUnknown: case VmbFeatureDataRaw: case VmbFeatureDataNone: @@ -585,8 +670,7 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, switch (featureInfo->featureDataType) { case VmbFeatureDataBool: { - VmbBool_t out; - ss >> out; + VmbBool_t out = (value == g_True ? true : false); err = g_api->VmbFeatureBoolSet_t(m_handle, featureName, out); break; } @@ -611,6 +695,7 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, break; } case VmbFeatureDataCommand: + // TODO case VmbFeatureDataUnknown: case VmbFeatureDataRaw: case VmbFeatureDataNone: @@ -621,232 +706,65 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, return err; } -VmbError_t AlliedVisionCamera::createPropertyFromFeature( - const VmbFeatureInfo_t* feature, MM::ActionFunctor* callback, - const char* propertyName, bool skipVmbCallback) { - if (feature == nullptr) { - return VmbErrorInvalidValue; - } - - auto featureName = feature->name; - auto propName = (propertyName != nullptr) ? propertyName : featureName; - VmbError_t err = VmbErrorSuccess; - - if (!skipVmbCallback) { - // Vmb callback for given feature - auto vmbCallback = [](VmbHandle_t handle, const char* name, - void* userContext) { - AlliedVisionCamera* camera = - reinterpret_cast(userContext); - camera->UpdateProperty(name); - }; - // Register VMb callback - err = g_api->VmbFeatureInvalidationRegister_t(m_handle, featureName, - vmbCallback, this); - if (err != VmbErrorSuccess) { - return err; - } - } - - if (HasProperty(propName)) { - // Already exist - return err; +void AlliedVisionCamera::mapFeatureNameToPropertyName( + const char* feature, std::string& property) const { + property = std::string(feature); + auto search = m_featureToProperty.find(property); + if (search != m_featureToProperty.end()) { + property = search->second; } - - switch (feature->featureDataType) { - case VmbFeatureDataBool: { - CreateIntegerProperty(propName, 0, true, callback); - break; - } - case VmbFeatureDataEnum: { - CreateStringProperty(propName, "", true, callback); - break; - } - case VmbFeatureDataFloat: { - CreateFloatProperty(propName, 0.0, true, callback); - break; - } - case VmbFeatureDataInt: { - CreateIntegerProperty(propName, 0, true, callback); - break; - } - case VmbFeatureDataString: { - CreateStringProperty(propName, "", true, callback); - break; +} +void AlliedVisionCamera::mapPropertyNameToFeatureNames( + const char* property, std::vector& featureNames) const { + // Check property mapping + auto searchRange = m_propertyToFeature.equal_range(property); + if (searchRange.first != m_propertyToFeature.end()) { + // Features that are mapped from property + for (auto it = searchRange.first; it != searchRange.second; ++it) { + featureNames.push_back(it->second); } - case VmbFeatureDataCommand: - case VmbFeatureDataUnknown: - case VmbFeatureDataRaw: - case VmbFeatureDataNone: - default: - // nothing - break; + } else { + // for rest + featureNames.push_back(property); } - - return err; } -VmbError_t AlliedVisionCamera::createCoreProperties() { - VmbError_t err = VmbErrorSuccess; - //=== Create PIXEL_TYPE from PIXEL_FORMAT - { - VmbFeatureInfo_t feature; - err = g_api->VmbFeatureInfoQuery_t(m_handle, g_PixelFormatFeature, &feature, - sizeof(VmbFeatureInfo_t)); - if (err != VmbErrorSuccess) { - return err; - } - // uManager callback - CPropertyAction* callback = - new CPropertyAction(this, &AlliedVisionCamera::OnPixelType); - err = createPropertyFromFeature(&feature, callback, MM::g_Keyword_PixelType, - true); - if (err != VmbErrorSuccess) { - return err; - } - - err = setAllowedValues(&feature, MM::g_Keyword_PixelType); - if (err != VmbErrorSuccess) { - return err; - } - - // Vmb callback - auto vmbCallback = [](VmbHandle_t handle, const char* name, - void* userContext) { - AlliedVisionCamera* camera = - reinterpret_cast(userContext); - camera->UpdateProperty(MM::g_Keyword_PixelType); - }; - err = g_api->VmbFeatureInvalidationRegister_t( - m_handle, g_PixelFormatFeature, vmbCallback, this); - if (err != VmbErrorSuccess) { - return err; - } +std::string AlliedVisionCamera::adjustValue(double min, double max, double step, + double propertyValue) const { + if (propertyValue > max) { + return std::to_string(max); } - - //=== Create EXPOSURE from EXPOSURE_TIME - { - VmbFeatureInfo_t feature; - err = g_api->VmbFeatureInfoQuery_t(m_handle, g_ExposureFeature, &feature, - sizeof(VmbFeatureInfo_t)); - if (err != VmbErrorSuccess) { - return err; - } - - // uManager callback - CPropertyAction* callback = - new CPropertyAction(this, &AlliedVisionCamera::OnExposure); - err = createPropertyFromFeature(&feature, callback, MM::g_Keyword_Exposure, - true); - if (err != VmbErrorSuccess) { - return err; - } - - err = setAllowedValues(&feature, MM::g_Keyword_Exposure); - if (err != VmbErrorSuccess) { - return err; - } - - // Vmb callback - auto vmbCallback = [](VmbHandle_t handle, const char* name, - void* userContext) { - AlliedVisionCamera* camera = - reinterpret_cast(userContext); - camera->UpdateProperty(MM::g_Keyword_Exposure); - }; - - err = g_api->VmbFeatureInvalidationRegister_t(m_handle, g_ExposureFeature, - vmbCallback, this); - if (err != VmbErrorSuccess) { - return err; - } + if (propertyValue < min) { + return std::to_string(min); } - //=== Create BINNING from BINNING_HORIZONTAL and BINNING_VERTICAL - { - VmbFeatureInfo_t feature; - err = g_api->VmbFeatureInfoQuery_t(m_handle, g_BinningHorizontalFeature, - &feature, sizeof(VmbFeatureInfo_t)); - if (err != VmbErrorSuccess) { - return err; - } - - // uManager callback - CPropertyAction* callback = - new CPropertyAction(this, &AlliedVisionCamera::OnBinning); - err = createPropertyFromFeature(&feature, callback, MM::g_Keyword_Binning, - true); - if (err != VmbErrorSuccess) { - return err; - } - - // Set limits for BINNING - VmbInt64_t minHorizontal, maxHorizontal, minVertical, maxVertical; - err = g_api->VmbFeatureIntRangeQuery_t(m_handle, g_BinningHorizontalFeature, - &minHorizontal, &maxHorizontal); - if (VmbErrorSuccess != err) { - return err; - } - - err = g_api->VmbFeatureIntRangeQuery_t(m_handle, g_BinningVerticalFeature, - &minVertical, &maxVertical); - if (VmbErrorSuccess != err) { - return err; - } - auto min = std::max(minHorizontal, minVertical); - auto max = std::min(maxHorizontal, maxVertical); - - std::vector strValues; - for (VmbInt64_t i = min; i <= max; i++) { - strValues.push_back(std::to_string(i)); - } - - SetAllowedValues(MM::g_Keyword_Binning, strValues); + VmbInt64_t factor = static_cast((propertyValue - min) / step); + double prev = min + factor * step; + double next = min + (factor + 1) * step; - // Vmb callback for horizontal binning - auto vmbCallbackHorizontal = [](VmbHandle_t handle, const char* name, - void* userContext) { - AlliedVisionCamera* camera = - reinterpret_cast(userContext); - camera->UpdateProperty(MM::g_Keyword_Binning); - }; + double prevDiff = abs(propertyValue - prev); + double nextDiff = abs(next - propertyValue); - err = g_api->VmbFeatureInvalidationRegister_t( - m_handle, g_BinningHorizontalFeature, vmbCallbackHorizontal, this); - if (err != VmbErrorSuccess) { - return err; - } - - // Vmb callback for vertical binning - auto vmbCallbackVertical = [](VmbHandle_t handle, const char* name, - void* userContext) { - AlliedVisionCamera* camera = - reinterpret_cast(userContext); - camera->UpdateProperty(MM::g_Keyword_Binning); - }; - - err = g_api->VmbFeatureInvalidationRegister_t( - m_handle, g_BinningVerticalFeature, vmbCallbackVertical, this); - if (err != VmbErrorSuccess) { - return err; - } - } - - return err; + return (nextDiff < prevDiff) ? std::to_string(next) : std::to_string(prev); } VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, const char* propertyName) { - if (feature == nullptr) { + if (feature == nullptr || propertyName == nullptr) { return VmbErrorInvalidValue; } - auto propName = (propertyName != nullptr) ? propertyName : feature->name; VmbError_t err = VmbErrorSuccess; + auto search = m_propertyItems.find(propertyName); + if (search == m_propertyItems.end()) { + LogMessage("Cannot find propery on internal list"); + return VmbErrorInvalidValue; + } switch (feature->featureDataType) { case VmbFeatureDataBool: { - // TODO check if possible values needs to be set here + AddAllowedValue(propertyName, g_False); + AddAllowedValue(propertyName, g_True); break; } case VmbFeatureDataFloat: { @@ -854,11 +772,30 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, double max = 0; err = g_api->VmbFeatureFloatRangeQuery_t(m_handle, feature->name, &min, &max); + if (VmbErrorSuccess != err || min == max) { + return err; + } + + double step = 0.0; + bool isIncremental = false; + err = g_api->VmbFeatureFloatIncrementQuery_t(m_handle, feature->name, + &isIncremental, &step); if (VmbErrorSuccess != err) { return err; } - err = SetPropertyLimits(propName, min, max); + PropertyItem tempProp{propertyName, static_cast(min), + static_cast(max), + static_cast(step)}; + if (tempProp == search->second) { + break; + } + + m_propertyItems.at(propertyName).m_min = static_cast(min); + m_propertyItems.at(propertyName).m_max = static_cast(max); + m_propertyItems.at(propertyName).m_step = static_cast(step); + + err = SetPropertyLimits(propertyName, min, max); break; } case VmbFeatureDataEnum: { @@ -874,20 +811,38 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, for (size_t i = 0; i < valuesNum; i++) { strValues.push_back(values[i]); } - SetAllowedValues(propName, strValues); + err = SetAllowedValues(propertyName, strValues); break; } case VmbFeatureDataInt: { - VmbInt64_t min = 0; - VmbInt64_t max = 0; + VmbInt64_t min, max, step; + std::vector strValues; + err = g_api->VmbFeatureIntRangeQuery_t(m_handle, feature->name, &min, &max); + if (VmbErrorSuccess != err || min == max) { + return err; + } + + err = + g_api->VmbFeatureIntIncrementQuery_t(m_handle, feature->name, &step); if (VmbErrorSuccess != err) { return err; } - err = SetPropertyLimits(propName, min, max); + PropertyItem tempProp{propertyName, static_cast(min), + static_cast(max), + static_cast(step)}; + if (tempProp == search->second) { + break; + } + + m_propertyItems.at(propertyName).m_min = static_cast(min); + m_propertyItems.at(propertyName).m_max = static_cast(max); + m_propertyItems.at(propertyName).m_step = static_cast(step); + + err = SetPropertyLimits(propertyName, min, max); break; } case VmbFeatureDataString: { @@ -904,42 +859,63 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, return err; } -VmbError_t AlliedVisionCamera::setupProperties() { - VmbUint32_t featureCount = 0; - VmbError_t err = g_api->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, - sizeof(VmbFeatureInfo_t)); - if (err != VmbErrorSuccess || !featureCount) { +int AlliedVisionCamera::SnapImage() { + if (m_isAcquisitionRunning) { + return DEVICE_CAMERA_BUSY_ACQUIRING; + } + resizeImageBuffer(); + + VmbFrame_t frame; + frame.buffer = m_buffer[0]; + frame.bufferSize = m_bufferSize; + + VmbError_t err = + g_api->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); + if (err != VmbErrorSuccess) { return err; } - std::shared_ptr features = - std::shared_ptr(new VmbFeatureInfo_t[featureCount]); - err = g_api->VmbFeaturesList_t(m_handle, features.get(), featureCount, - &featureCount, sizeof(VmbFeatureInfo_t)); + err = g_api->VmbCaptureStart_t(m_handle); if (err != VmbErrorSuccess) { return err; } - // TODO handle error - err = createCoreProperties(); + err = g_api->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); + if (err != VmbErrorSuccess) { + return err; + } - const VmbFeatureInfo_t* end = features.get() + featureCount; - for (VmbFeatureInfo_t* feature = features.get(); feature != end; ++feature) { - auto featureName = std::string(feature->name); - // Skip these features as they are mapped to the Core Properties - if (featureName == std::string(g_PixelFormatFeature) || - featureName == std::string(g_BinningHorizontalFeature) || - featureName == std::string(g_BinningVerticalFeature) || - featureName == std::string(g_ExposureFeature)) { - continue; - } + err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); + if (err != VmbErrorSuccess) { + return err; + } - // uManager callback - CPropertyAction* callback = - new CPropertyAction(this, &AlliedVisionCamera::onProperty); - // TODO handle error - err = createPropertyFromFeature(feature, callback); + err = g_api->VmbCaptureFrameWait_t(m_handle, &frame, 3000); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureEnd_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbCaptureQueueFlush_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } + + err = g_api->VmbFrameRevokeAll_t(m_handle); + if (err != VmbErrorSuccess) { + return err; } + + return err; } int AlliedVisionCamera::StartSequenceAcquisition(long numImages, @@ -1032,7 +1008,7 @@ int AlliedVisionCamera::StopSequenceAcquisition() { void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { if (frame != nullptr && frame->receiveStatus == VmbFrameStatusComplete) { - VmbUint8_t* buffer = reinterpret_cast(frame->buffer); + VmbUint8_t* buffer = reinterpret_cast(frame->imageData); // TODO implement metadata Metadata md; diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 8e3866c05..3decc5603 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -25,6 +25,7 @@ #include "DeviceBase.h" #include "Loader/LibLoader.h" +#include "PropertyItem.h" /** * @brief Pointer to the Vimba API @@ -41,6 +42,11 @@ static constexpr const char* g_BinningVerticalFeature = "BinningVertical"; static constexpr const char* g_Width = "Width"; static constexpr const char* g_Height = "Height"; +/////////////////////////////////////////////////////////////////////////////// +// STATIC VARIABLES +/////////////////////////////////////////////////////////////////////////////// +static constexpr const char* g_True = "True"; +static constexpr const char* g_False = "False"; /** * @brief Main Allied Vision Camera class */ @@ -100,8 +106,6 @@ class AlliedVisionCamera : public CCameraBase { MM::ActionType eAct); //!<< PixelType property callback int OnBinning(MM::PropertyBase* pProp, MM::ActionType eAct); //!<< Binning property callback - int OnExposure(MM::PropertyBase* pProp, - MM::ActionType eAct); //!<< Exposure property callback int onProperty(MM::PropertyBase* pProp, MM::ActionType eAct); //!<< General property callback @@ -130,45 +134,25 @@ class AlliedVisionCamera : public CCameraBase { */ VmbError_t setupProperties(); - /** - * @brief Helper method to create single uManager property from Vimba feature - * @param[in] feature Pointer to the Vimba feature - * @return VmbError_t - */ /** * @brief Helper method to create single uManager property from Vimba feature * @param[in] feature Pointer to the Vimba feature * @param[in] callback uManager callback for given property - * @param[in] propertyName uManager propery name (if differs from - * feature name). By default nullptr - * @param[in] skipVmbCallback If set to true, VmbCallback will not be - * added to this feature. By default false * @return VmbError_t */ VmbError_t createPropertyFromFeature(const VmbFeatureInfo_t* feature, - MM::ActionFunctor* callback, - const char* propertyName = nullptr, - bool skipVmbCallback = false); - - /** - * @brief Helper method to create core properties from feature. - * @return VmbError_t - * - * It is used to create properties which names does not match to the Vimba - * feature. As example these are Binning, Exposure, PixelType - */ - VmbError_t createCoreProperties(); + MM::ActionFunctor* callback); /** * @brief Helper method to set allowed values for given property, based on * its feature type * @param[in] feature Vimba feature name * @param[in] propertyName uManager propery name (if differs from - * feature name). By default nullptr + * feature name) * @return */ VmbError_t setAllowedValues(const VmbFeatureInfo_t* feature, - const char* propertyName = nullptr); + const char* propertyName); /** * @brief Insert ready frame to the uManager @@ -198,6 +182,35 @@ class AlliedVisionCamera : public CCameraBase { VmbError_t setFeatureValue(VmbFeatureInfo_t* featureInfo, const char* featureName, std::string& value); + /** + * @brief Helper method to map feature name into property name of uManager + * @param[in] feature Vimba Feature name + * @param property uManager property name + */ + void mapFeatureNameToPropertyName(const char* feature, + std::string& property) const; + + /** + * @brief Helper method to map uManager property in Vimba feature or features + * name + * @param[in] property uManager property name + * @param featureNames Vimba feature or features name + */ + void mapPropertyNameToFeatureNames( + const char* property, std::vector& featureNames) const; + + /** + * @brief In case trying to set invalid value, adjust it to the closest with + * inceremntal step + * @param[in] min Minimum for given property + * @param[in] max Maximum for given property + * @param[in] step Incremental step + * @param[in] propertyValue Value that was tried to be set + * @return Adjusted value resresented as a string + */ + std::string adjustValue(double min, double max, double step, + double propertyValue) const; + /////////////////////////////////////////////////////////////////////////////// // MEMBERS /////////////////////////////////////////////////////////////////////////////// @@ -209,6 +222,12 @@ class AlliedVisionCamera : public CCameraBase { VmbUint32_t m_bufferSize; // + m_propertyItems; //!< Internal map of properties + static const std::unordered_map + m_featureToProperty; //!< Map of features name into uManager properties + static const std::unordered_multimap + m_propertyToFeature; //!< Map of uManager properties into Vimba features }; #endif diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj index fb5846871..7e3e86303 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj @@ -20,6 +20,7 @@ + @@ -31,6 +32,7 @@ + diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters index 03328d086..14c49d5a3 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters @@ -42,6 +42,9 @@ Header Files + + Header Files + @@ -50,5 +53,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/PropertyItem.cpp b/DeviceAdapters/AlliedVisionCamera/PropertyItem.cpp new file mode 100644 index 000000000..4b0865174 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/PropertyItem.cpp @@ -0,0 +1,5 @@ +#include "PropertyItem.h" + +PropertyItem::PropertyItem(const std::string& name, double min, double max, + double step) + : m_name(name), m_min(min), m_max(max), m_step(step) {} \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/PropertyItem.h b/DeviceAdapters/AlliedVisionCamera/PropertyItem.h new file mode 100644 index 000000000..ed1232dd7 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/PropertyItem.h @@ -0,0 +1,43 @@ +/*============================================================================= + Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ +#ifndef PROPERTYITEM_H +#define PROPERTYITEM_H + +#include + +/** + * @brief + */ +struct PropertyItem { + PropertyItem(const std::string& name, double min = 0.0, double max = 0.0, double step = 1.0); + ~PropertyItem() = default; + + bool operator==(PropertyItem& rhs) { + return rhs.m_name == m_name && rhs.m_min == m_min && rhs.m_max == m_max && + rhs.m_step == m_step; + } + bool operator!=(PropertyItem& rhs) { return !(rhs == *this); } + + std::string m_name; + double m_min; + double m_max; + double m_step; +}; + +#endif // PROPERTYITEM_H diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp index 386d3256b..57b659336 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp @@ -50,16 +50,22 @@ VimbaXApi::VimbaXApi() : m_sdk(VIMBA_X_LIB_NAME, VIMBA_X_LIB_DIR.c_str()) { VmbFeatureStringGet_t = m_sdk.resolveFunction("VmbFeatureStringGet"); VmbFeatureStringSet_t = m_sdk.resolveFunction("VmbFeatureStringSet"); VmbChunkDataAccess_t = m_sdk.resolveFunction("VmbChunkDataAccess"); - VmbFeatureEnumRangeQuery_t = m_sdk.resolveFunction("VmbFeatureEnumRangeQuery"); + VmbFeatureEnumRangeQuery_t = + m_sdk.resolveFunction("VmbFeatureEnumRangeQuery"); VmbFeatureIntRangeQuery_t = m_sdk.resolveFunction("VmbFeatureIntRangeQuery"); - VmbFeatureStringMaxlengthQuery_t = m_sdk.resolveFunction("VmbFeatureStringMaxlengthQuery"); + VmbFeatureStringMaxlengthQuery_t = + m_sdk.resolveFunction("VmbFeatureStringMaxlengthQuery"); VmbFeatureInfoQuery_t = m_sdk.resolveFunction("VmbFeatureInfoQuery"); VmbFeatureFloatRangeQuery_t = m_sdk.resolveFunction("VmbFeatureFloatRangeQuery"); VmbFeatureInvalidationRegister_t = m_sdk.resolveFunction("VmbFeatureInvalidationRegister"); VmbFeatureAccessQuery_t = m_sdk.resolveFunction("VmbFeatureAccessQuery"); + VmbFeatureIntIncrementQuery_t = + m_sdk.resolveFunction("VmbFeatureIntIncrementQuery"); + VmbFeatureFloatIncrementQuery_t = + m_sdk.resolveFunction("VmbFeatureFloatIncrementQuery"); } } diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h index 2b0e64ce7..7f3c3d158 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h @@ -29,7 +29,9 @@ * @brief Wrapper for single Windows process */ class ProcWrapper { + /////////////////////////////////////////////////////////////////////////////// // PUBLIC + /////////////////////////////////////////////////////////////////////////////// public: /** * @brief Constructor of wrapper @@ -44,7 +46,9 @@ class ProcWrapper { operator T*() const { return reinterpret_cast(m_funPtr); } + /////////////////////////////////////////////////////////////////////////////// // PRIVATE + /////////////////////////////////////////////////////////////////////////////// private: FARPROC m_funPtr; // Date: Mon, 10 Jul 2023 13:43:35 +0200 Subject: [PATCH 04/43] Support for command features Changes: - Support for command features Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 37 ++++++++++++++++--- .../AlliedVisionCamera/AlliedVisionCamera.h | 3 ++ .../SDK/Loader/LibLoader.cpp | 2 + .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 1 + 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 07afa78b6..40ebec3d1 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -651,7 +651,8 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, break; } case VmbFeatureDataCommand: - // TODO + value = std::string(g_Command); + break; case VmbFeatureDataUnknown: case VmbFeatureDataRaw: case VmbFeatureDataNone: @@ -667,6 +668,8 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, std::string& value) { VmbError_t err = VmbErrorSuccess; std::stringstream ss(value); + bool isDone = false; + VmbUint32_t maxLen = 0; switch (featureInfo->featureDataType) { case VmbFeatureDataBool: { @@ -691,11 +694,33 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, break; } case VmbFeatureDataString: { - err = g_api->VmbFeatureStringSet_t(m_handle, featureName, value.c_str()); + err = g_api->VmbFeatureStringMaxlengthQuery_t(m_handle, featureName, + &maxLen); + if (err != VmbErrorSuccess) { + LogMessageCode(err); + break; + } + if (value.size() > maxLen) { + err = VmbErrorInvalidValue; + } else { + err = + g_api->VmbFeatureStringSet_t(m_handle, featureName, value.c_str()); + } break; } case VmbFeatureDataCommand: - // TODO + err = g_api->VmbFeatureCommandRun_t(m_handle, featureName); + if (err != VmbErrorSuccess) { + break; + } + while (!isDone) { + err = g_api->VmbFeatureCommandIsDone_t(m_handle, featureName, &isDone); + if (err != VmbErrorSuccess) { + LogMessageCode(err); + break; + } + } + break; case VmbFeatureDataUnknown: case VmbFeatureDataRaw: case VmbFeatureDataNone: @@ -845,11 +870,13 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, err = SetPropertyLimits(propertyName, min, max); break; } - case VmbFeatureDataString: { + case VmbFeatureDataCommand: { + AddAllowedValue(propertyName, g_Command); + AddAllowedValue(propertyName, g_Execute); break; } + case VmbFeatureDataString: case VmbFeatureDataRaw: - case VmbFeatureDataCommand: case VmbFeatureDataNone: default: // nothing diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 3decc5603..cf9fe7f60 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -47,6 +47,9 @@ static constexpr const char* g_Height = "Height"; /////////////////////////////////////////////////////////////////////////////// static constexpr const char* g_True = "True"; static constexpr const char* g_False = "False"; +static constexpr const char* g_Execute = "Execute"; +static constexpr const char* g_Command = "Command"; + /** * @brief Main Allied Vision Camera class */ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp index 57b659336..3270532db 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp @@ -66,6 +66,8 @@ VimbaXApi::VimbaXApi() : m_sdk(VIMBA_X_LIB_NAME, VIMBA_X_LIB_DIR.c_str()) { m_sdk.resolveFunction("VmbFeatureIntIncrementQuery"); VmbFeatureFloatIncrementQuery_t = m_sdk.resolveFunction("VmbFeatureFloatIncrementQuery"); + VmbFeatureCommandIsDone_t = + m_sdk.resolveFunction("VmbFeatureCommandIsDone"); } } diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h index 7f3c3d158..7401a1a3b 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h @@ -162,6 +162,7 @@ class VimbaXApi { nullptr; decltype(VmbFeatureFloatIncrementQuery)* VmbFeatureFloatIncrementQuery_t = nullptr; + decltype(VmbFeatureCommandIsDone)* VmbFeatureCommandIsDone_t = nullptr; /////////////////////////////////////////////////////////////////////////////// // PRIVATE /////////////////////////////////////////////////////////////////////////////// From 753deaa508e1940f722134433106f5cd513df7b6 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Mon, 10 Jul 2023 16:31:11 +0200 Subject: [PATCH 05/43] ROI support Changes: - ROI support Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 160 +++++++++++++++++- .../AlliedVisionCamera/AlliedVisionCamera.h | 21 +++ 2 files changed, 174 insertions(+), 7 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 40ebec3d1..a2bb0c6e3 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -352,19 +352,141 @@ void AlliedVisionCamera::SetExposure(double exp_ms) { int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) { - // TODO implement - return VmbErrorSuccess; + auto width = GetImageWidth(); + auto height = GetImageHeight(); + VmbError_t err = VmbErrorSuccess; + + if (xSize > width) { + std::string strValueX = std::to_string(x); + err = SetProperty(g_OffsetX, strValueX.c_str()); + if (err != DEVICE_OK) { + return err; + } + + std::string strValueWidth = std::to_string(xSize); + err = SetProperty(g_Width, strValueWidth.c_str()); + if (err != DEVICE_OK) { + return err; + } + + } else { + std::string strValueWidth = std::to_string(xSize); + err = SetProperty(g_Width, strValueWidth.c_str()); + if (err != DEVICE_OK) { + return err; + } + + std::string strValueX = std::to_string(x); + err = SetProperty(g_OffsetX, strValueX.c_str()); + if (err != DEVICE_OK) { + return err; + } + } + + if (ySize > height) { + std::string strValueY = std::to_string(y); + err = SetProperty(g_OffsetY, strValueY.c_str()); + if (err != DEVICE_OK) { + return err; + } + + std::string strValueHeight = std::to_string(ySize); + err = SetProperty(g_Height, strValueHeight.c_str()); + if (err != DEVICE_OK) { + return err; + } + + } else { + std::string strValueHeight = std::to_string(ySize); + err = SetProperty(g_Height, strValueHeight.c_str()); + if (err != DEVICE_OK) { + return err; + } + + std::string strValueY = std::to_string(y); + err = SetProperty(g_OffsetY, strValueY.c_str()); + if (err != DEVICE_OK) { + return err; + } + } + + return resizeImageBuffer(); } int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, unsigned& ySize) { - // TODO implement - return VmbErrorSuccess; + { + char strX[MM::MaxStrLength]; + auto ret = GetProperty(g_OffsetX, strX); + if (ret != DEVICE_OK) { + return ret; + } + x = atoi(strX); + } + { + char strY[MM::MaxStrLength]; + auto ret = GetProperty(g_OffsetY, strY); + if (ret != DEVICE_OK) { + return ret; + } + y = atoi(strY); + } + { + char strXSize[MM::MaxStrLength]; + auto ret = GetProperty(g_Width, strXSize); + if (ret != DEVICE_OK) { + return ret; + } + xSize = atoi(strXSize); + } + { + char strYSize[MM::MaxStrLength]; + auto ret = GetProperty(g_Height, strYSize); + if (ret != DEVICE_OK) { + return ret; + } + ySize = atoi(strYSize); + } + + return DEVICE_OK; } int AlliedVisionCamera::ClearROI() { - // TODO implement - return 0; + std::string maxWidth, maxHeight; + VmbError_t err = getFeatureValue(g_WidthMax, maxWidth); + if (VmbErrorSuccess != err) { + return err; + } + + err = getFeatureValue(g_HeightMax, maxHeight); + if (VmbErrorSuccess != err) { + return err; + } + + std::string offsetXval = "0"; + std::string offsetYval = "0"; + + err = setFeatureValue(g_OffsetX, offsetXval); + if (VmbErrorSuccess != err) { + return err; + } + + err = setFeatureValue(g_OffsetY, offsetYval); + if (VmbErrorSuccess != err) { + return err; + } + + err = setFeatureValue(g_Width, maxWidth); + if (VmbErrorSuccess != err) { + return err; + } + + err = setFeatureValue(g_Height, maxHeight); + if (VmbErrorSuccess != err) { + return err; + } + + return resizeImageBuffer(); } int AlliedVisionCamera::IsExposureSequenceable(bool& isSequenceable) const { @@ -578,7 +700,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, adjustValue(propertyItem.m_min, propertyItem.m_max, propertyItem.m_step, std::stod(propertyValue)); pProp->Set(adjustedValue.c_str()); - (void)setFeatureValue(&featureInfo, featureName.c_str(), + err = setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); } } @@ -663,6 +785,18 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, return err; } +VmbError_t AlliedVisionCamera::getFeatureValue(const char* featureName, + std::string& value) { + VmbFeatureInfo_t featureInfo; + VmbError_t err = g_api->VmbFeatureInfoQuery_t( + m_handle, featureName, &featureInfo, sizeof(featureInfo)); + if (VmbErrorSuccess != err) { + return err; + } + + return getFeatureValue(&featureInfo, featureName, value); +} + VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, const char* featureName, std::string& value) { @@ -731,6 +865,18 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, return err; } +VmbError_t AlliedVisionCamera::setFeatureValue(const char* featureName, + std::string& value) { + VmbFeatureInfo_t featureInfo; + VmbError_t err = g_api->VmbFeatureInfoQuery_t( + m_handle, featureName, &featureInfo, sizeof(featureInfo)); + if (VmbErrorSuccess != err) { + return err; + } + + return setFeatureValue(&featureInfo, featureName, value); +} + void AlliedVisionCamera::mapFeatureNameToPropertyName( const char* feature, std::string& property) const { property = std::string(feature); diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index cf9fe7f60..0d3fae798 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -41,6 +41,10 @@ static constexpr const char* g_BinningHorizontalFeature = "BinningHorizontal"; static constexpr const char* g_BinningVerticalFeature = "BinningVertical"; static constexpr const char* g_Width = "Width"; static constexpr const char* g_Height = "Height"; +static constexpr const char* g_OffsetX = "OffsetX"; +static constexpr const char* g_OffsetY = "OffsetY"; +static constexpr const char* g_WidthMax = "WidthMax"; +static constexpr const char* g_HeightMax = "HeightMax"; /////////////////////////////////////////////////////////////////////////////// // STATIC VARIABLES @@ -173,6 +177,14 @@ class AlliedVisionCamera : public CCameraBase { */ VmbError_t getFeatureValue(VmbFeatureInfo_t* featureInfo, const char* featureName, std::string& value); + /** + * @brief Method to get feature value, based on its type. Feature value is + * always a string type. + * @param[in] featureName Feature name + * @param[out] value Value of feature, read from device + * @return VmbError_t + */ + VmbError_t getFeatureValue(const char* featureName, std::string& value); /** * @brief Method to set a feature value, bases on its type. Feature value is @@ -185,6 +197,15 @@ class AlliedVisionCamera : public CCameraBase { VmbError_t setFeatureValue(VmbFeatureInfo_t* featureInfo, const char* featureName, std::string& value); + /** + * @brief Method to set a feature value, bases on its type. Feature value is + * always a string type. + * @param[in] featureName Feature name + * @param[in] value Value of feature to be set + * @return VmbError_t + */ + VmbError_t setFeatureValue(const char* featureName, std::string& value); + /** * @brief Helper method to map feature name into property name of uManager * @param[in] feature Vimba Feature name From 704332c7bf642070195095b9d3bcd5e84e4414ab Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Wed, 12 Jul 2023 14:37:20 +0200 Subject: [PATCH 06/43] Device HUB and refactoring Changes: - Added device HUB type - Fixed issue with reading write only features from SDK - Refactored SDK loading and handling approach to be based on unique_ptr Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 208 ++++++++---------- .../AlliedVisionCamera/AlliedVisionCamera.h | 29 ++- .../AlliedVisionCamera.vcxproj | 2 + .../AlliedVisionCamera.vcxproj.filters | 6 + .../AlliedVisionCamera/AlliedVisionHub.cpp | 53 +++++ .../AlliedVisionCamera/AlliedVisionHub.h | 65 ++++++ .../SDK/Loader/LibLoader.cpp | 31 ++- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 19 +- 8 files changed, 260 insertions(+), 153 deletions(-) create mode 100644 DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp create mode 100644 DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index a2bb0c6e3..3735710fb 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -27,6 +27,7 @@ #include #include +#include "AlliedVisionHub.h" #include "ModuleInterface.h" #include "VmbC/VmbC.h" @@ -51,17 +52,7 @@ const std::unordered_multimap // Exported MMDevice API /////////////////////////////////////////////////////////////////////////////// MODULE_API void InitializeModuleData() { - g_api = std::make_unique(); - assert(g_api != nullptr); - auto err = g_api->VmbStartup_t(nullptr); - assert(err == VmbErrorSuccess); - - err = AlliedVisionCamera::getCamerasList(); - if (err != VmbErrorSuccess) { - // TODO Handle error - } - - g_api->VmbShutdown_t(); + RegisterDevice(g_hubName, MM::HubDevice, "Allied Vision Hub"); } MODULE_API MM::Device* CreateDevice(const char* deviceName) { @@ -69,7 +60,18 @@ MODULE_API MM::Device* CreateDevice(const char* deviceName) { return nullptr; } - return new AlliedVisionCamera(deviceName); + if (g_api == nullptr) { + g_api = std::make_unique(); + } + if(g_api == nullptr || !g_api->isInitialized()){ + return nullptr; + } + + if (std::string(deviceName) == std::string(g_hubName)) { + return new AlliedVisionHub(g_api); + } else { + return new AlliedVisionCamera(deviceName, g_api); + } } MODULE_API void DeleteDevice(MM::Device* pDevice) { delete pDevice; } @@ -86,8 +88,10 @@ AlliedVisionCamera::~AlliedVisionCamera() { } } -AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) +AlliedVisionCamera::AlliedVisionCamera(const char* deviceName, + std::unique_ptr& sdk) : CCameraBase(), + m_sdk(sdk), m_handle{nullptr}, m_cameraName{deviceName}, m_frames{}, @@ -101,24 +105,9 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) int AlliedVisionCamera::Initialize() { // [Rule] Implement communication here - LogMessage("Initializing Vimba X API..."); - VmbError_t err = g_api->VmbStartup_t(nullptr); - if (err != VmbErrorSuccess) { - return err; - } - - VmbVersionInfo_t ver; - err = g_api->VmbVersionQuery_t(&ver, sizeof(ver)); - if (err != VmbErrorSuccess) { - return err; - } - std::string v = std::to_string(ver.major) + "." + std::to_string(ver.minor) + - "." + std::to_string(ver.patch); - LogMessage("SDK version:" + v); - LogMessage("Opening camera: " + m_cameraName); - err = g_api->VmbCameraOpen_t(m_cameraName.c_str(), - VmbAccessModeType::VmbAccessModeFull, &m_handle); + VmbError_t err = m_sdk->VmbCameraOpen_t( + m_cameraName.c_str(), VmbAccessModeType::VmbAccessModeFull, &m_handle); if (err != VmbErrorSuccess || m_handle == nullptr) { return err; } @@ -135,13 +124,12 @@ int AlliedVisionCamera::Shutdown() { // [Rule] Implement disconnection here LogMessage("Shutting down camera: " + m_cameraName); if (m_handle != nullptr) { - VmbError_t err = g_api->VmbCameraClose_t(m_handle); + VmbError_t err = m_sdk->VmbCameraClose_t(m_handle); if (err != VmbErrorSuccess) { return err; } } - g_api->VmbShutdown_t(); return DEVICE_OK; } @@ -161,7 +149,7 @@ void AlliedVisionCamera::setApiErrorMessages() { VmbError_t AlliedVisionCamera::setupProperties() { VmbUint32_t featureCount = 0; - VmbError_t err = g_api->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, + VmbError_t err = m_sdk->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, sizeof(VmbFeatureInfo_t)); if (err != VmbErrorSuccess || !featureCount) { return err; @@ -169,7 +157,7 @@ VmbError_t AlliedVisionCamera::setupProperties() { std::shared_ptr features = std::shared_ptr(new VmbFeatureInfo_t[featureCount]); - err = g_api->VmbFeaturesList_t(m_handle, features.get(), featureCount, + err = m_sdk->VmbFeaturesList_t(m_handle, features.get(), featureCount, &featureCount, sizeof(VmbFeatureInfo_t)); if (err != VmbErrorSuccess) { return err; @@ -189,31 +177,8 @@ VmbError_t AlliedVisionCamera::setupProperties() { } } -VmbError_t AlliedVisionCamera::getCamerasList() { - VmbUint32_t camNum; - // Get the number of connected cameras first - VmbError_t err = g_api->VmbCamerasList_t(nullptr, 0, &camNum, 0); - if (VmbErrorSuccess == err) { - VmbCameraInfo_t* camInfo = new VmbCameraInfo_t[camNum]; - - // Get the cameras - err = g_api->VmbCamerasList_t(camInfo, camNum, &camNum, sizeof *camInfo); - - if (err == VmbErrorSuccess) { - for (VmbUint32_t i = 0; i < camNum; ++i) { - RegisterDevice(camInfo[i].cameraIdString, MM::CameraDevice, - camInfo[i].cameraName); - } - } - - delete[] camInfo; - } - - return err; -} - VmbError_t AlliedVisionCamera::resizeImageBuffer() { - VmbError_t err = g_api->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); + VmbError_t err = m_sdk->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); if (err != VmbErrorSuccess) { return err; } @@ -251,7 +216,7 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( m_propertyItems.insert({propName, {propName}}); // Register VMb callback - err = g_api->VmbFeatureInvalidationRegister_t(m_handle, featureName, + err = m_sdk->VmbFeatureInvalidationRegister_t(m_handle, featureName, vmbCallback, this); if (err != VmbErrorSuccess) { return err; @@ -504,7 +469,7 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, MM::ActionType eAct) { // Get horizonal binning VmbFeatureInfo_t featureInfoHorizontal; - VmbError_t err = g_api->VmbFeatureInfoQuery_t( + VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( m_handle, g_BinningHorizontalFeature, &featureInfoHorizontal, sizeof(featureInfoHorizontal)); if (VmbErrorSuccess != err) { @@ -513,7 +478,7 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, // Get vertical binning VmbFeatureInfo_t featureInfoVertical; - err = g_api->VmbFeatureInfoQuery_t(m_handle, g_BinningVerticalFeature, + err = m_sdk->VmbFeatureInfoQuery_t(m_handle, g_BinningVerticalFeature, &featureInfoVertical, sizeof(featureInfoVertical)); if (VmbErrorSuccess != err) { @@ -523,7 +488,7 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, // Get read/write mode - assume binning horizontal and vertical has the same // mode bool rMode, wMode, readOnly, featureAvailable; - err = g_api->VmbFeatureAccessQuery_t(m_handle, g_BinningVerticalFeature, + err = m_sdk->VmbFeatureAccessQuery_t(m_handle, g_BinningVerticalFeature, &rMode, &wMode); if (VmbErrorSuccess != err) { return err; @@ -569,14 +534,14 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, // Update property's limits and allowed values if (!readOnly) { // Update binning limits - err = g_api->VmbFeatureIntRangeQuery_t(m_handle, + err = m_sdk->VmbFeatureIntRangeQuery_t(m_handle, g_BinningHorizontalFeature, &minHorizontal, &maxHorizontal); if (VmbErrorSuccess != err) { return err; } - err = g_api->VmbFeatureIntRangeQuery_t( + err = m_sdk->VmbFeatureIntRangeQuery_t( m_handle, g_BinningVerticalFeature, &minVertical, &maxVertical); if (VmbErrorSuccess != err) { return err; @@ -639,7 +604,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, for (const auto& featureName : featureNames) { // Get Feature Info VmbFeatureInfo_t featureInfo; - err = g_api->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), + err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), &featureInfo, sizeof(featureInfo)); if (VmbErrorSuccess != err) { return err; @@ -647,7 +612,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Get Access Mode bool rMode, wMode, readOnly, featureAvailable; - err = g_api->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), + err = m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, &wMode); if (VmbErrorSuccess != err) { return err; @@ -663,31 +628,34 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Get values std::string propertyValue, featureValue; pProp->Get(propertyValue); - err = getFeatureValue(&featureInfo, featureName.c_str(), featureValue); - if (VmbErrorSuccess != err) { - return err; - } // Handle property value change switch (eAct) { case MM::ActionType::BeforeGet: //!< Update property from feature - // Update property - if (propertyValue != featureValue) { - pProp->Set(featureValue.c_str()); - } - - // Update property's access mode - pChildProperty->SetReadOnly(readOnly); - // Update property's limits and allowed values - if (!readOnly) { - err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (rMode) { + err = getFeatureValue(&featureInfo, featureName.c_str(), + featureValue); if (VmbErrorSuccess != err) { return err; } + // Update property + if (propertyValue != featureValue) { + pProp->Set(featureValue.c_str()); + } + + // Update property's access mode + pChildProperty->SetReadOnly(readOnly); + // Update property's limits and allowed values + if (!readOnly) { + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) { + return err; + } + } } break; case MM::ActionType::AfterSet: //!< Update feature from property - if (propertyValue != featureValue) { + if (wMode) { err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); if (err != VmbErrorSuccess) { @@ -723,7 +691,7 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, switch (featureInfo->featureDataType) { case VmbFeatureDataBool: { VmbBool_t out; - err = g_api->VmbFeatureBoolGet_t(m_handle, featureName, &out); + err = m_sdk->VmbFeatureBoolGet_t(m_handle, featureName, &out); if (err != VmbErrorSuccess) { break; } @@ -732,7 +700,7 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, } case VmbFeatureDataEnum: { const char* out = nullptr; - err = g_api->VmbFeatureEnumGet_t(m_handle, featureName, &out); + err = m_sdk->VmbFeatureEnumGet_t(m_handle, featureName, &out); if (err != VmbErrorSuccess) { break; } @@ -741,7 +709,7 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, } case VmbFeatureDataFloat: { double out; - err = g_api->VmbFeatureFloatGet_t(m_handle, featureName, &out); + err = m_sdk->VmbFeatureFloatGet_t(m_handle, featureName, &out); if (err != VmbErrorSuccess) { break; } @@ -750,7 +718,7 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, } case VmbFeatureDataInt: { VmbInt64_t out; - err = g_api->VmbFeatureIntGet_t(m_handle, featureName, &out); + err = m_sdk->VmbFeatureIntGet_t(m_handle, featureName, &out); if (err != VmbErrorSuccess) { break; } @@ -759,11 +727,11 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, } case VmbFeatureDataString: { VmbUint32_t size = 0; - err = g_api->VmbFeatureStringGet_t(m_handle, featureName, nullptr, 0, + err = m_sdk->VmbFeatureStringGet_t(m_handle, featureName, nullptr, 0, &size); if (VmbErrorSuccess == err && size > 0) { std::shared_ptr buff = std::shared_ptr(new char[size]); - err = g_api->VmbFeatureStringGet_t(m_handle, featureName, buff.get(), + err = m_sdk->VmbFeatureStringGet_t(m_handle, featureName, buff.get(), size, &size); if (err != VmbErrorSuccess) { break; @@ -788,7 +756,7 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, VmbError_t AlliedVisionCamera::getFeatureValue(const char* featureName, std::string& value) { VmbFeatureInfo_t featureInfo; - VmbError_t err = g_api->VmbFeatureInfoQuery_t( + VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( m_handle, featureName, &featureInfo, sizeof(featureInfo)); if (VmbErrorSuccess != err) { return err; @@ -808,27 +776,27 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, switch (featureInfo->featureDataType) { case VmbFeatureDataBool: { VmbBool_t out = (value == g_True ? true : false); - err = g_api->VmbFeatureBoolSet_t(m_handle, featureName, out); + err = m_sdk->VmbFeatureBoolSet_t(m_handle, featureName, out); break; } case VmbFeatureDataEnum: { - err = g_api->VmbFeatureEnumSet_t(m_handle, featureName, value.c_str()); + err = m_sdk->VmbFeatureEnumSet_t(m_handle, featureName, value.c_str()); break; } case VmbFeatureDataFloat: { double out; ss >> out; - err = g_api->VmbFeatureFloatSet_t(m_handle, featureName, out); + err = m_sdk->VmbFeatureFloatSet_t(m_handle, featureName, out); break; } case VmbFeatureDataInt: { VmbInt64_t out; ss >> out; - err = g_api->VmbFeatureIntSet_t(m_handle, featureName, out); + err = m_sdk->VmbFeatureIntSet_t(m_handle, featureName, out); break; } case VmbFeatureDataString: { - err = g_api->VmbFeatureStringMaxlengthQuery_t(m_handle, featureName, + err = m_sdk->VmbFeatureStringMaxlengthQuery_t(m_handle, featureName, &maxLen); if (err != VmbErrorSuccess) { LogMessageCode(err); @@ -838,17 +806,17 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, err = VmbErrorInvalidValue; } else { err = - g_api->VmbFeatureStringSet_t(m_handle, featureName, value.c_str()); + m_sdk->VmbFeatureStringSet_t(m_handle, featureName, value.c_str()); } break; } case VmbFeatureDataCommand: - err = g_api->VmbFeatureCommandRun_t(m_handle, featureName); + err = m_sdk->VmbFeatureCommandRun_t(m_handle, featureName); if (err != VmbErrorSuccess) { break; } while (!isDone) { - err = g_api->VmbFeatureCommandIsDone_t(m_handle, featureName, &isDone); + err = m_sdk->VmbFeatureCommandIsDone_t(m_handle, featureName, &isDone); if (err != VmbErrorSuccess) { LogMessageCode(err); break; @@ -868,7 +836,7 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, VmbError_t AlliedVisionCamera::setFeatureValue(const char* featureName, std::string& value) { VmbFeatureInfo_t featureInfo; - VmbError_t err = g_api->VmbFeatureInfoQuery_t( + VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( m_handle, featureName, &featureInfo, sizeof(featureInfo)); if (VmbErrorSuccess != err) { return err; @@ -941,7 +909,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, case VmbFeatureDataFloat: { double min = 0; double max = 0; - err = g_api->VmbFeatureFloatRangeQuery_t(m_handle, feature->name, &min, + err = m_sdk->VmbFeatureFloatRangeQuery_t(m_handle, feature->name, &min, &max); if (VmbErrorSuccess != err || min == max) { return err; @@ -949,7 +917,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, double step = 0.0; bool isIncremental = false; - err = g_api->VmbFeatureFloatIncrementQuery_t(m_handle, feature->name, + err = m_sdk->VmbFeatureFloatIncrementQuery_t(m_handle, feature->name, &isIncremental, &step); if (VmbErrorSuccess != err) { return err; @@ -973,7 +941,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, std::array values; std::vector strValues; VmbUint32_t valuesNum = 0; - err = g_api->VmbFeatureEnumRangeQuery_t( + err = m_sdk->VmbFeatureEnumRangeQuery_t( m_handle, feature->name, values.data(), MM::MaxStrLength, &valuesNum); if (VmbErrorSuccess != err) { return err; @@ -991,13 +959,13 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, std::vector strValues; err = - g_api->VmbFeatureIntRangeQuery_t(m_handle, feature->name, &min, &max); + m_sdk->VmbFeatureIntRangeQuery_t(m_handle, feature->name, &min, &max); if (VmbErrorSuccess != err || min == max) { return err; } err = - g_api->VmbFeatureIntIncrementQuery_t(m_handle, feature->name, &step); + m_sdk->VmbFeatureIntIncrementQuery_t(m_handle, feature->name, &step); if (VmbErrorSuccess != err) { return err; } @@ -1043,47 +1011,47 @@ int AlliedVisionCamera::SnapImage() { frame.bufferSize = m_bufferSize; VmbError_t err = - g_api->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); + m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbCaptureStart_t(m_handle); + err = m_sdk->VmbCaptureStart_t(m_handle); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); + err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); + err = m_sdk->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbCaptureFrameWait_t(m_handle, &frame, 3000); + err = m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); + err = m_sdk->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbCaptureEnd_t(m_handle); + err = m_sdk->VmbCaptureEnd_t(m_handle); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbCaptureQueueFlush_t(m_handle); + err = m_sdk->VmbCaptureQueueFlush_t(m_handle); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbFrameRevokeAll_t(m_handle); + err = m_sdk->VmbFrameRevokeAll_t(m_handle); if (err != VmbErrorSuccess) { return err; } @@ -1117,12 +1085,12 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, reinterpret_cast(i); //VmbFrameAnnounce_t(m_handle, &(m_frames[i]), sizeof(VmbFrame_t)); + m_sdk->VmbFrameAnnounce_t(m_handle, &(m_frames[i]), sizeof(VmbFrame_t)); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbCaptureFrameQueue_t( + err = m_sdk->VmbCaptureFrameQueue_t( m_handle, &(m_frames[i]), [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, VmbFrame_t* frame) { @@ -1134,12 +1102,12 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, } } - err = g_api->VmbCaptureStart_t(m_handle); + err = m_sdk->VmbCaptureStart_t(m_handle); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); + err = m_sdk->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); if (err != VmbErrorSuccess) { return err; } @@ -1153,7 +1121,7 @@ int AlliedVisionCamera::StartSequenceAcquisition(double interval_ms) { } int AlliedVisionCamera::StopSequenceAcquisition() { if (m_isAcquisitionRunning) { - auto err = g_api->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); + auto err = m_sdk->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); if (err != VmbErrorSuccess) { return err; } @@ -1161,17 +1129,17 @@ int AlliedVisionCamera::StopSequenceAcquisition() { m_isAcquisitionRunning = false; } - auto err = g_api->VmbCaptureEnd_t(m_handle); + auto err = m_sdk->VmbCaptureEnd_t(m_handle); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbCaptureQueueFlush_t(m_handle); + err = m_sdk->VmbCaptureQueueFlush_t(m_handle); if (err != VmbErrorSuccess) { return err; } - err = g_api->VmbFrameRevokeAll_t(m_handle); + err = m_sdk->VmbFrameRevokeAll_t(m_handle); if (err != VmbErrorSuccess) { return err; } @@ -1201,7 +1169,7 @@ void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { } if (m_isAcquisitionRunning) { - g_api->VmbCaptureFrameQueue_t( + m_sdk->VmbCaptureFrameQueue_t( m_handle, frame, [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, VmbFrame_t* frame) { diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 0d3fae798..4f62e5032 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -16,8 +16,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ -#ifndef ALLIEDVISIONCAMERA_H -#define ALLIEDVISIONCAMERA_H +#ifndef AlliedVisionCamera_H +#define AlliedVisionCamera_H #include #include @@ -27,11 +27,6 @@ #include "Loader/LibLoader.h" #include "PropertyItem.h" -/** - * @brief Pointer to the Vimba API - */ -static std::unique_ptr g_api; - /////////////////////////////////////////////////////////////////////////////// // STATIC FEATURE NAMES (FROM VIMBA) /////////////////////////////////////////////////////////////////////////////// @@ -54,6 +49,12 @@ static constexpr const char* g_False = "False"; static constexpr const char* g_Execute = "Execute"; static constexpr const char* g_Command = "Command"; +/** + * @brief Global pointer to the Vimba API, that needs to be released in a + * correct way at the end + */ +static std::unique_ptr g_api{nullptr}; + /** * @brief Main Allied Vision Camera class */ @@ -64,19 +65,14 @@ class AlliedVisionCamera : public CCameraBase { public: /** * @brief Contructor of Allied Vision Camera - * @param[in] deviceName Device name + * @param[in] deviceName Device name + * @param[in] sdk Unique pointer to the SDK */ - AlliedVisionCamera(const char* deviceName); + AlliedVisionCamera(const char* deviceName, std::unique_ptr& sdk); /** * @brief Allied Vision Camera destructor */ - ~AlliedVisionCamera(); - - /** - * @brief Get connected camera list - * @return VmbError_t - */ - static VmbError_t getCamerasList(); + virtual ~AlliedVisionCamera(); /////////////////////////////////////////////////////////////////////////////// // uMANAGER API METHODS @@ -238,6 +234,7 @@ class AlliedVisionCamera : public CCameraBase { /////////////////////////////////////////////////////////////////////////////// // MEMBERS /////////////////////////////////////////////////////////////////////////////// + std::unique_ptr& m_sdk; // m_frames; // + @@ -32,6 +33,7 @@ + diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters index 14c49d5a3..2d7e866f7 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters @@ -45,6 +45,9 @@ Header Files + + Header Files + @@ -56,5 +59,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp new file mode 100644 index 000000000..73b85e7e7 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp @@ -0,0 +1,53 @@ +#include "AlliedVisionHub.h" + +#include "AlliedVisionCamera.h" + +AlliedVisionHub::AlliedVisionHub(std::unique_ptr& sdk) : m_sdk(sdk) {} + +AlliedVisionHub::~AlliedVisionHub() { + // Release static SDK variable from DLL, otherwise process will not be + // killed, destructor not called + m_sdk.reset(); +} + +int AlliedVisionHub::DetectInstalledDevices() { + VmbUint32_t camNum; + // Get the number of connected cameras first + VmbError_t err = m_sdk->VmbCamerasList_t(nullptr, 0, &camNum, 0); + if (VmbErrorSuccess == err) { + VmbCameraInfo_t* camInfo = new VmbCameraInfo_t[camNum]; + + // Get the cameras + err = m_sdk->VmbCamerasList_t(camInfo, camNum, &camNum, sizeof *camInfo); + + if (err == VmbErrorSuccess) { + for (VmbUint32_t i = 0; i < camNum; ++i) { + if (camInfo[i].permittedAccess & VmbAccessModeFull) { + MM::Device* pDev = + new AlliedVisionCamera(camInfo[i].cameraIdString, m_sdk); + AddInstalledDevice(pDev); + } + } + } + + delete[] camInfo; + } + + return err; +} + +int AlliedVisionHub::Initialize() { + LogMessage("Init HUB"); + return DEVICE_OK; +} + +int AlliedVisionHub::Shutdown() { + LogMessage("Shutting down HUB"); + return DEVICE_OK; +} + +void AlliedVisionHub::GetName(char* name) const { + CDeviceUtils::CopyLimitedString(name, g_hubName); +} + +bool AlliedVisionHub::Busy() { return false; } diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h new file mode 100644 index 000000000..dea6c36db --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h @@ -0,0 +1,65 @@ +/*============================================================================= + Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ +#ifndef AlliedVisionHub_H +#define AlliedVisionHub_H + +#include "DeviceBase.h" +#include "SDK/Loader/LibLoader.h" + +/////////////////////////////////////////////////////////////////////////////// +// STATIC VARIABLES +/////////////////////////////////////////////////////////////////////////////// +static constexpr const char* g_hubName = "AlliedVisionHub"; + +/** + * @brief Class that represents a HUB of supported devices + */ +class AlliedVisionHub : public HubBase { + /////////////////////////////////////////////////////////////////////////////// + // PUBLIC + /////////////////////////////////////////////////////////////////////////////// + public: + /** + * @brief Contructor of a HUB + * @param sdk Unique pointer to the SDK + */ + AlliedVisionHub(std::unique_ptr& sdk); + + /** + * @brief Destructor of a HUB + */ + virtual ~AlliedVisionHub(); + + /////////////////////////////////////////////////////////////////////////////// + // uMANAGER API METHODS + /////////////////////////////////////////////////////////////////////////////// + int DetectInstalledDevices() override; + int Initialize() override; + int Shutdown() override; + void GetName(char* name) const override; + bool Busy() override; + + /////////////////////////////////////////////////////////////////////////////// + // PRIVATE + /////////////////////////////////////////////////////////////////////////////// + private: + std::unique_ptr& m_sdk; // Date: Thu, 13 Jul 2023 14:38:23 +0200 Subject: [PATCH 07/43] Fixes Changes: - Fix to hide event/chunk category properties - Fix for command properties that were broken - Fix for handling TriggerMode scenario and capturing images in LIVE mode - Fix for cleaning capturing state of camera in case of error Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 206 +++++++++--------- .../AlliedVisionCamera/AlliedVisionCamera.h | 5 + 2 files changed, 102 insertions(+), 109 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 3735710fb..d64998ab9 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -63,7 +63,7 @@ MODULE_API MM::Device* CreateDevice(const char* deviceName) { if (g_api == nullptr) { g_api = std::make_unique(); } - if(g_api == nullptr || !g_api->isInitialized()){ + if (g_api == nullptr || !g_api->isInitialized()) { return nullptr; } @@ -98,6 +98,7 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName, m_buffer{}, m_bufferSize{0}, m_isAcquisitionRunning{false} { + CreateHubIDProperty(); // [Rule] Create properties here (pre-init only) InitializeDefaultErrorMessages(); setApiErrorMessages(); @@ -122,6 +123,7 @@ int AlliedVisionCamera::Initialize() { int AlliedVisionCamera::Shutdown() { // [Rule] Implement disconnection here + (void)StopSequenceAcquisition(); LogMessage("Shutting down camera: " + m_cameraName); if (m_handle != nullptr) { VmbError_t err = m_sdk->VmbCameraClose_t(m_handle); @@ -222,14 +224,30 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( return err; } + std::string featureCategory = feature->category; + if (featureCategory.find(g_EventCategory) != std::string::npos || + featureCategory.find(g_ChunkCategory) != std::string::npos) { + return err; + } + switch (feature->featureDataType) { case VmbFeatureDataInt: { err = CreateIntegerProperty(propName.c_str(), 0, true, callback); break; } - case VmbFeatureDataBool: + case VmbFeatureDataBool: { + err = CreateStringProperty(propName.c_str(), g_False, true, callback); + AddAllowedValue(propName.c_str(), g_False); + AddAllowedValue(propName.c_str(), g_True); + break; + } + case VmbFeatureDataCommand: { + err = CreateStringProperty(propName.c_str(), g_Command, true, callback); + AddAllowedValue(propName.c_str(), g_Command); + AddAllowedValue(propName.c_str(), g_Execute); + break; + } case VmbFeatureDataEnum: - case VmbFeatureDataCommand: case VmbFeatureDataString: { err = CreateStringProperty(propName.c_str(), "", true, callback); break; @@ -494,30 +512,11 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, return err; } - featureAvailable = (rMode || wMode); - if (!featureAvailable) { - return err; - } - - readOnly = featureAvailable && (rMode && !wMode); + readOnly = (rMode && !wMode); // Get values of property and features std::string propertyValue, featureHorizontalValue, featureVerticalValue; pProp->Get(propertyValue); - err = getFeatureValue(&featureInfoHorizontal, g_BinningHorizontalFeature, - featureHorizontalValue); - if (VmbErrorSuccess != err) { - return err; - } - err = getFeatureValue(&featureInfoVertical, g_BinningVerticalFeature, - featureVerticalValue); - if (VmbErrorSuccess != err) { - return err; - } - - std::string featureValue = - std::to_string(std::min(atoi(featureHorizontalValue.c_str()), - atoi(featureVerticalValue.c_str()))); MM::Property* pChildProperty = (MM::Property*)pProp; std::vector strValues; @@ -525,14 +524,32 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, switch (eAct) { case MM::ActionType::BeforeGet: - // Update property - if (propertyValue != featureValue) { - pProp->Set(featureValue.c_str()); + if (rMode) { + err = + getFeatureValue(&featureInfoHorizontal, g_BinningHorizontalFeature, + featureHorizontalValue); + if (VmbErrorSuccess != err) { + return err; + } + err = getFeatureValue(&featureInfoVertical, g_BinningVerticalFeature, + featureVerticalValue); + if (VmbErrorSuccess != err) { + return err; + } + + std::string featureValue = + std::to_string(std::min(atoi(featureHorizontalValue.c_str()), + atoi(featureVerticalValue.c_str()))); + // Update property + if (propertyValue != featureValue) { + pProp->Set(featureValue.c_str()); + } } + // Update property's access mode pChildProperty->SetReadOnly(readOnly); // Update property's limits and allowed values - if (!readOnly) { + if (wMode) { // Update binning limits err = m_sdk->VmbFeatureIntRangeQuery_t(m_handle, g_BinningHorizontalFeature, @@ -559,7 +576,7 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, } break; case MM::ActionType::AfterSet: - if (propertyValue != featureValue) { + if (wMode) { VmbError_t errHor = setFeatureValue( &featureInfoHorizontal, g_BinningHorizontalFeature, propertyValue); VmbError_t errVer = setFeatureValue( @@ -618,12 +635,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, return err; } - featureAvailable = (rMode || wMode); - if (!featureAvailable) { - return err; - } - - readOnly = featureAvailable && (rMode && !wMode); + readOnly = (rMode && !wMode); // Get values std::string propertyValue, featureValue; @@ -642,15 +654,15 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, if (propertyValue != featureValue) { pProp->Set(featureValue.c_str()); } + } - // Update property's access mode - pChildProperty->SetReadOnly(readOnly); - // Update property's limits and allowed values - if (!readOnly) { - err = setAllowedValues(&featureInfo, propertyName.c_str()); - if (VmbErrorSuccess != err) { - return err; - } + // Update property's access mode + pChildProperty->SetReadOnly(readOnly); + // Update property's limits and allowed values + if (wMode) { + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) { + return err; } } break; @@ -772,6 +784,7 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, std::stringstream ss(value); bool isDone = false; VmbUint32_t maxLen = 0; + std::string property{}; switch (featureInfo->featureDataType) { case VmbFeatureDataBool: { @@ -811,15 +824,25 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, break; } case VmbFeatureDataCommand: - err = m_sdk->VmbFeatureCommandRun_t(m_handle, featureName); - if (err != VmbErrorSuccess) { - break; - } - while (!isDone) { - err = m_sdk->VmbFeatureCommandIsDone_t(m_handle, featureName, &isDone); - if (err != VmbErrorSuccess) { - LogMessageCode(err); - break; + if (value == g_Execute) { + mapFeatureNameToPropertyName(featureName, property); + if (!property.empty()) { + err = m_sdk->VmbFeatureCommandRun_t(m_handle, featureName); + if (err != VmbErrorSuccess) { + break; + } + while (!isDone) { + err = m_sdk->VmbFeatureCommandIsDone_t(m_handle, featureName, + &isDone); + if (err != VmbErrorSuccess) { + LogMessageCode(err); + break; + } + } + // Set back property to "Command" + SetProperty(property.c_str(), g_Command); + } else { + err = VmbErrorInvalidValue; } } break; @@ -901,9 +924,9 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, } switch (feature->featureDataType) { + case VmbFeatureDataCommand: case VmbFeatureDataBool: { - AddAllowedValue(propertyName, g_False); - AddAllowedValue(propertyName, g_True); + // Already set in creation break; } case VmbFeatureDataFloat: { @@ -984,11 +1007,6 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, err = SetPropertyLimits(propertyName, min, max); break; } - case VmbFeatureDataCommand: { - AddAllowedValue(propertyName, g_Command); - AddAllowedValue(propertyName, g_Execute); - break; - } case VmbFeatureDataString: case VmbFeatureDataRaw: case VmbFeatureDataNone: @@ -1001,7 +1019,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, } int AlliedVisionCamera::SnapImage() { - if (m_isAcquisitionRunning) { + if (IsCapturing()) { return DEVICE_CAMERA_BUSY_ACQUIRING; } resizeImageBuffer(); @@ -1012,57 +1030,27 @@ int AlliedVisionCamera::SnapImage() { VmbError_t err = m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbCaptureStart_t(m_handle); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbCaptureEnd_t(m_handle); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbCaptureQueueFlush_t(m_handle); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbFrameRevokeAll_t(m_handle); - if (err != VmbErrorSuccess) { - return err; + if (err == VmbErrorSuccess) { + err = m_sdk->VmbCaptureStart_t(m_handle); + if (err == VmbErrorSuccess) { + err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); + if (err == VmbErrorSuccess) { + err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); + m_isAcquisitionRunning = true; + if (err == VmbErrorSuccess) { + err = m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); + } + } + } } - + (void)StopSequenceAcquisition(); return err; } int AlliedVisionCamera::StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow) { - if (m_isAcquisitionRunning) { + if (IsCapturing()) { return DEVICE_CAMERA_BUSY_ACQUIRING; } @@ -1107,12 +1095,13 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, return err; } - err = m_sdk->VmbFeatureCommandRun_t(m_handle, "AcquisitionStart"); + err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); if (err != VmbErrorSuccess) { return err; } m_isAcquisitionRunning = true; + return err; } @@ -1120,13 +1109,12 @@ int AlliedVisionCamera::StartSequenceAcquisition(double interval_ms) { return StartSequenceAcquisition(LONG_MAX, interval_ms, true); } int AlliedVisionCamera::StopSequenceAcquisition() { - if (m_isAcquisitionRunning) { - auto err = m_sdk->VmbFeatureCommandRun_t(m_handle, "AcquisitionStop"); + if (IsCapturing()) { + auto err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStop); + m_isAcquisitionRunning = false; if (err != VmbErrorSuccess) { return err; } - - m_isAcquisitionRunning = false; } auto err = m_sdk->VmbCaptureEnd_t(m_handle); @@ -1168,7 +1156,7 @@ void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { md.Serialize().c_str(), false); } - if (m_isAcquisitionRunning) { + if (IsCapturing()) { m_sdk->VmbCaptureFrameQueue_t( m_handle, frame, [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 4f62e5032..4c0d553b8 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -48,6 +48,11 @@ static constexpr const char* g_True = "True"; static constexpr const char* g_False = "False"; static constexpr const char* g_Execute = "Execute"; static constexpr const char* g_Command = "Command"; +static constexpr const char* g_ChunkCategory = "ChunkDataControl"; +static constexpr const char* g_EventCategory = "EventControl"; +static constexpr const char* g_AcquisitionStart = "AcquisitionStart"; +static constexpr const char* g_AcquisitionStop = "AcquisitionStop"; +static constexpr const char* g_AcqusitionStatus = "AcqusitionStatus"; /** * @brief Global pointer to the Vimba API, that needs to be released in a From fa12156c3b1672b0962f07ac4be06fa76b7cecb4 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Fri, 14 Jul 2023 10:57:10 +0200 Subject: [PATCH 08/43] Refactoring Changes: - Added error handling for symbols resolve and SDK init - Changed way of SDK object creation/deletion to shared_ptr Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 25 ++-- .../AlliedVisionCamera/AlliedVisionCamera.h | 11 +- .../AlliedVisionCamera/AlliedVisionHub.cpp | 15 +-- .../AlliedVisionCamera/AlliedVisionHub.h | 13 +- .../SDK/Loader/LibLoader.cpp | 121 ++++++++++-------- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 6 +- 6 files changed, 103 insertions(+), 88 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index d64998ab9..024e23efd 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -60,17 +60,10 @@ MODULE_API MM::Device* CreateDevice(const char* deviceName) { return nullptr; } - if (g_api == nullptr) { - g_api = std::make_unique(); - } - if (g_api == nullptr || !g_api->isInitialized()) { - return nullptr; - } - if (std::string(deviceName) == std::string(g_hubName)) { - return new AlliedVisionHub(g_api); + return new AlliedVisionHub(); } else { - return new AlliedVisionCamera(deviceName, g_api); + return new AlliedVisionCamera(deviceName); } } @@ -88,23 +81,29 @@ AlliedVisionCamera::~AlliedVisionCamera() { } } -AlliedVisionCamera::AlliedVisionCamera(const char* deviceName, - std::unique_ptr& sdk) +AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) : CCameraBase(), - m_sdk(sdk), + m_sdk(nullptr), m_handle{nullptr}, m_cameraName{deviceName}, m_frames{}, m_buffer{}, m_bufferSize{0}, m_isAcquisitionRunning{false} { - CreateHubIDProperty(); // [Rule] Create properties here (pre-init only) + CreateHubIDProperty(); InitializeDefaultErrorMessages(); setApiErrorMessages(); } int AlliedVisionCamera::Initialize() { + auto parentHub = dynamic_cast(GetParentHub()); + if (parentHub == nullptr) { + LogMessage("Parent HUB not found!"); + return DEVICE_ERR; + } + + m_sdk = parentHub->getSDK(); // [Rule] Implement communication here LogMessage("Opening camera: " + m_cameraName); VmbError_t err = m_sdk->VmbCameraOpen_t( diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 4c0d553b8..146b41ebd 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -54,12 +54,6 @@ static constexpr const char* g_AcquisitionStart = "AcquisitionStart"; static constexpr const char* g_AcquisitionStop = "AcquisitionStop"; static constexpr const char* g_AcqusitionStatus = "AcqusitionStatus"; -/** - * @brief Global pointer to the Vimba API, that needs to be released in a - * correct way at the end - */ -static std::unique_ptr g_api{nullptr}; - /** * @brief Main Allied Vision Camera class */ @@ -71,9 +65,8 @@ class AlliedVisionCamera : public CCameraBase { /** * @brief Contructor of Allied Vision Camera * @param[in] deviceName Device name - * @param[in] sdk Unique pointer to the SDK */ - AlliedVisionCamera(const char* deviceName, std::unique_ptr& sdk); + AlliedVisionCamera(const char* deviceName); /** * @brief Allied Vision Camera destructor */ @@ -239,7 +232,7 @@ class AlliedVisionCamera : public CCameraBase { /////////////////////////////////////////////////////////////////////////////// // MEMBERS /////////////////////////////////////////////////////////////////////////////// - std::unique_ptr& m_sdk; // m_sdk; // m_frames; //& sdk) : m_sdk(sdk) {} - -AlliedVisionHub::~AlliedVisionHub() { - // Release static SDK variable from DLL, otherwise process will not be - // killed, destructor not called - m_sdk.reset(); -} +AlliedVisionHub::AlliedVisionHub() : m_sdk(std::make_shared()) {} int AlliedVisionHub::DetectInstalledDevices() { VmbUint32_t camNum; @@ -23,8 +17,7 @@ int AlliedVisionHub::DetectInstalledDevices() { if (err == VmbErrorSuccess) { for (VmbUint32_t i = 0; i < camNum; ++i) { if (camInfo[i].permittedAccess & VmbAccessModeFull) { - MM::Device* pDev = - new AlliedVisionCamera(camInfo[i].cameraIdString, m_sdk); + MM::Device* pDev = new AlliedVisionCamera(camInfo[i].cameraIdString); AddInstalledDevice(pDev); } } @@ -37,7 +30,7 @@ int AlliedVisionHub::DetectInstalledDevices() { } int AlliedVisionHub::Initialize() { - LogMessage("Init HUB"); + LogMessage("Init HUB"); return DEVICE_OK; } @@ -51,3 +44,5 @@ void AlliedVisionHub::GetName(char* name) const { } bool AlliedVisionHub::Busy() { return false; } + +std::shared_ptr& AlliedVisionHub::getSDK() { return m_sdk; } diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h index dea6c36db..a18629d94 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h @@ -37,14 +37,19 @@ class AlliedVisionHub : public HubBase { public: /** * @brief Contructor of a HUB - * @param sdk Unique pointer to the SDK */ - AlliedVisionHub(std::unique_ptr& sdk); + AlliedVisionHub(); /** * @brief Destructor of a HUB */ - virtual ~AlliedVisionHub(); + virtual ~AlliedVisionHub() = default; + + /** + * @brief SDK getter + * @return Pointer to SDK + */ + std::shared_ptr& getSDK(); /////////////////////////////////////////////////////////////////////////////// // uMANAGER API METHODS @@ -59,7 +64,7 @@ class AlliedVisionHub : public HubBase { // PRIVATE /////////////////////////////////////////////////////////////////////////////// private: - std::unique_ptr& m_sdk; // m_sdk; // Date: Fri, 14 Jul 2023 21:40:40 +0200 Subject: [PATCH 09/43] Refactoring Changes: - Refactoring of existing solution Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 458 ++++++++---------- .../AlliedVisionCamera/AlliedVisionCamera.h | 22 +- .../AlliedVisionCamera.vcxproj | 2 - .../AlliedVisionCamera.vcxproj.filters | 6 - .../AlliedVisionCamera/AlliedVisionHub.cpp | 1 + .../AlliedVisionCamera/PropertyItem.cpp | 5 - .../AlliedVisionCamera/PropertyItem.h | 43 -- 7 files changed, 204 insertions(+), 333 deletions(-) delete mode 100644 DeviceAdapters/AlliedVisionCamera/PropertyItem.cpp delete mode 100644 DeviceAdapters/AlliedVisionCamera/PropertyItem.h diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 024e23efd..f386d0614 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -72,7 +72,6 @@ MODULE_API void DeleteDevice(MM::Device* pDevice) { delete pDevice; } /////////////////////////////////////////////////////////////////////////////// // AlliedVisionCamera /////////////////////////////////////////////////////////////////////////////// - AlliedVisionCamera::~AlliedVisionCamera() { m_handle = nullptr; @@ -90,7 +89,6 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) m_buffer{}, m_bufferSize{0}, m_isAcquisitionRunning{false} { - // [Rule] Create properties here (pre-init only) CreateHubIDProperty(); InitializeDefaultErrorMessages(); setApiErrorMessages(); @@ -102,9 +100,8 @@ int AlliedVisionCamera::Initialize() { LogMessage("Parent HUB not found!"); return DEVICE_ERR; } - m_sdk = parentHub->getSDK(); - // [Rule] Implement communication here + LogMessage("Opening camera: " + m_cameraName); VmbError_t err = m_sdk->VmbCameraOpen_t( m_cameraName.c_str(), VmbAccessModeType::VmbAccessModeFull, &m_handle); @@ -115,23 +112,20 @@ int AlliedVisionCamera::Initialize() { // Init properties and buffer // TODO handle error setupProperties(); - resizeImageBuffer(); - return DEVICE_OK; + return resizeImageBuffer(); } int AlliedVisionCamera::Shutdown() { - // [Rule] Implement disconnection here - (void)StopSequenceAcquisition(); LogMessage("Shutting down camera: " + m_cameraName); + VmbError_t err = VmbErrorSuccess; + + (void)StopSequenceAcquisition(); if (m_handle != nullptr) { - VmbError_t err = m_sdk->VmbCameraClose_t(m_handle); - if (err != VmbErrorSuccess) { - return err; - } + err = m_sdk->VmbCameraClose_t(m_handle); } - return DEVICE_OK; + return err; } void AlliedVisionCamera::setApiErrorMessages() { @@ -146,6 +140,13 @@ void AlliedVisionCamera::setApiErrorMessages() { SetErrorText(VmbErrorInvalidValue, "The value is not valid: either out of bounds or not an " "increment of the minimum"); + SetErrorText(VmbErrorBadHandle, "Given device handle is not valid"); + SetErrorText(VmbErrorInvalidAccess, + "Operation is invalid with the current access mode"); + SetErrorText(VmbErrorTimeout, "Timeout occured"); + SetErrorText(VmbErrorNotAvailable, "Something is not available"); + SetErrorText(VmbErrorNotInitialized, "Something is not initialized"); + SetErrorText(VmbErrorAlready, "The operation has been already done"); } VmbError_t AlliedVisionCamera::setupProperties() { @@ -166,16 +167,14 @@ VmbError_t AlliedVisionCamera::setupProperties() { const VmbFeatureInfo_t* end = features.get() + featureCount; for (VmbFeatureInfo_t* feature = features.get(); feature != end; ++feature) { - // uManager callback - CPropertyAction* callback = - new CPropertyAction(this, &AlliedVisionCamera::onProperty); - - err = createPropertyFromFeature(feature, callback); + err = createPropertyFromFeature(feature); if (err != VmbErrorSuccess) { LogMessageCode(err); continue; } } + + return VmbErrorSuccess; } VmbError_t AlliedVisionCamera::resizeImageBuffer() { @@ -193,66 +192,77 @@ VmbError_t AlliedVisionCamera::resizeImageBuffer() { } VmbError_t AlliedVisionCamera::createPropertyFromFeature( - const VmbFeatureInfo_t* feature, MM::ActionFunctor* callback) { + const VmbFeatureInfo_t* feature) { if (feature == nullptr) { return VmbErrorInvalidValue; } - auto featureName = feature->name; VmbError_t err = VmbErrorSuccess; - std::string propName = {}; - mapFeatureNameToPropertyName(featureName, propName); + // Skip Event and Chunk features + std::string featureCategory = feature->category; + if (featureCategory.find(g_EventCategory) != std::string::npos || + featureCategory.find(g_ChunkCategory) != std::string::npos) { + return err; + } + + // Map feature to property name + std::string propertyName = {}; + mapFeatureNameToPropertyName(feature->name, propertyName); + + // uManager callback + CPropertyAction* uManagerCallback = + new CPropertyAction(this, &AlliedVisionCamera::onProperty); // Vimba callback auto vmbCallback = [](VmbHandle_t handle, const char* name, void* userContext) { + (void)handle; AlliedVisionCamera* camera = reinterpret_cast(userContext); std::string propertyName; camera->mapFeatureNameToPropertyName(name, propertyName); - camera->UpdateProperty(propertyName.c_str()); + auto err = camera->UpdateProperty(propertyName.c_str()); + if (err != VmbErrorSuccess) { + camera->LogMessage("Property: " + propertyName + " update failed"); + } }; - // Add property to the list - m_propertyItems.insert({propName, {propName}}); - - // Register VMb callback - err = m_sdk->VmbFeatureInvalidationRegister_t(m_handle, featureName, + // Register VMB callback for given feature + err = m_sdk->VmbFeatureInvalidationRegister_t(m_handle, feature->name, vmbCallback, this); if (err != VmbErrorSuccess) { return err; } - std::string featureCategory = feature->category; - if (featureCategory.find(g_EventCategory) != std::string::npos || - featureCategory.find(g_ChunkCategory) != std::string::npos) { - return err; - } - switch (feature->featureDataType) { case VmbFeatureDataInt: { - err = CreateIntegerProperty(propName.c_str(), 0, true, callback); + err = CreateIntegerProperty(propertyName.c_str(), 0, true, + uManagerCallback); break; } case VmbFeatureDataBool: { - err = CreateStringProperty(propName.c_str(), g_False, true, callback); - AddAllowedValue(propName.c_str(), g_False); - AddAllowedValue(propName.c_str(), g_True); + err = CreateStringProperty(propertyName.c_str(), g_False, true, + uManagerCallback); + AddAllowedValue(propertyName.c_str(), g_False); + AddAllowedValue(propertyName.c_str(), g_True); break; } case VmbFeatureDataCommand: { - err = CreateStringProperty(propName.c_str(), g_Command, true, callback); - AddAllowedValue(propName.c_str(), g_Command); - AddAllowedValue(propName.c_str(), g_Execute); + err = CreateStringProperty(propertyName.c_str(), g_Command, true, + uManagerCallback); + AddAllowedValue(propertyName.c_str(), g_Command); + AddAllowedValue(propertyName.c_str(), g_Execute); break; } case VmbFeatureDataEnum: case VmbFeatureDataString: { - err = CreateStringProperty(propName.c_str(), "", true, callback); + err = CreateStringProperty(propertyName.c_str(), "", true, + uManagerCallback); break; } case VmbFeatureDataFloat: { - err = CreateFloatProperty(propName.c_str(), 0.0, true, callback); + err = CreateFloatProperty(propertyName.c_str(), 0.0, true, + uManagerCallback); break; } case VmbFeatureDataUnknown: @@ -273,7 +283,7 @@ const unsigned char* AlliedVisionCamera::GetImageBuffer() { unsigned AlliedVisionCamera::GetImageWidth() const { char value[MM::MaxStrLength]; int ret = GetProperty(g_Width, value); - if (ret != DEVICE_OK) { + if (ret != VmbErrorSuccess) { return 0; } @@ -283,7 +293,7 @@ unsigned AlliedVisionCamera::GetImageWidth() const { unsigned AlliedVisionCamera::GetImageHeight() const { char value[MM::MaxStrLength]; int ret = GetProperty(g_Height, value); - if (ret != DEVICE_OK) { + if (ret != VmbErrorSuccess) { return 0; } @@ -305,7 +315,7 @@ unsigned AlliedVisionCamera::GetBitDepth() const { int AlliedVisionCamera::GetBinning() const { char value[MM::MaxStrLength]; int ret = GetProperty(MM::g_Keyword_Binning, value); - if (ret != DEVICE_OK) { + if (ret != VmbErrorSuccess) { return 0; } @@ -320,7 +330,7 @@ int AlliedVisionCamera::SetBinning(int binSize) { double AlliedVisionCamera::GetExposure() const { char strExposure[MM::MaxStrLength]; int ret = GetProperty(MM::g_Keyword_Exposure, strExposure); - if (ret != DEVICE_OK) { + if (ret != VmbErrorSuccess) { return 0.0; } @@ -338,56 +348,39 @@ int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, auto height = GetImageHeight(); VmbError_t err = VmbErrorSuccess; - if (xSize > width) { - std::string strValueX = std::to_string(x); - err = SetProperty(g_OffsetX, strValueX.c_str()); - if (err != DEVICE_OK) { - return err; - } + std::function setOffsetXProperty = [this](long x) { + return SetProperty(g_OffsetX, CDeviceUtils::ConvertToString(x)); + }; + std::function setOffsetYProperty = [this](long y) { + return SetProperty(g_OffsetY, CDeviceUtils::ConvertToString(y)); + }; + std::function setWidthProperty = [this](long xSize) { + return SetProperty(g_Width, CDeviceUtils::ConvertToString(xSize)); + }; + std::function setHeightProperty = [this](long ySize) { + return SetProperty(g_Height, CDeviceUtils::ConvertToString(ySize)); + }; - std::string strValueWidth = std::to_string(xSize); - err = SetProperty(g_Width, strValueWidth.c_str()); - if (err != DEVICE_OK) { + if (xSize > width) { + err = setOffsetXProperty(x) || setWidthProperty(xSize); + if (err != VmbErrorSuccess) { return err; } - } else { - std::string strValueWidth = std::to_string(xSize); - err = SetProperty(g_Width, strValueWidth.c_str()); - if (err != DEVICE_OK) { - return err; - } - - std::string strValueX = std::to_string(x); - err = SetProperty(g_OffsetX, strValueX.c_str()); - if (err != DEVICE_OK) { + err = setWidthProperty(xSize) || setOffsetXProperty(x); + if (err != VmbErrorSuccess) { return err; } } if (ySize > height) { - std::string strValueY = std::to_string(y); - err = SetProperty(g_OffsetY, strValueY.c_str()); - if (err != DEVICE_OK) { - return err; - } - - std::string strValueHeight = std::to_string(ySize); - err = SetProperty(g_Height, strValueHeight.c_str()); - if (err != DEVICE_OK) { + err = setOffsetYProperty(y) || setHeightProperty(ySize); + if (err != VmbErrorSuccess) { return err; } - } else { - std::string strValueHeight = std::to_string(ySize); - err = SetProperty(g_Height, strValueHeight.c_str()); - if (err != DEVICE_OK) { - return err; - } - - std::string strValueY = std::to_string(y); - err = SetProperty(g_OffsetY, strValueY.c_str()); - if (err != DEVICE_OK) { + err = setHeightProperty(ySize) || setOffsetYProperty(y); + if (err != VmbErrorSuccess) { return err; } } @@ -397,75 +390,41 @@ int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, unsigned& ySize) { - { - char strX[MM::MaxStrLength]; - auto ret = GetProperty(g_OffsetX, strX); - if (ret != DEVICE_OK) { - return ret; - } - x = atoi(strX); - } - { - char strY[MM::MaxStrLength]; - auto ret = GetProperty(g_OffsetY, strY); - if (ret != DEVICE_OK) { - return ret; - } - y = atoi(strY); - } - { - char strXSize[MM::MaxStrLength]; - auto ret = GetProperty(g_Width, strXSize); - if (ret != DEVICE_OK) { - return ret; - } - xSize = atoi(strXSize); - } - { - char strYSize[MM::MaxStrLength]; - auto ret = GetProperty(g_Height, strYSize); - if (ret != DEVICE_OK) { - return ret; + std::unordered_map fields = { + {g_OffsetX, x}, {g_OffsetY, y}, {g_Width, xSize}, {g_Height, ySize}}; + + std::array value; + VmbError_t err = VmbErrorSuccess; + for (auto& field : fields) { + value.fill(0x00); // Clean the buffer + err = GetProperty(field.first, value.data()); + if (err != VmbErrorSuccess) { + break; } - ySize = atoi(strYSize); + field.second = atoi(value.data()); } - return DEVICE_OK; + return err; } int AlliedVisionCamera::ClearROI() { std::string maxWidth, maxHeight; - VmbError_t err = getFeatureValue(g_WidthMax, maxWidth); - if (VmbErrorSuccess != err) { - return err; - } - - err = getFeatureValue(g_HeightMax, maxHeight); - if (VmbErrorSuccess != err) { - return err; - } - - std::string offsetXval = "0"; - std::string offsetYval = "0"; - - err = setFeatureValue(g_OffsetX, offsetXval); - if (VmbErrorSuccess != err) { - return err; - } - - err = setFeatureValue(g_OffsetY, offsetYval); + VmbError_t err = getFeatureValue(g_WidthMax, maxWidth) || + getFeatureValue(g_HeightMax, maxHeight); if (VmbErrorSuccess != err) { return err; } - err = setFeatureValue(g_Width, maxWidth); - if (VmbErrorSuccess != err) { - return err; - } + std::unordered_map fields = {{g_OffsetX, "0"}, + {g_OffsetY, "0"}, + {g_Width, maxWidth}, + {g_Height, maxHeight}}; - err = setFeatureValue(g_Height, maxHeight); - if (VmbErrorSuccess != err) { - return err; + for (auto& field : fields) { + err = setFeatureValue(field.first, field.second); + if (err != VmbErrorSuccess) { + break; + } } return resizeImageBuffer(); @@ -504,7 +463,7 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, // Get read/write mode - assume binning horizontal and vertical has the same // mode - bool rMode, wMode, readOnly, featureAvailable; + bool rMode, wMode, readOnly; err = m_sdk->VmbFeatureAccessQuery_t(m_handle, g_BinningVerticalFeature, &rMode, &wMode); if (VmbErrorSuccess != err) { @@ -590,7 +549,6 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, break; } - //// TODO return uManager error return err; } @@ -618,17 +576,12 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, } else { // Retrive each feature for (const auto& featureName : featureNames) { - // Get Feature Info + // Get Feature Info and Access Mode VmbFeatureInfo_t featureInfo; + bool rMode{}, wMode{}, readOnly{}; err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), - &featureInfo, sizeof(featureInfo)); - if (VmbErrorSuccess != err) { - return err; - } - - // Get Access Mode - bool rMode, wMode, readOnly, featureAvailable; - err = m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), + &featureInfo, sizeof(featureInfo)) || + m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, &wMode); if (VmbErrorSuccess != err) { return err; @@ -660,28 +613,31 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Update property's limits and allowed values if (wMode) { err = setAllowedValues(&featureInfo, propertyName.c_str()); - if (VmbErrorSuccess != err) { - return err; - } } break; case MM::ActionType::AfterSet: //!< Update feature from property if (wMode) { err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); - if (err != VmbErrorSuccess) { - if (featureInfo.featureDataType == - VmbFeatureDataType::VmbFeatureDataFloat || - featureInfo.featureDataType == - VmbFeatureDataType::VmbFeatureDataInt) { - auto propertyItem = m_propertyItems.at(propertyName); - std::string adjustedValue = - adjustValue(propertyItem.m_min, propertyItem.m_max, - propertyItem.m_step, std::stod(propertyValue)); - pProp->Set(adjustedValue.c_str()); - err = setFeatureValue(&featureInfo, featureName.c_str(), - adjustedValue); + if (err == VmbErrorInvalidValue) { + // Update limits first to have latest min and max + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) { + return err; } + + // Adjust value + double min{}, max{}; + err = GetPropertyLowerLimit(propertyName.c_str(), min) || + GetPropertyUpperLimit(propertyName.c_str(), max); + if (VmbErrorSuccess != err) { + return err; + } + std::string adjustedValue = + adjustValue(featureInfo, min, max, std::stod(propertyValue)); + pProp->Set(adjustedValue.c_str()); + err = setFeatureValue(&featureInfo, featureName.c_str(), + adjustedValue); } } break; @@ -839,7 +795,7 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, } } // Set back property to "Command" - SetProperty(property.c_str(), g_Command); + err = SetProperty(property.c_str(), g_Command); } else { err = VmbErrorInvalidValue; } @@ -890,8 +846,36 @@ void AlliedVisionCamera::mapPropertyNameToFeatureNames( } } -std::string AlliedVisionCamera::adjustValue(double min, double max, double step, +std::string AlliedVisionCamera::adjustValue(VmbFeatureInfo_t& featureInfo, + double min, double max, double propertyValue) const { + VmbError_t err = VmbErrorSuccess; + double step = 1.0; + VmbInt64_t stepI = 1; + bool isIncremental = true; + switch (featureInfo.featureDataType) { + case VmbFeatureDataFloat: + err = m_sdk->VmbFeatureFloatIncrementQuery_t(m_handle, featureInfo.name, + &isIncremental, &step); + break; + case VmbFeatureDataInt: + err = m_sdk->VmbFeatureIntIncrementQuery_t(m_handle, featureInfo.name, + &stepI); + step = static_cast(stepI); + break; + default: + // nothing + break; + } + if (VmbErrorSuccess != err) { + LogMessage("Cannot get feature incremental step to adjust a value"); + return std::to_string(propertyValue); + } + + if (!isIncremental) { + return std::to_string(propertyValue); + } + if (propertyValue > max) { return std::to_string(max); } @@ -916,11 +900,6 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, } VmbError_t err = VmbErrorSuccess; - auto search = m_propertyItems.find(propertyName); - if (search == m_propertyItems.end()) { - LogMessage("Cannot find propery on internal list"); - return VmbErrorInvalidValue; - } switch (feature->featureDataType) { case VmbFeatureDataCommand: @@ -929,33 +908,13 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, break; } case VmbFeatureDataFloat: { - double min = 0; - double max = 0; + double min, max; err = m_sdk->VmbFeatureFloatRangeQuery_t(m_handle, feature->name, &min, &max); if (VmbErrorSuccess != err || min == max) { return err; } - double step = 0.0; - bool isIncremental = false; - err = m_sdk->VmbFeatureFloatIncrementQuery_t(m_handle, feature->name, - &isIncremental, &step); - if (VmbErrorSuccess != err) { - return err; - } - - PropertyItem tempProp{propertyName, static_cast(min), - static_cast(max), - static_cast(step)}; - if (tempProp == search->second) { - break; - } - - m_propertyItems.at(propertyName).m_min = static_cast(min); - m_propertyItems.at(propertyName).m_max = static_cast(max); - m_propertyItems.at(propertyName).m_step = static_cast(step); - err = SetPropertyLimits(propertyName, min, max); break; } @@ -977,7 +936,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, break; } case VmbFeatureDataInt: { - VmbInt64_t min, max, step; + VmbInt64_t min, max; std::vector strValues; err = @@ -986,24 +945,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, return err; } - err = - m_sdk->VmbFeatureIntIncrementQuery_t(m_handle, feature->name, &step); - if (VmbErrorSuccess != err) { - return err; - } - - PropertyItem tempProp{propertyName, static_cast(min), - static_cast(max), - static_cast(step)}; - if (tempProp == search->second) { - break; - } - - m_propertyItems.at(propertyName).m_min = static_cast(min); - m_propertyItems.at(propertyName).m_max = static_cast(max); - m_propertyItems.at(propertyName).m_step = static_cast(step); - - err = SetPropertyLimits(propertyName, min, max); + err = SetPropertyLimits(propertyName, static_cast(min), static_cast(max)); break; } case VmbFeatureDataString: @@ -1028,37 +970,30 @@ int AlliedVisionCamera::SnapImage() { frame.bufferSize = m_bufferSize; VmbError_t err = - m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); - if (err == VmbErrorSuccess) { - err = m_sdk->VmbCaptureStart_t(m_handle); - if (err == VmbErrorSuccess) { - err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); - if (err == VmbErrorSuccess) { - err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); - m_isAcquisitionRunning = true; - if (err == VmbErrorSuccess) { - err = m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); - } - } - } - } + m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)) || + m_sdk->VmbCaptureStart_t(m_handle) || + m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr) || + m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart) || + m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); + + m_isAcquisitionRunning = true; (void)StopSequenceAcquisition(); + return err; } int AlliedVisionCamera::StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow) { + (void)stopOnOverflow; + (void)interval_ms; + (void)numImages; + if (IsCapturing()) { return DEVICE_CAMERA_BUSY_ACQUIRING; } - int err = GetCoreCallback()->PrepareForAcq(this); - if (err != DEVICE_OK) { - return err; - } - - err = resizeImageBuffer(); + int err = GetCoreCallback()->PrepareForAcq(this) || resizeImageBuffer(); if (err != VmbErrorSuccess) { return err; } @@ -1071,36 +1006,31 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, m_frames[i].context[1] = reinterpret_cast(i); //VmbFrameAnnounce_t(m_handle, &(m_frames[i]), sizeof(VmbFrame_t)); - if (err != VmbErrorSuccess) { - return err; - } + auto frameCallback = [](const VmbHandle_t cameraHandle, + const VmbHandle_t streamHandle, VmbFrame_t* frame) { + (void)cameraHandle; + (void)streamHandle; + reinterpret_cast(frame->context[0]) + ->insertFrame(frame); + }; - err = m_sdk->VmbCaptureFrameQueue_t( - m_handle, &(m_frames[i]), - [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, - VmbFrame_t* frame) { - reinterpret_cast(frame->context[0]) - ->insertFrame(frame); - }); + err = + m_sdk->VmbFrameAnnounce_t(m_handle, &(m_frames[i]), + sizeof(VmbFrame_t)) || + m_sdk->VmbCaptureFrameQueue_t(m_handle, &(m_frames[i]), frameCallback); if (err != VmbErrorSuccess) { return err; } } - err = m_sdk->VmbCaptureStart_t(m_handle); - if (err != VmbErrorSuccess) { - return err; - } + err = m_sdk->VmbCaptureStart_t(m_handle) || + m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); + m_isAcquisitionRunning = true; - err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); if (err != VmbErrorSuccess) { return err; } - m_isAcquisitionRunning = true; - return err; } @@ -1108,6 +1038,7 @@ int AlliedVisionCamera::StartSequenceAcquisition(double interval_ms) { return StartSequenceAcquisition(LONG_MAX, interval_ms, true); } int AlliedVisionCamera::StopSequenceAcquisition() { + // This method shall never return any error if (IsCapturing()) { auto err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStop); m_isAcquisitionRunning = false; @@ -1116,20 +1047,9 @@ int AlliedVisionCamera::StopSequenceAcquisition() { } } - auto err = m_sdk->VmbCaptureEnd_t(m_handle); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbCaptureQueueFlush_t(m_handle); - if (err != VmbErrorSuccess) { - return err; - } - - err = m_sdk->VmbFrameRevokeAll_t(m_handle); - if (err != VmbErrorSuccess) { - return err; - } + auto err = m_sdk->VmbCaptureEnd_t(m_handle) || + m_sdk->VmbCaptureQueueFlush_t(m_handle) || + m_sdk->VmbFrameRevokeAll_t(m_handle); return err; } @@ -1160,6 +1080,8 @@ void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { m_handle, frame, [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, VmbFrame_t* frame) { + (void)cameraHandle; + (void)streamHandle; reinterpret_cast(frame->context[0]) ->insertFrame(frame); }); diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 146b41ebd..86d4e0a39 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -25,7 +25,6 @@ #include "DeviceBase.h" #include "Loader/LibLoader.h" -#include "PropertyItem.h" /////////////////////////////////////////////////////////////////////////////// // STATIC FEATURE NAMES (FROM VIMBA) @@ -138,11 +137,9 @@ class AlliedVisionCamera : public CCameraBase { /** * @brief Helper method to create single uManager property from Vimba feature * @param[in] feature Pointer to the Vimba feature - * @param[in] callback uManager callback for given property * @return VmbError_t */ - VmbError_t createPropertyFromFeature(const VmbFeatureInfo_t* feature, - MM::ActionFunctor* callback); + VmbError_t createPropertyFromFeature(const VmbFeatureInfo_t* feature); /** * @brief Helper method to set allowed values for given property, based on @@ -220,13 +217,22 @@ class AlliedVisionCamera : public CCameraBase { /** * @brief In case trying to set invalid value, adjust it to the closest with * inceremntal step - * @param[in] min Minimum for given property - * @param[in] max Maximum for given property + * @param[in] step Incremental step + + * @return Adjusted value resresented as a string + */ + + /** + * @brief In case trying to set invalid value, adjust it to the closest with + * inceremntal step + * @param[in] featureInfo Feature info object + * @param[in] min Minimum for given property + * @param[in] max Maximum for given property * @param[in] propertyValue Value that was tried to be set * @return Adjusted value resresented as a string */ - std::string adjustValue(double min, double max, double step, + std::string adjustValue(VmbFeatureInfo_t& featureInfo, double min, double max, double propertyValue) const; /////////////////////////////////////////////////////////////////////////////// @@ -241,8 +247,6 @@ class AlliedVisionCamera : public CCameraBase { VmbUint32_t m_bufferSize; // - m_propertyItems; //!< Internal map of properties static const std::unordered_map m_featureToProperty; //!< Map of features name into uManager properties static const std::unordered_multimap diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj index ead62b67c..7174e830c 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj @@ -21,7 +21,6 @@ - @@ -34,7 +33,6 @@ - diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters index 2d7e866f7..15ee3a694 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters @@ -42,9 +42,6 @@ Header Files - - Header Files - Header Files @@ -56,9 +53,6 @@ Source Files - - Source Files - Source Files diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp index b800b5c8c..47f400949 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp @@ -5,6 +5,7 @@ AlliedVisionHub::AlliedVisionHub() : m_sdk(std::make_shared()) {} int AlliedVisionHub::DetectInstalledDevices() { + LogMessage("Detecting installed cameras..."); VmbUint32_t camNum; // Get the number of connected cameras first VmbError_t err = m_sdk->VmbCamerasList_t(nullptr, 0, &camNum, 0); diff --git a/DeviceAdapters/AlliedVisionCamera/PropertyItem.cpp b/DeviceAdapters/AlliedVisionCamera/PropertyItem.cpp deleted file mode 100644 index 4b0865174..000000000 --- a/DeviceAdapters/AlliedVisionCamera/PropertyItem.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "PropertyItem.h" - -PropertyItem::PropertyItem(const std::string& name, double min, double max, - double step) - : m_name(name), m_min(min), m_max(max), m_step(step) {} \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/PropertyItem.h b/DeviceAdapters/AlliedVisionCamera/PropertyItem.h deleted file mode 100644 index ed1232dd7..000000000 --- a/DeviceAdapters/AlliedVisionCamera/PropertyItem.h +++ /dev/null @@ -1,43 +0,0 @@ -/*============================================================================= - Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. - - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, - NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -=============================================================================*/ -#ifndef PROPERTYITEM_H -#define PROPERTYITEM_H - -#include - -/** - * @brief - */ -struct PropertyItem { - PropertyItem(const std::string& name, double min = 0.0, double max = 0.0, double step = 1.0); - ~PropertyItem() = default; - - bool operator==(PropertyItem& rhs) { - return rhs.m_name == m_name && rhs.m_min == m_min && rhs.m_max == m_max && - rhs.m_step == m_step; - } - bool operator!=(PropertyItem& rhs) { return !(rhs == *this); } - - std::string m_name; - double m_min; - double m_max; - double m_step; -}; - -#endif // PROPERTYITEM_H From 9edd88274aca9e135ab94f96b94365f7584e0bc6 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Mon, 17 Jul 2023 11:21:20 +0200 Subject: [PATCH 10/43] Error handling Changes: - Error handling for issues related to the loading SDK Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 36 +++++-------------- .../AlliedVisionCamera/AlliedVisionCamera.h | 5 --- .../AlliedVisionCamera/AlliedVisionHub.cpp | 33 +++++++++++++++-- .../AlliedVisionCamera/AlliedVisionHub.h | 7 +++- .../SDK/Loader/LibLoader.cpp | 6 ++-- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index f386d0614..37731e7bc 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -90,8 +90,6 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) m_bufferSize{0}, m_isAcquisitionRunning{false} { CreateHubIDProperty(); - InitializeDefaultErrorMessages(); - setApiErrorMessages(); } int AlliedVisionCamera::Initialize() { @@ -119,36 +117,16 @@ int AlliedVisionCamera::Initialize() { int AlliedVisionCamera::Shutdown() { LogMessage("Shutting down camera: " + m_cameraName); VmbError_t err = VmbErrorSuccess; - - (void)StopSequenceAcquisition(); - if (m_handle != nullptr) { - err = m_sdk->VmbCameraClose_t(m_handle); + if (m_sdk != nullptr && m_sdk->isInitialized()) { + (void)StopSequenceAcquisition(); + if (m_handle != nullptr) { + err = m_sdk->VmbCameraClose_t(m_handle); + } } return err; } -void AlliedVisionCamera::setApiErrorMessages() { - SetErrorText(VmbErrorApiNotStarted, "Vimba X API not started"); - SetErrorText(VmbErrorNotFound, "Device cannot be found"); - SetErrorText(VmbErrorDeviceNotOpen, "Device cannot be opened"); - SetErrorText(VmbErrorBadParameter, - "Invalid parameter passed to the function"); - SetErrorText(VmbErrorNotImplemented, "Feature not implemented"); - SetErrorText(VmbErrorNotSupported, "Feature not supported"); - SetErrorText(VmbErrorUnknown, "Unknown error"); - SetErrorText(VmbErrorInvalidValue, - "The value is not valid: either out of bounds or not an " - "increment of the minimum"); - SetErrorText(VmbErrorBadHandle, "Given device handle is not valid"); - SetErrorText(VmbErrorInvalidAccess, - "Operation is invalid with the current access mode"); - SetErrorText(VmbErrorTimeout, "Timeout occured"); - SetErrorText(VmbErrorNotAvailable, "Something is not available"); - SetErrorText(VmbErrorNotInitialized, "Something is not initialized"); - SetErrorText(VmbErrorAlready, "The operation has been already done"); -} - VmbError_t AlliedVisionCamera::setupProperties() { VmbUint32_t featureCount = 0; VmbError_t err = m_sdk->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, @@ -541,6 +519,7 @@ int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, &featureInfoVertical, g_BinningVerticalFeature, propertyValue); if (VmbErrorSuccess != errHor || VmbErrorSuccess != errVer) { //[IMPORTANT] For binning, adjust value is ignored + err = errHor | errVer; } } break; @@ -945,7 +924,8 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, return err; } - err = SetPropertyLimits(propertyName, static_cast(min), static_cast(max)); + err = SetPropertyLimits(propertyName, static_cast(min), + static_cast(max)); break; } case VmbFeatureDataString: diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 86d4e0a39..b530525a1 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -117,11 +117,6 @@ class AlliedVisionCamera : public CCameraBase { static constexpr const VmbUint8_t MAX_FRAMES = 7; //!<< Max frame number in the buffer - /** - * @brief Setup error messages for Vimba API - */ - void setApiErrorMessages(); - /** * @brief Resize all buffers for image frames * @return VmbError_t diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp index 47f400949..729962443 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp @@ -2,7 +2,10 @@ #include "AlliedVisionCamera.h" -AlliedVisionHub::AlliedVisionHub() : m_sdk(std::make_shared()) {} +AlliedVisionHub::AlliedVisionHub() : m_sdk(std::make_shared()) { + InitializeDefaultErrorMessages(); + setApiErrorMessages(); +} int AlliedVisionHub::DetectInstalledDevices() { LogMessage("Detecting installed cameras..."); @@ -32,7 +35,12 @@ int AlliedVisionHub::DetectInstalledDevices() { int AlliedVisionHub::Initialize() { LogMessage("Init HUB"); - return DEVICE_OK; + if (m_sdk->isInitialized()) { + return DEVICE_OK; + } else { + LogMessage("SDK not initialized!"); + return VmbErrorApiNotStarted; + } } int AlliedVisionHub::Shutdown() { @@ -47,3 +55,24 @@ void AlliedVisionHub::GetName(char* name) const { bool AlliedVisionHub::Busy() { return false; } std::shared_ptr& AlliedVisionHub::getSDK() { return m_sdk; } + +void AlliedVisionHub::setApiErrorMessages() { + SetErrorText(VmbErrorApiNotStarted, "Vimba X API not started"); + SetErrorText(VmbErrorNotFound, "Device cannot be found"); + SetErrorText(VmbErrorDeviceNotOpen, "Device cannot be opened"); + SetErrorText(VmbErrorBadParameter, + "Invalid parameter passed to the function"); + SetErrorText(VmbErrorNotImplemented, "Feature not implemented"); + SetErrorText(VmbErrorNotSupported, "Feature not supported"); + SetErrorText(VmbErrorUnknown, "Unknown error"); + SetErrorText(VmbErrorInvalidValue, + "The value is not valid: either out of bounds or not an " + "increment of the minimum"); + SetErrorText(VmbErrorBadHandle, "Given device handle is not valid"); + SetErrorText(VmbErrorInvalidAccess, + "Operation is invalid with the current access mode"); + SetErrorText(VmbErrorTimeout, "Timeout occured"); + SetErrorText(VmbErrorNotAvailable, "Something is not available"); + SetErrorText(VmbErrorNotInitialized, "Something is not initialized"); + SetErrorText(VmbErrorAlready, "The operation has been already done"); +} diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h index a18629d94..09c77aeba 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h @@ -48,9 +48,14 @@ class AlliedVisionHub : public HubBase { /** * @brief SDK getter * @return Pointer to SDK - */ + */ std::shared_ptr& getSDK(); + /** + * @brief Setup error messages for Vimba API + */ + void setApiErrorMessages(); + /////////////////////////////////////////////////////////////////////////////// // uMANAGER API METHODS /////////////////////////////////////////////////////////////////////////////// diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp index 95c43266c..44b6a5336 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp @@ -98,8 +98,10 @@ VimbaXApi::VimbaXApi() bool VimbaXApi::isInitialized() const { return m_initialized; } VimbaXApi::~VimbaXApi() { - m_initialized = false; - VmbShutdown_t(); + if (m_initialized) { + m_initialized = false; + VmbShutdown_t(); + } } LibLoader::LibLoader(const char* lib, const char* libPath) From 432e4eec120df9bcc6822e191239a6a4500c88f2 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Tue, 18 Jul 2023 10:14:30 +0200 Subject: [PATCH 11/43] Few fixes Changes: - Removed RAW features from the list - Reduced GetProperty calls that generates a lot of calls - Added calling OnPropertyChanged callback for Property Browser Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 41 +++++++++++-------- .../AlliedVisionCamera/AlliedVisionCamera.h | 4 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 37731e7bc..65839f70c 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -176,10 +176,11 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( } VmbError_t err = VmbErrorSuccess; - // Skip Event and Chunk features + // Skip Event, Chunk, RAW features std::string featureCategory = feature->category; if (featureCategory.find(g_EventCategory) != std::string::npos || - featureCategory.find(g_ChunkCategory) != std::string::npos) { + featureCategory.find(g_ChunkCategory) != std::string::npos || + feature->featureDataType == VmbFeatureDataRaw) { return err; } @@ -259,23 +260,23 @@ const unsigned char* AlliedVisionCamera::GetImageBuffer() { } unsigned AlliedVisionCamera::GetImageWidth() const { - char value[MM::MaxStrLength]; - int ret = GetProperty(g_Width, value); + std::string value{}; + auto ret = getFeatureValue(g_Width, value); if (ret != VmbErrorSuccess) { return 0; } - return atoi(value); + return atoi(value.c_str()); } unsigned AlliedVisionCamera::GetImageHeight() const { - char value[MM::MaxStrLength]; - int ret = GetProperty(g_Height, value); + std::string value{}; + auto ret = getFeatureValue(g_Height, value); if (ret != VmbErrorSuccess) { return 0; } - return atoi(value); + return atoi(value.c_str()); } unsigned AlliedVisionCamera::GetImageBytesPerPixel() const { @@ -306,13 +307,13 @@ int AlliedVisionCamera::SetBinning(int binSize) { } double AlliedVisionCamera::GetExposure() const { - char strExposure[MM::MaxStrLength]; - int ret = GetProperty(MM::g_Keyword_Exposure, strExposure); + std::string value{}; + auto ret = getFeatureValue(g_ExposureFeature, value); if (ret != VmbErrorSuccess) { - return 0.0; + return 0; } - return strtod(strExposure, nullptr); + return strtod(value.c_str(), nullptr); } void AlliedVisionCamera::SetExposure(double exp_ms) { @@ -371,11 +372,10 @@ int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, std::unordered_map fields = { {g_OffsetX, x}, {g_OffsetY, y}, {g_Width, xSize}, {g_Height, ySize}}; - std::array value; VmbError_t err = VmbErrorSuccess; for (auto& field : fields) { - value.fill(0x00); // Clean the buffer - err = GetProperty(field.first, value.data()); + std::string value{}; + err = getFeatureValue(field.first, value); if (err != VmbErrorSuccess) { break; } @@ -584,11 +584,17 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Update property if (propertyValue != featureValue) { pProp->Set(featureValue.c_str()); + err = GetCoreCallback()->OnPropertyChanged( + this, propertyName.c_str(), featureValue.c_str()); + if (VmbErrorSuccess != err) { + return err; + } } } // Update property's access mode pChildProperty->SetReadOnly(readOnly); + // Update property's limits and allowed values if (wMode) { err = setAllowedValues(&featureInfo, propertyName.c_str()); @@ -614,7 +620,6 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, } std::string adjustedValue = adjustValue(featureInfo, min, max, std::stod(propertyValue)); - pProp->Set(adjustedValue.c_str()); err = setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); } @@ -632,7 +637,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, const char* featureName, - std::string& value) { + std::string& value) const { VmbError_t err = VmbErrorSuccess; switch (featureInfo->featureDataType) { case VmbFeatureDataBool: { @@ -700,7 +705,7 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, } VmbError_t AlliedVisionCamera::getFeatureValue(const char* featureName, - std::string& value) { + std::string& value) const { VmbFeatureInfo_t featureInfo; VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( m_handle, featureName, &featureInfo, sizeof(featureInfo)); diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index b530525a1..8e5db5a8f 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -162,7 +162,7 @@ class AlliedVisionCamera : public CCameraBase { * @return VmbError_t */ VmbError_t getFeatureValue(VmbFeatureInfo_t* featureInfo, - const char* featureName, std::string& value); + const char* featureName, std::string& value) const; /** * @brief Method to get feature value, based on its type. Feature value is * always a string type. @@ -170,7 +170,7 @@ class AlliedVisionCamera : public CCameraBase { * @param[out] value Value of feature, read from device * @return VmbError_t */ - VmbError_t getFeatureValue(const char* featureName, std::string& value); + VmbError_t getFeatureValue(const char* featureName, std::string& value) const; /** * @brief Method to set a feature value, bases on its type. Feature value is From bad9b851b05509b922e8ba0b1a9d02beb2f4b8b6 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Wed, 19 Jul 2023 11:49:58 +0200 Subject: [PATCH 12/43] Binning and ROI changes Changes: - Removed generic Binning to have Vertical/Horizontal only - Changes to ROI Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 290 ++++++------------ .../AlliedVisionCamera/AlliedVisionCamera.h | 2 - 2 files changed, 87 insertions(+), 205 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 65839f70c..7e29d6ef4 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -37,16 +37,12 @@ const std::unordered_map AlliedVisionCamera::m_featureToProperty = { {g_PixelFormatFeature, MM::g_Keyword_PixelType}, - {g_ExposureFeature, MM::g_Keyword_Exposure}, - {g_BinningHorizontalFeature, MM::g_Keyword_Binning}, - {g_BinningVerticalFeature, MM::g_Keyword_Binning}}; + {g_ExposureFeature, MM::g_Keyword_Exposure}}; const std::unordered_multimap AlliedVisionCamera::m_propertyToFeature = { {MM::g_Keyword_PixelType, g_PixelFormatFeature}, - {MM::g_Keyword_Exposure, g_ExposureFeature}, - {MM::g_Keyword_Binning, g_BinningHorizontalFeature}, - {MM::g_Keyword_Binning, g_BinningVerticalFeature}}; + {MM::g_Keyword_Exposure, g_ExposureFeature}}; /////////////////////////////////////////////////////////////////////////////// // Exported MMDevice API @@ -292,18 +288,13 @@ unsigned AlliedVisionCamera::GetBitDepth() const { } int AlliedVisionCamera::GetBinning() const { - char value[MM::MaxStrLength]; - int ret = GetProperty(MM::g_Keyword_Binning, value); - if (ret != VmbErrorSuccess) { - return 0; - } - - return atoi(value); + // Binning not supported. We support BinningVertical/Horizontal + return 1; } int AlliedVisionCamera::SetBinning(int binSize) { - return SetProperty(MM::g_Keyword_Binning, - CDeviceUtils::ConvertToString(binSize)); + // Binning not supported. We support BinningVertical/Horizontal + return DEVICE_OK; } double AlliedVisionCamera::GetExposure() const { @@ -369,7 +360,7 @@ int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, unsigned& ySize) { - std::unordered_map fields = { + std::map fields = { {g_OffsetX, x}, {g_OffsetY, y}, {g_Width, xSize}, {g_Height, ySize}}; VmbError_t err = VmbErrorSuccess; @@ -393,10 +384,12 @@ int AlliedVisionCamera::ClearROI() { return err; } - std::unordered_map fields = {{g_OffsetX, "0"}, - {g_OffsetY, "0"}, - {g_Width, maxWidth}, - {g_Height, maxHeight}}; + // Keep the order of the fields + std::vector> fields = { + {g_OffsetX, "0"}, + {g_OffsetY, "0"}, + {g_Width, maxWidth}, + {g_Height, maxHeight}}; for (auto& field : fields) { err = setFeatureValue(field.first, field.second); @@ -419,118 +412,6 @@ void AlliedVisionCamera::GetName(char* name) const { bool AlliedVisionCamera::IsCapturing() { return m_isAcquisitionRunning; } -int AlliedVisionCamera::OnBinning(MM::PropertyBase* pProp, - MM::ActionType eAct) { - // Get horizonal binning - VmbFeatureInfo_t featureInfoHorizontal; - VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( - m_handle, g_BinningHorizontalFeature, &featureInfoHorizontal, - sizeof(featureInfoHorizontal)); - if (VmbErrorSuccess != err) { - return err; - } - - // Get vertical binning - VmbFeatureInfo_t featureInfoVertical; - err = m_sdk->VmbFeatureInfoQuery_t(m_handle, g_BinningVerticalFeature, - &featureInfoVertical, - sizeof(featureInfoVertical)); - if (VmbErrorSuccess != err) { - return err; - } - - // Get read/write mode - assume binning horizontal and vertical has the same - // mode - bool rMode, wMode, readOnly; - err = m_sdk->VmbFeatureAccessQuery_t(m_handle, g_BinningVerticalFeature, - &rMode, &wMode); - if (VmbErrorSuccess != err) { - return err; - } - - readOnly = (rMode && !wMode); - - // Get values of property and features - std::string propertyValue, featureHorizontalValue, featureVerticalValue; - pProp->Get(propertyValue); - - MM::Property* pChildProperty = (MM::Property*)pProp; - std::vector strValues; - VmbInt64_t minHorizontal, maxHorizontal, minVertical, maxVertical, min, max; - - switch (eAct) { - case MM::ActionType::BeforeGet: - if (rMode) { - err = - getFeatureValue(&featureInfoHorizontal, g_BinningHorizontalFeature, - featureHorizontalValue); - if (VmbErrorSuccess != err) { - return err; - } - err = getFeatureValue(&featureInfoVertical, g_BinningVerticalFeature, - featureVerticalValue); - if (VmbErrorSuccess != err) { - return err; - } - - std::string featureValue = - std::to_string(std::min(atoi(featureHorizontalValue.c_str()), - atoi(featureVerticalValue.c_str()))); - // Update property - if (propertyValue != featureValue) { - pProp->Set(featureValue.c_str()); - } - } - - // Update property's access mode - pChildProperty->SetReadOnly(readOnly); - // Update property's limits and allowed values - if (wMode) { - // Update binning limits - err = m_sdk->VmbFeatureIntRangeQuery_t(m_handle, - g_BinningHorizontalFeature, - &minHorizontal, &maxHorizontal); - if (VmbErrorSuccess != err) { - return err; - } - - err = m_sdk->VmbFeatureIntRangeQuery_t( - m_handle, g_BinningVerticalFeature, &minVertical, &maxVertical); - if (VmbErrorSuccess != err) { - return err; - } - - //[IMPORTANT] For binning, increment step is ignored - - min = std::max(minHorizontal, minVertical); - max = std::min(maxHorizontal, maxVertical); - - for (VmbInt64_t i = min; i <= max; i++) { - strValues.push_back(std::to_string(i)); - } - err = SetAllowedValues(pProp->GetName().c_str(), strValues); - } - break; - case MM::ActionType::AfterSet: - if (wMode) { - VmbError_t errHor = setFeatureValue( - &featureInfoHorizontal, g_BinningHorizontalFeature, propertyValue); - VmbError_t errVer = setFeatureValue( - &featureInfoVertical, g_BinningVerticalFeature, propertyValue); - if (VmbErrorSuccess != errHor || VmbErrorSuccess != errVer) { - //[IMPORTANT] For binning, adjust value is ignored - err = errHor | errVer; - } - } - break; - default: - // nothing - break; - } - - return err; -} - int AlliedVisionCamera::OnPixelType(MM::PropertyBase* pProp, MM::ActionType eAct) { // TODO implement @@ -548,87 +429,85 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Check property mapping mapPropertyNameToFeatureNames(propertyName.c_str(), featureNames); - if (propertyName == std::string(MM::g_Keyword_Binning)) { - // Binning requires special handling and combining two features into one - // property - OnBinning(pProp, eAct); - } else { - // Retrive each feature - for (const auto& featureName : featureNames) { - // Get Feature Info and Access Mode - VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}, readOnly{}; - err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), - &featureInfo, sizeof(featureInfo)) || - m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), - &rMode, &wMode); - if (VmbErrorSuccess != err) { - return err; - } + // Retrive each feature + for (const auto& featureName : featureNames) { + // Get Feature Info and Access Mode + VmbFeatureInfo_t featureInfo; + bool rMode{}, wMode{}, readOnly{}; + err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), + &featureInfo, sizeof(featureInfo)) || + m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, + &wMode); + if (VmbErrorSuccess != err) { + return err; + } + + readOnly = (rMode && !wMode); + //TODO + //Set somehow property to be unavailable when there is no r and w modes - readOnly = (rMode && !wMode); + // Get values + std::string propertyValue{}, featureValue{}; + pProp->Get(propertyValue); + + // Handle property value change + switch (eAct) { + case MM::ActionType::BeforeGet: //!< Update property from feature + if (rMode) { + err = + getFeatureValue(&featureInfo, featureName.c_str(), featureValue); + if (VmbErrorSuccess != err) { + return err; + } - // Get values - std::string propertyValue, featureValue; - pProp->Get(propertyValue); + // Update property + if (propertyValue != featureValue) { + pProp->Set(featureValue.c_str()); + err = GetCoreCallback()->OnPropertyChanged( + this, propertyName.c_str(), featureValue.c_str()); - // Handle property value change - switch (eAct) { - case MM::ActionType::BeforeGet: //!< Update property from feature - if (rMode) { - err = getFeatureValue(&featureInfo, featureName.c_str(), - featureValue); if (VmbErrorSuccess != err) { return err; } - // Update property - if (propertyValue != featureValue) { - pProp->Set(featureValue.c_str()); - err = GetCoreCallback()->OnPropertyChanged( - this, propertyName.c_str(), featureValue.c_str()); - if (VmbErrorSuccess != err) { - return err; - } - } } + } - // Update property's access mode - pChildProperty->SetReadOnly(readOnly); + // Update property's access mode + pChildProperty->SetReadOnly(readOnly); - // Update property's limits and allowed values - if (wMode) { + // Update property's limits and allowed values + if (wMode) { + err = setAllowedValues(&featureInfo, propertyName.c_str()); + } + break; + case MM::ActionType::AfterSet: //!< Update feature from property + if (wMode) { + err = + setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); + if (err == VmbErrorInvalidValue) { + // Update limits first to have latest min and max err = setAllowedValues(&featureInfo, propertyName.c_str()); - } - break; - case MM::ActionType::AfterSet: //!< Update feature from property - if (wMode) { - err = setFeatureValue(&featureInfo, featureName.c_str(), - propertyValue); - if (err == VmbErrorInvalidValue) { - // Update limits first to have latest min and max - err = setAllowedValues(&featureInfo, propertyName.c_str()); - if (VmbErrorSuccess != err) { - return err; - } - - // Adjust value - double min{}, max{}; - err = GetPropertyLowerLimit(propertyName.c_str(), min) || - GetPropertyUpperLimit(propertyName.c_str(), max); - if (VmbErrorSuccess != err) { - return err; - } - std::string adjustedValue = - adjustValue(featureInfo, min, max, std::stod(propertyValue)); - err = setFeatureValue(&featureInfo, featureName.c_str(), - adjustedValue); + if (VmbErrorSuccess != err) { + return err; + } + + // Adjust value + double min{}, max{}; + err = GetPropertyLowerLimit(propertyName.c_str(), min) || + GetPropertyUpperLimit(propertyName.c_str(), max); + if (VmbErrorSuccess != err) { + return err; } + std::string adjustedValue = + adjustValue(featureInfo, min, max, std::stod(propertyValue)); + err = setFeatureValue(&featureInfo, featureName.c_str(), + adjustedValue); } - break; - default: - // nothing - break; - } + } + break; + default: + // nothing + break; } } @@ -780,6 +659,8 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, } // Set back property to "Command" err = SetProperty(property.c_str(), g_Command); + GetCoreCallback()->OnPropertyChanged(this, property.c_str(), + g_Command); } else { err = VmbErrorInvalidValue; } @@ -1016,7 +897,7 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, return err; } - return err; + return UpdateStatus(); } int AlliedVisionCamera::StartSequenceAcquisition(double interval_ms) { @@ -1035,8 +916,11 @@ int AlliedVisionCamera::StopSequenceAcquisition() { auto err = m_sdk->VmbCaptureEnd_t(m_handle) || m_sdk->VmbCaptureQueueFlush_t(m_handle) || m_sdk->VmbFrameRevokeAll_t(m_handle); + if (err != VmbErrorSuccess) { + return err; + } - return err; + return UpdateStatus(); } void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 8e5db5a8f..bea9b8e2e 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -104,8 +104,6 @@ class AlliedVisionCamera : public CCameraBase { /////////////////////////////////////////////////////////////////////////////// int OnPixelType(MM::PropertyBase* pProp, MM::ActionType eAct); //!<< PixelType property callback - int OnBinning(MM::PropertyBase* pProp, - MM::ActionType eAct); //!<< Binning property callback int onProperty(MM::PropertyBase* pProp, MM::ActionType eAct); //!<< General property callback From 3bd5b99ba841e3a11d693b34c48716e173ff1fe1 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Fri, 21 Jul 2023 14:25:50 +0200 Subject: [PATCH 13/43] Error handling Changes: - Error handling improvements - Created a base class for devices to handle the same stuff everywhere - Created logging macro Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 138 ++++++++++++++---- .../AlliedVisionCamera/AlliedVisionCamera.h | 9 +- .../AlliedVisionCamera.vcxproj | 2 + .../AlliedVisionCamera.vcxproj.filters | 6 + .../AlliedVisionDeviceBase.cpp | 3 + .../AlliedVisionDeviceBase.h | 97 ++++++++++++ .../AlliedVisionCamera/AlliedVisionHub.cpp | 30 +--- .../AlliedVisionCamera/AlliedVisionHub.h | 14 +- 8 files changed, 229 insertions(+), 70 deletions(-) create mode 100644 DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.cpp create mode 100644 DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 7e29d6ef4..67e0b8a6c 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -77,8 +77,7 @@ AlliedVisionCamera::~AlliedVisionCamera() { } AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) - : CCameraBase(), - m_sdk(nullptr), + : m_sdk(nullptr), m_handle{nullptr}, m_cameraName{deviceName}, m_frames{}, @@ -91,8 +90,8 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) int AlliedVisionCamera::Initialize() { auto parentHub = dynamic_cast(GetParentHub()); if (parentHub == nullptr) { - LogMessage("Parent HUB not found!"); - return DEVICE_ERR; + LOG_ERROR(VmbErrorBadParameter, "Parent HUB not found!"); + return VmbErrorBadParameter; } m_sdk = parentHub->getSDK(); @@ -100,6 +99,7 @@ int AlliedVisionCamera::Initialize() { VmbError_t err = m_sdk->VmbCameraOpen_t( m_cameraName.c_str(), VmbAccessModeType::VmbAccessModeFull, &m_handle); if (err != VmbErrorSuccess || m_handle == nullptr) { + LOG_ERROR(err, "Error while opening camera or handle is NULL!"); return err; } @@ -127,7 +127,8 @@ VmbError_t AlliedVisionCamera::setupProperties() { VmbUint32_t featureCount = 0; VmbError_t err = m_sdk->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, sizeof(VmbFeatureInfo_t)); - if (err != VmbErrorSuccess || !featureCount) { + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error occurred when obtaining features count!"); return err; } @@ -136,6 +137,7 @@ VmbError_t AlliedVisionCamera::setupProperties() { err = m_sdk->VmbFeaturesList_t(m_handle, features.get(), featureCount, &featureCount, sizeof(VmbFeatureInfo_t)); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error occurred when obtaining features!"); return err; } @@ -143,7 +145,8 @@ VmbError_t AlliedVisionCamera::setupProperties() { for (VmbFeatureInfo_t* feature = features.get(); feature != end; ++feature) { err = createPropertyFromFeature(feature); if (err != VmbErrorSuccess) { - LogMessageCode(err); + LOG_ERROR(err, + "Error while creating property" + std::string(feature->name)); continue; } } @@ -154,6 +157,7 @@ VmbError_t AlliedVisionCamera::setupProperties() { VmbError_t AlliedVisionCamera::resizeImageBuffer() { VmbError_t err = m_sdk->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while reading payload size"); return err; } @@ -168,6 +172,7 @@ VmbError_t AlliedVisionCamera::resizeImageBuffer() { VmbError_t AlliedVisionCamera::createPropertyFromFeature( const VmbFeatureInfo_t* feature) { if (feature == nullptr) { + LogMessage("Cannot create feature. It is NULL"); return VmbErrorInvalidValue; } @@ -177,6 +182,7 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( if (featureCategory.find(g_EventCategory) != std::string::npos || featureCategory.find(g_ChunkCategory) != std::string::npos || feature->featureDataType == VmbFeatureDataRaw) { + // Skip return err; } @@ -198,7 +204,7 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( camera->mapFeatureNameToPropertyName(name, propertyName); auto err = camera->UpdateProperty(propertyName.c_str()); if (err != VmbErrorSuccess) { - camera->LogMessage("Property: " + propertyName + " update failed"); + camera->LOG_ERROR(err, "Property: " + propertyName + " update failed"); } }; @@ -206,6 +212,8 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( err = m_sdk->VmbFeatureInvalidationRegister_t(m_handle, feature->name, vmbCallback, this); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while registering invalidation callback for " + + std::string(feature->name)); return err; } @@ -248,6 +256,11 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( break; } + if (err != VmbErrorSuccess) { + LOG_ERROR(err, + "Error while creating property " + std::string(feature->name)); + } + return err; } @@ -259,6 +272,7 @@ unsigned AlliedVisionCamera::GetImageWidth() const { std::string value{}; auto ret = getFeatureValue(g_Width, value); if (ret != VmbErrorSuccess) { + LOG_ERROR(ret, "Error while getting image width!"); return 0; } @@ -269,6 +283,7 @@ unsigned AlliedVisionCamera::GetImageHeight() const { std::string value{}; auto ret = getFeatureValue(g_Height, value); if (ret != VmbErrorSuccess) { + LOG_ERROR(ret, "Error while getting image height!"); return 0; } @@ -301,6 +316,7 @@ double AlliedVisionCamera::GetExposure() const { std::string value{}; auto ret = getFeatureValue(g_ExposureFeature, value); if (ret != VmbErrorSuccess) { + LOG_ERROR(ret, "Error while getting exposure!"); return 0; } @@ -332,25 +348,29 @@ int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, }; if (xSize > width) { - err = setOffsetXProperty(x) || setWidthProperty(xSize); + err = setOffsetXProperty(x) | setWidthProperty(xSize); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while ROI X!"); return err; } } else { - err = setWidthProperty(xSize) || setOffsetXProperty(x); + err = setWidthProperty(xSize) | setOffsetXProperty(x); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while ROI X!"); return err; } } if (ySize > height) { - err = setOffsetYProperty(y) || setHeightProperty(ySize); + err = setOffsetYProperty(y) | setHeightProperty(ySize); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while ROI Y!"); return err; } } else { - err = setHeightProperty(ySize) || setOffsetYProperty(y); + err = setHeightProperty(ySize) | setOffsetYProperty(y); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while ROI Y!"); return err; } } @@ -368,6 +388,7 @@ int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, std::string value{}; err = getFeatureValue(field.first, value); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while getting ROI!"); break; } field.second = atoi(value.data()); @@ -378,9 +399,10 @@ int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, int AlliedVisionCamera::ClearROI() { std::string maxWidth, maxHeight; - VmbError_t err = getFeatureValue(g_WidthMax, maxWidth) || + VmbError_t err = getFeatureValue(g_WidthMax, maxWidth) | getFeatureValue(g_HeightMax, maxHeight); if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while clearing ROI!"); return err; } @@ -394,6 +416,7 @@ int AlliedVisionCamera::ClearROI() { for (auto& field : fields) { err = setFeatureValue(field.first, field.second); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while clearing ROI!"); break; } } @@ -433,18 +456,25 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, for (const auto& featureName : featureNames) { // Get Feature Info and Access Mode VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}, readOnly{}; + bool rMode{}, wMode{}, readOnly{}, featureAvailable{}; err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), - &featureInfo, sizeof(featureInfo)) || + &featureInfo, sizeof(featureInfo)) | m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, &wMode); if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting info or access query!"); return err; } readOnly = (rMode && !wMode); - //TODO - //Set somehow property to be unavailable when there is no r and w modes + featureAvailable = rMode || wMode; + if (!featureAvailable) { + LOG_ERROR(VmbErrorFeaturesUnavailable, + "Feature is currently not available! Feature: " + featureName); + return err; + } + // TODO + // Set somehow property to be unavailable when there is no r and w modes // Get values std::string propertyValue{}, featureValue{}; @@ -457,6 +487,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, err = getFeatureValue(&featureInfo, featureName.c_str(), featureValue); if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting feature value " + featureName); return err; } @@ -467,6 +498,9 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, this, propertyName.c_str(), featureValue.c_str()); if (VmbErrorSuccess != err) { + LOG_ERROR(err, + "Error while calling OnPropertyChanged callback for " + + featureName); return err; } } @@ -488,14 +522,17 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Update limits first to have latest min and max err = setAllowedValues(&featureInfo, propertyName.c_str()); if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while setting allowed values for feature " + + featureName); return err; } // Adjust value double min{}, max{}; - err = GetPropertyLowerLimit(propertyName.c_str(), min) || + err = GetPropertyLowerLimit(propertyName.c_str(), min) | GetPropertyUpperLimit(propertyName.c_str(), max); if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting limits for " + propertyName); return err; } std::string adjustedValue = @@ -511,6 +548,10 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, } } + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while updating property " + propertyName); + } + return err; } @@ -580,6 +621,12 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, // nothing break; } + + if (VmbErrorSuccess != err) { + LOG_ERROR(err, + "Error while getting feature value " + std::string(featureName)); + } + return err; } @@ -589,6 +636,8 @@ VmbError_t AlliedVisionCamera::getFeatureValue(const char* featureName, VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( m_handle, featureName, &featureInfo, sizeof(featureInfo)); if (VmbErrorSuccess != err) { + LOG_ERROR(err, + "Error while getting feature value " + std::string(featureName)); return err; } @@ -630,7 +679,6 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, err = m_sdk->VmbFeatureStringMaxlengthQuery_t(m_handle, featureName, &maxLen); if (err != VmbErrorSuccess) { - LogMessageCode(err); break; } if (value.size() > maxLen) { @@ -653,7 +701,6 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, err = m_sdk->VmbFeatureCommandIsDone_t(m_handle, featureName, &isDone); if (err != VmbErrorSuccess) { - LogMessageCode(err); break; } } @@ -661,6 +708,9 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, err = SetProperty(property.c_str(), g_Command); GetCoreCallback()->OnPropertyChanged(this, property.c_str(), g_Command); + if (err != VmbErrorSuccess) { + break; + } } else { err = VmbErrorInvalidValue; } @@ -673,6 +723,12 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, // nothing break; } + + if (VmbErrorSuccess != err) { + LOG_ERROR(err, + "Error while setting feature value " + std::string(featureName)); + } + return err; } @@ -682,6 +738,8 @@ VmbError_t AlliedVisionCamera::setFeatureValue(const char* featureName, VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( m_handle, featureName, &featureInfo, sizeof(featureInfo)); if (VmbErrorSuccess != err) { + LOG_ERROR(err, + "Error while setting feature value " + std::string(featureName)); return err; } @@ -733,7 +791,8 @@ std::string AlliedVisionCamera::adjustValue(VmbFeatureInfo_t& featureInfo, break; } if (VmbErrorSuccess != err) { - LogMessage("Cannot get feature incremental step to adjust a value"); + LOG_ERROR(err, "Error while getting increment query for feature " + + std::string(featureInfo.name)); return std::to_string(propertyValue); } @@ -777,7 +836,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, err = m_sdk->VmbFeatureFloatRangeQuery_t(m_handle, feature->name, &min, &max); if (VmbErrorSuccess != err || min == max) { - return err; + break; } err = SetPropertyLimits(propertyName, min, max); @@ -790,7 +849,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, err = m_sdk->VmbFeatureEnumRangeQuery_t( m_handle, feature->name, values.data(), MM::MaxStrLength, &valuesNum); if (VmbErrorSuccess != err) { - return err; + break; } for (size_t i = 0; i < valuesNum; i++) { @@ -807,7 +866,7 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, err = m_sdk->VmbFeatureIntRangeQuery_t(m_handle, feature->name, &min, &max); if (VmbErrorSuccess != err || min == max) { - return err; + break; } err = SetPropertyLimits(propertyName, static_cast(min), @@ -822,6 +881,11 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, break; } + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while setting allowed values for feature " + + std::string(feature->name)); + } + return err; } @@ -836,15 +900,19 @@ int AlliedVisionCamera::SnapImage() { frame.bufferSize = m_bufferSize; VmbError_t err = - m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)) || - m_sdk->VmbCaptureStart_t(m_handle) || - m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr) || - m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart) || + m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)) | + m_sdk->VmbCaptureStart_t(m_handle) | + m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr) | + m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart) | m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); m_isAcquisitionRunning = true; (void)StopSequenceAcquisition(); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while snapping image!"); + } + return err; } @@ -859,8 +927,9 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, return DEVICE_CAMERA_BUSY_ACQUIRING; } - int err = GetCoreCallback()->PrepareForAcq(this) || resizeImageBuffer(); + int err = GetCoreCallback()->PrepareForAcq(this) | resizeImageBuffer(); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while preparing for acquisition!"); return err; } @@ -882,18 +951,21 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, err = m_sdk->VmbFrameAnnounce_t(m_handle, &(m_frames[i]), - sizeof(VmbFrame_t)) || + sizeof(VmbFrame_t)) | m_sdk->VmbCaptureFrameQueue_t(m_handle, &(m_frames[i]), frameCallback); if (err != VmbErrorSuccess) { + LOG_ERROR(err, + "Error during frame praparation for continous acquisition!"); return err; } } - err = m_sdk->VmbCaptureStart_t(m_handle) || + err = m_sdk->VmbCaptureStart_t(m_handle) | m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); m_isAcquisitionRunning = true; if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error during start acquisition!"); return err; } @@ -909,14 +981,16 @@ int AlliedVisionCamera::StopSequenceAcquisition() { auto err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStop); m_isAcquisitionRunning = false; if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error during stopping acquisition command!"); return err; } } - auto err = m_sdk->VmbCaptureEnd_t(m_handle) || - m_sdk->VmbCaptureQueueFlush_t(m_handle) || + auto err = m_sdk->VmbCaptureEnd_t(m_handle) | + m_sdk->VmbCaptureQueueFlush_t(m_handle) | m_sdk->VmbFrameRevokeAll_t(m_handle); if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error in acquisition stop!"); return err; } diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index bea9b8e2e..5668286d9 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -16,13 +16,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ -#ifndef AlliedVisionCamera_H -#define AlliedVisionCamera_H +#ifndef ALLIEDVISIONCAMERA_H +#define ALLIEDVISIONCAMERA_H #include #include #include +#include "AlliedVisionDeviceBase.h" #include "DeviceBase.h" #include "Loader/LibLoader.h" @@ -56,7 +57,9 @@ static constexpr const char* g_AcqusitionStatus = "AcqusitionStatus"; /** * @brief Main Allied Vision Camera class */ -class AlliedVisionCamera : public CCameraBase { +class AlliedVisionCamera + : public AlliedVisionDeviceBase, + AlliedVisionCamera> { /////////////////////////////////////////////////////////////////////////////// // PUBLIC /////////////////////////////////////////////////////////////////////////////// diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj index 7174e830c..7106ac0ca 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj @@ -20,6 +20,7 @@ + @@ -32,6 +33,7 @@ + diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters index 15ee3a694..bdb569ec1 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters @@ -45,6 +45,9 @@ Header Files + + Header Files + @@ -56,5 +59,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.cpp new file mode 100644 index 000000000..64e692022 --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.cpp @@ -0,0 +1,3 @@ +#include "AlliedVisionDeviceBase.h" + + diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h new file mode 100644 index 000000000..fa7d6c30a --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h @@ -0,0 +1,97 @@ +/*============================================================================= + Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ +#ifndef ALLIEDVISIONDEVICEBASE_H +#define ALLIEDVISIONDEVICEBASE_H + +#include "DeviceBase.h" +#include "Loader/LibLoader.h" + +#define LOG_ERROR(err, message) logError(err, message, __FUNCTION__, __LINE__) + +/** + * @brief Base class for Allied Vision devices + */ +template +class AlliedVisionDeviceBase : public CDeviceBase { + /////////////////////////////////////////////////////////////////////////////// + // PUBLIC + /////////////////////////////////////////////////////////////////////////////// + public: + /** + * @brief Constructor + */ + AlliedVisionDeviceBase() { + CDeviceBase::InitializeDefaultErrorMessages(); + setApiErrorMessages(); + }; + + /** + * @brief Destructor + */ + virtual ~AlliedVisionDeviceBase() = default; + + void logError(int error, std::string message, std::string function = "", + int line = 0) const { + std::string prefix = "[" + function + "():" + std::to_string(line) + "] "; + CDeviceBase::LogMessage(prefix + message); + CDeviceBase::LogMessageCode(error); + } + + /////////////////////////////////////////////////////////////////////////////// + // PRIVATE + /////////////////////////////////////////////////////////////////////////////// + private: + /** + * @brief Setup error messages for Vimba API + */ + void setApiErrorMessages() { + CDeviceBase::SetErrorText(VmbErrorApiNotStarted, + "Vimba X API not started"); + CDeviceBase::SetErrorText(VmbErrorNotFound, "Device cannot be found"); + CDeviceBase::SetErrorText(VmbErrorDeviceNotOpen, + "Device cannot be opened"); + CDeviceBase::SetErrorText(VmbErrorBadParameter, + "Invalid parameter passed to the function"); + CDeviceBase::SetErrorText(VmbErrorNotImplemented, + "Feature not implemented"); + CDeviceBase::SetErrorText(VmbErrorNotSupported, + "Feature not supported"); + CDeviceBase::SetErrorText(VmbErrorUnknown, "Unknown error"); + CDeviceBase::SetErrorText( + VmbErrorInvalidValue, + "The value is not valid: either out of bounds or not an " + "increment of the minimum"); + CDeviceBase::SetErrorText(VmbErrorBadHandle, + "Given device handle is not valid"); + CDeviceBase::SetErrorText( + VmbErrorInvalidAccess, + "Operation is invalid with the current access mode"); + CDeviceBase::SetErrorText(VmbErrorTimeout, "Timeout occured"); + CDeviceBase::SetErrorText(VmbErrorNotAvailable, + "Something is not available"); + CDeviceBase::SetErrorText(VmbErrorNotInitialized, + "Something is not initialized"); + CDeviceBase::SetErrorText(VmbErrorAlready, + "The operation has been already done"); + CDeviceBase::SetErrorText(VmbErrorFeaturesUnavailable, + "Feature is currently unavailable"); + } +}; + +#endif diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp index 729962443..74b3bee5e 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp @@ -2,10 +2,7 @@ #include "AlliedVisionCamera.h" -AlliedVisionHub::AlliedVisionHub() : m_sdk(std::make_shared()) { - InitializeDefaultErrorMessages(); - setApiErrorMessages(); -} +AlliedVisionHub::AlliedVisionHub() : m_sdk(std::make_shared()) {} int AlliedVisionHub::DetectInstalledDevices() { LogMessage("Detecting installed cameras..."); @@ -28,6 +25,8 @@ int AlliedVisionHub::DetectInstalledDevices() { } delete[] camInfo; + } else { + LOG_ERROR(err, "Cannot get installed devices!"); } return err; @@ -38,7 +37,7 @@ int AlliedVisionHub::Initialize() { if (m_sdk->isInitialized()) { return DEVICE_OK; } else { - LogMessage("SDK not initialized!"); + LOG_ERROR(VmbErrorApiNotStarted, "SDK not initialized!"); return VmbErrorApiNotStarted; } } @@ -55,24 +54,3 @@ void AlliedVisionHub::GetName(char* name) const { bool AlliedVisionHub::Busy() { return false; } std::shared_ptr& AlliedVisionHub::getSDK() { return m_sdk; } - -void AlliedVisionHub::setApiErrorMessages() { - SetErrorText(VmbErrorApiNotStarted, "Vimba X API not started"); - SetErrorText(VmbErrorNotFound, "Device cannot be found"); - SetErrorText(VmbErrorDeviceNotOpen, "Device cannot be opened"); - SetErrorText(VmbErrorBadParameter, - "Invalid parameter passed to the function"); - SetErrorText(VmbErrorNotImplemented, "Feature not implemented"); - SetErrorText(VmbErrorNotSupported, "Feature not supported"); - SetErrorText(VmbErrorUnknown, "Unknown error"); - SetErrorText(VmbErrorInvalidValue, - "The value is not valid: either out of bounds or not an " - "increment of the minimum"); - SetErrorText(VmbErrorBadHandle, "Given device handle is not valid"); - SetErrorText(VmbErrorInvalidAccess, - "Operation is invalid with the current access mode"); - SetErrorText(VmbErrorTimeout, "Timeout occured"); - SetErrorText(VmbErrorNotAvailable, "Something is not available"); - SetErrorText(VmbErrorNotInitialized, "Something is not initialized"); - SetErrorText(VmbErrorAlready, "The operation has been already done"); -} diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h index 09c77aeba..dceb66dc5 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h @@ -16,12 +16,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ -#ifndef AlliedVisionHub_H -#define AlliedVisionHub_H +#ifndef ALLIEDVISIONHUB_H +#define ALLIEDVISIONHUB_H +#include "AlliedVisionDeviceBase.h" #include "DeviceBase.h" #include "SDK/Loader/LibLoader.h" - /////////////////////////////////////////////////////////////////////////////// // STATIC VARIABLES /////////////////////////////////////////////////////////////////////////////// @@ -30,7 +30,8 @@ static constexpr const char* g_hubName = "AlliedVisionHub"; /** * @brief Class that represents a HUB of supported devices */ -class AlliedVisionHub : public HubBase { +class AlliedVisionHub + : public AlliedVisionDeviceBase, AlliedVisionHub> { /////////////////////////////////////////////////////////////////////////////// // PUBLIC /////////////////////////////////////////////////////////////////////////////// @@ -51,11 +52,6 @@ class AlliedVisionHub : public HubBase { */ std::shared_ptr& getSDK(); - /** - * @brief Setup error messages for Vimba API - */ - void setApiErrorMessages(); - /////////////////////////////////////////////////////////////////////////////// // uMANAGER API METHODS /////////////////////////////////////////////////////////////////////////////// From f126db07dccd009eab50c82dc6490c039ff52be4 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Mon, 24 Jul 2023 10:15:48 +0200 Subject: [PATCH 14/43] Property read-only handling and fixes Changes: - Changes to the handling of read-only property - Fixes for errors for snap/live mode in release mode - Added additional error checks Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 203 +++++++++++------- 1 file changed, 124 insertions(+), 79 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 67e0b8a6c..6b7071a5e 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -114,7 +114,6 @@ int AlliedVisionCamera::Shutdown() { LogMessage("Shutting down camera: " + m_cameraName); VmbError_t err = VmbErrorSuccess; if (m_sdk != nullptr && m_sdk->isInitialized()) { - (void)StopSequenceAcquisition(); if (m_handle != nullptr) { err = m_sdk->VmbCameraClose_t(m_handle); } @@ -219,19 +218,19 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( switch (feature->featureDataType) { case VmbFeatureDataInt: { - err = CreateIntegerProperty(propertyName.c_str(), 0, true, + err = CreateIntegerProperty(propertyName.c_str(), 0, false, uManagerCallback); break; } case VmbFeatureDataBool: { - err = CreateStringProperty(propertyName.c_str(), g_False, true, + err = CreateStringProperty(propertyName.c_str(), g_False, false, uManagerCallback); AddAllowedValue(propertyName.c_str(), g_False); AddAllowedValue(propertyName.c_str(), g_True); break; } case VmbFeatureDataCommand: { - err = CreateStringProperty(propertyName.c_str(), g_Command, true, + err = CreateStringProperty(propertyName.c_str(), g_Command, false, uManagerCallback); AddAllowedValue(propertyName.c_str(), g_Command); AddAllowedValue(propertyName.c_str(), g_Execute); @@ -239,12 +238,12 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( } case VmbFeatureDataEnum: case VmbFeatureDataString: { - err = CreateStringProperty(propertyName.c_str(), "", true, + err = CreateStringProperty(propertyName.c_str(), "", false, uManagerCallback); break; } case VmbFeatureDataFloat: { - err = CreateFloatProperty(propertyName.c_str(), 0.0, true, + err = CreateFloatProperty(propertyName.c_str(), 0.0, false, uManagerCallback); break; } @@ -335,44 +334,48 @@ int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, VmbError_t err = VmbErrorSuccess; std::function setOffsetXProperty = [this](long x) { - return SetProperty(g_OffsetX, CDeviceUtils::ConvertToString(x)); + auto err = SetProperty(g_OffsetX, CDeviceUtils::ConvertToString(x)); + if (err) { + LOG_ERROR(err, "Error while ROI Offset X!"); + } + return err; }; std::function setOffsetYProperty = [this](long y) { - return SetProperty(g_OffsetY, CDeviceUtils::ConvertToString(y)); + auto err = SetProperty(g_OffsetY, CDeviceUtils::ConvertToString(y)); + if (err) { + LOG_ERROR(err, "Error while ROI Offset Y!"); + } + return err; }; std::function setWidthProperty = [this](long xSize) { - return SetProperty(g_Width, CDeviceUtils::ConvertToString(xSize)); + auto err = SetProperty(g_Width, CDeviceUtils::ConvertToString(xSize)); + if (err) { + LOG_ERROR(err, "Error while ROI X!"); + } + return err; }; std::function setHeightProperty = [this](long ySize) { - return SetProperty(g_Height, CDeviceUtils::ConvertToString(ySize)); + auto err = SetProperty(g_Height, CDeviceUtils::ConvertToString(ySize)); + if (err) { + LOG_ERROR(err, "Error while ROI Y!"); + } + return err; }; if (xSize > width) { - err = setOffsetXProperty(x) | setWidthProperty(xSize); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while ROI X!"); - return err; - } + err = setOffsetXProperty(x) || setWidthProperty(xSize); } else { - err = setWidthProperty(xSize) | setOffsetXProperty(x); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while ROI X!"); - return err; - } + err = setWidthProperty(xSize) || setOffsetXProperty(x); } if (ySize > height) { - err = setOffsetYProperty(y) | setHeightProperty(ySize); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while ROI Y!"); - return err; - } + err = setOffsetYProperty(y) || setHeightProperty(ySize); } else { - err = setHeightProperty(ySize) | setOffsetYProperty(y); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while ROI Y!"); - return err; - } + err = setHeightProperty(ySize) || setOffsetYProperty(y); + } + + if (err != VmbErrorSuccess) { + return err; } return resizeImageBuffer(); @@ -446,7 +449,6 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Init std::vector featureNames = {}; VmbError_t err = VmbErrorSuccess; - MM::Property* pChildProperty = (MM::Property*)pProp; const auto propertyName = pProp->GetName(); // Check property mapping @@ -456,7 +458,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, for (const auto& featureName : featureNames) { // Get Feature Info and Access Mode VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}, readOnly{}, featureAvailable{}; + bool rMode{}, wMode{}, featureAvailable{}; err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), &featureInfo, sizeof(featureInfo)) | m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, @@ -466,7 +468,6 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, return err; } - readOnly = (rMode && !wMode); featureAvailable = rMode || wMode; if (!featureAvailable) { LOG_ERROR(VmbErrorFeaturesUnavailable, @@ -506,40 +507,32 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, } } - // Update property's access mode - pChildProperty->SetReadOnly(readOnly); + err = setAllowedValues(&featureInfo, propertyName.c_str()); - // Update property's limits and allowed values - if (wMode) { - err = setAllowedValues(&featureInfo, propertyName.c_str()); - } break; case MM::ActionType::AfterSet: //!< Update feature from property - if (wMode) { - err = - setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); - if (err == VmbErrorInvalidValue) { - // Update limits first to have latest min and max - err = setAllowedValues(&featureInfo, propertyName.c_str()); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while setting allowed values for feature " + - featureName); - return err; - } + err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); + if (err == VmbErrorInvalidValue) { + // Update limits first to have latest min and max + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while setting allowed values for feature " + + featureName); + return err; + } - // Adjust value - double min{}, max{}; - err = GetPropertyLowerLimit(propertyName.c_str(), min) | - GetPropertyUpperLimit(propertyName.c_str(), max); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting limits for " + propertyName); - return err; - } - std::string adjustedValue = - adjustValue(featureInfo, min, max, std::stod(propertyValue)); - err = setFeatureValue(&featureInfo, featureName.c_str(), - adjustedValue); + // Adjust value + double min{}, max{}; + err = GetPropertyLowerLimit(propertyName.c_str(), min) | + GetPropertyUpperLimit(propertyName.c_str(), max); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting limits for " + propertyName); + return err; } + std::string adjustedValue = + adjustValue(featureInfo, min, max, std::stod(propertyValue)); + err = + setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); } break; default: @@ -899,14 +892,39 @@ int AlliedVisionCamera::SnapImage() { frame.buffer = m_buffer[0]; frame.bufferSize = m_bufferSize; - VmbError_t err = - m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)) | - m_sdk->VmbCaptureStart_t(m_handle) | - m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr) | - m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart) | - m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); - + VmbError_t err = VmbErrorSuccess; + err = m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + err = m_sdk->VmbCaptureStart_t(m_handle); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } m_isAcquisitionRunning = true; + err = m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + (void)StopSequenceAcquisition(); if (VmbErrorSuccess != err) { @@ -927,12 +945,18 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, return DEVICE_CAMERA_BUSY_ACQUIRING; } - int err = GetCoreCallback()->PrepareForAcq(this) | resizeImageBuffer(); + int err = GetCoreCallback()->PrepareForAcq(this); if (err != VmbErrorSuccess) { LOG_ERROR(err, "Error while preparing for acquisition!"); return err; } + err = resizeImageBuffer(); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error during frame praparation for continous acquisition!"); + return err; + } + for (size_t i = 0; i < MAX_FRAMES; i++) { // Setup frame with buffer m_frames[i].buffer = new uint8_t[m_bufferSize]; @@ -950,8 +974,14 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, }; err = - m_sdk->VmbFrameAnnounce_t(m_handle, &(m_frames[i]), - sizeof(VmbFrame_t)) | + m_sdk->VmbFrameAnnounce_t(m_handle, &(m_frames[i]), sizeof(VmbFrame_t)); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, + "Error during frame praparation for continous acquisition!"); + return err; + } + + err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &(m_frames[i]), frameCallback); if (err != VmbErrorSuccess) { LOG_ERROR(err, @@ -960,8 +990,12 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, } } - err = m_sdk->VmbCaptureStart_t(m_handle) | - m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); + err = m_sdk->VmbCaptureStart_t(m_handle); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error during frame praparation for continous acquisition!"); + return err; + } + err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); m_isAcquisitionRunning = true; if (err != VmbErrorSuccess) { @@ -977,8 +1011,9 @@ int AlliedVisionCamera::StartSequenceAcquisition(double interval_ms) { } int AlliedVisionCamera::StopSequenceAcquisition() { // This method shall never return any error + VmbError_t err = VmbErrorSuccess; if (IsCapturing()) { - auto err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStop); + err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStop); m_isAcquisitionRunning = false; if (err != VmbErrorSuccess) { LOG_ERROR(err, "Error during stopping acquisition command!"); @@ -986,11 +1021,21 @@ int AlliedVisionCamera::StopSequenceAcquisition() { } } - auto err = m_sdk->VmbCaptureEnd_t(m_handle) | - m_sdk->VmbCaptureQueueFlush_t(m_handle) | - m_sdk->VmbFrameRevokeAll_t(m_handle); + err = m_sdk->VmbCaptureEnd_t(m_handle); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error during stop acquisition!"); + return err; + } + + err = m_sdk->VmbCaptureQueueFlush_t(m_handle); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error during stop acquisition!"); + return err; + } + + err = m_sdk->VmbFrameRevokeAll_t(m_handle); if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error in acquisition stop!"); + LOG_ERROR(err, "Error during stop acquisition!"); return err; } From 6922c32b7f15775636e89a11e1ec22e6bbb75ad1 Mon Sep 17 00:00:00 2001 From: "Florian Klostermann [Allied Vision]" Date: Thu, 27 Jul 2023 14:15:34 +0200 Subject: [PATCH 15/43] Pull request #1: Feature/UNISDK-3114 create jenkins jobs for building micro manager avt device adapter Merge in HSW_SDK/mmcoreanddevices from feature/UNISDK-3114-create-jenkins-jobs-for-building-micro-manager-avt-device-adapter to allied-vision-camera-device-adapter Squashed commit of the following: commit 3ef56cc7e2efbdda688d732476055bfdd318a234 Author: Florian Klostermann Date: Thu Jul 27 14:09:14 2023 +0200 Jenkinsfile fix commit f74b0b65cf5fce2277b17433b612915c51d52eaa Author: Florian Klostermann Date: Thu Jul 27 14:01:23 2023 +0200 fixed Windows Jenkinsfile commit bf1304f3b1afb11a19f32bbdaffd5ec0d80e2a59 Author: Florian Klostermann Date: Thu Jul 27 11:58:32 2023 +0200 Added Windows Jenkinsfile --- .../jenkins/Windows/Jenkinsfile | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 DeviceAdapters/AlliedVisionCamera/jenkins/Windows/Jenkinsfile diff --git a/DeviceAdapters/AlliedVisionCamera/jenkins/Windows/Jenkinsfile b/DeviceAdapters/AlliedVisionCamera/jenkins/Windows/Jenkinsfile new file mode 100644 index 000000000..1e904b62e --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/jenkins/Windows/Jenkinsfile @@ -0,0 +1,59 @@ +properties([ + buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '14')), + [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false], + [$class: 'JobLocalConfiguration', changeReasonComment: ''] +]) + +pipeline { + + agent { label 'Host_Software_Windows_Build_Machine2' } + + stages { + + stage("Build") { + steps { + bat label: 'cmake build Release', script: '''CALL %VS2019_VCVARSALL_BAT% amd64 + msbuild micromanager.sln /p:Configuration=Release /p:Platform=x64 -t:AlliedVisionCamera''' + } + } + + stage("Deploy") { + steps { + script { + def buildDir = "build\\Release\\x64" + def deployDir = "MicroManager_AlliedVisionCamera" + + bat label: 'Create Deploy folder', script: """rd /s /q ${deployDir} + mkdir ${deployDir} + copy /Y /V ${buildDir}\\mmgr_dal_AlliedVisionCamera.dll ${deployDir}""" + + withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-user', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_USER_PW')]) { + bat label: 'Upload to Nexus', script:"""python -m nexus_handler upload --repository hsw_test --group-id avt.hsw.vimba.Win64 --artifact-id MicroManager_AlliedVisionCamera --auto-version --input ${deployDir} --type zip --user %NEXUS_USER% --password "%NEXUS_USER_PW%" """ + } + } + } + } + } + post { + always { + notifyBitbucket(projectKey: "${currentBuild.fullDisplayName}") + } + unstable { + emailext ( + subject: "UNSTABLE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", + body: """The build for the job ${env.JOB_NAME} > #${env.BUILD_NUMBER} failed: +Check console output at ${env.BUILD_URL}""", + recipientProviders: [[$class: 'DevelopersRecipientProvider']] + ) + } + failure { + emailext ( + subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", + body: """The Job ${env.JOB_NAME} resulted in an unexpected error during build ${env.BUILD_NUMBER}. + +Check console output at ${env.BUILD_URL}""", + recipientProviders: [[$class: 'DevelopersRecipientProvider']] + ) + } + } +} \ No newline at end of file From dafcc7da010596a5249dcb3fb2fa9fedbe64c1a2 Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Mon, 31 Jul 2023 10:36:01 +0200 Subject: [PATCH 16/43] Pixel Format support Changes: - Added helper class for pixel type converting - Added draft pixel type support Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 138 ++++++++++--- .../AlliedVisionCamera/AlliedVisionCamera.h | 194 +++++++++++++++++- .../AlliedVisionCamera.vcxproj | 2 +- .../AlliedVisionCamera/SDK/Loader/Constants.h | 12 +- .../SDK/Loader/LibLoader.cpp | 10 +- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 9 +- 6 files changed, 323 insertions(+), 42 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 6b7071a5e..abfeaa4a4 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -83,8 +83,12 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) m_frames{}, m_buffer{}, m_bufferSize{0}, - m_isAcquisitionRunning{false} { + m_payloadSize{0}, + m_isAcquisitionRunning{false}, + m_currentPixelFormat{} { CreateHubIDProperty(); + // Binning property is a Core Property, we will have a dummy one + CreateProperty(MM::g_Keyword_Binning, "1", MM::Integer, false, nullptr); } int AlliedVisionCamera::Initialize() { @@ -154,18 +158,21 @@ VmbError_t AlliedVisionCamera::setupProperties() { } VmbError_t AlliedVisionCamera::resizeImageBuffer() { - VmbError_t err = m_sdk->VmbPayloadSizeGet_t(m_handle, &m_bufferSize); + VmbError_t err = m_sdk->VmbPayloadSizeGet_t(m_handle, &m_payloadSize); if (err != VmbErrorSuccess) { LOG_ERROR(err, "Error while reading payload size"); return err; } + m_bufferSize = GetImageWidth() * GetImageHeight() * + m_currentPixelFormat.getBytesPerPixel(); + for (size_t i = 0; i < MAX_FRAMES; i++) { delete[] m_buffer[i]; m_buffer[i] = new VmbUint8_t[m_bufferSize]; } - return err; + return VmbErrorSuccess; } VmbError_t AlliedVisionCamera::createPropertyFromFeature( @@ -290,15 +297,17 @@ unsigned AlliedVisionCamera::GetImageHeight() const { } unsigned AlliedVisionCamera::GetImageBytesPerPixel() const { - // TODO implement - return 1; + return m_currentPixelFormat.getBytesPerPixel(); } long AlliedVisionCamera::GetImageBufferSize() const { return m_bufferSize; } unsigned AlliedVisionCamera::GetBitDepth() const { - // TODO implement - return 8; + return m_currentPixelFormat.getBitDepth(); +} + +unsigned AlliedVisionCamera::GetNumberOfComponents() const { + return m_currentPixelFormat.getNumberOfComponents(); } int AlliedVisionCamera::GetBinning() const { @@ -438,12 +447,6 @@ void AlliedVisionCamera::GetName(char* name) const { bool AlliedVisionCamera::IsCapturing() { return m_isAcquisitionRunning; } -int AlliedVisionCamera::OnPixelType(MM::PropertyBase* pProp, - MM::ActionType eAct) { - // TODO implement - return 0; -} - int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, MM::ActionType eAct) { // Init @@ -497,6 +500,9 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, pProp->Set(featureValue.c_str()); err = GetCoreCallback()->OnPropertyChanged( this, propertyName.c_str(), featureValue.c_str()); + if (propertyName == MM::g_Keyword_PixelType) { + handlePixelFormatChange(featureValue); + } if (VmbErrorSuccess != err) { LOG_ERROR(err, @@ -534,6 +540,10 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, err = setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); } + + if (propertyName == MM::g_Keyword_PixelType) { + handlePixelFormatChange(propertyValue); + } break; default: // nothing @@ -548,6 +558,11 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, return err; } +void AlliedVisionCamera::handlePixelFormatChange(const std::string& pixelType) { + m_currentPixelFormat.setPixelType(pixelType); + resizeImageBuffer(); +} + VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, const char* featureName, std::string& value) const { @@ -889,8 +904,15 @@ int AlliedVisionCamera::SnapImage() { resizeImageBuffer(); VmbFrame_t frame; - frame.buffer = m_buffer[0]; - frame.bufferSize = m_bufferSize; + std::shared_ptr buffer{nullptr}; + if (m_currentPixelFormat.getNumberOfComponents() > 1) { + buffer = std::shared_ptr(new VmbUint8_t[m_payloadSize]); + frame.buffer = buffer.get(); + frame.bufferSize = m_payloadSize; + } else { + frame.buffer = m_buffer[0]; + frame.bufferSize = m_bufferSize; + } VmbError_t err = VmbErrorSuccess; err = m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); @@ -925,6 +947,15 @@ int AlliedVisionCamera::SnapImage() { return err; } + if (m_currentPixelFormat.getNumberOfComponents() > 1) { + err = transformImage(&frame, 0); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while snapping image - cannot transform image!"); + (void)StopSequenceAcquisition(); + return err; + } + } + (void)StopSequenceAcquisition(); if (VmbErrorSuccess != err) { @@ -959,8 +990,13 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, for (size_t i = 0; i < MAX_FRAMES; i++) { // Setup frame with buffer - m_frames[i].buffer = new uint8_t[m_bufferSize]; - m_frames[i].bufferSize = m_bufferSize; + if (m_currentPixelFormat.getNumberOfComponents() > 1) { + m_frames[i].buffer = new VmbUint8_t[m_payloadSize]; + m_frames[i].bufferSize = m_payloadSize; + } else { + m_frames[i].buffer = m_buffer[i]; + m_frames[i].bufferSize = m_bufferSize; + } m_frames[i].context[0] = this; //(i); //buffer; + src.Size = sizeof(src); + + dest.Data = m_buffer[frameIndex]; + dest.Size = sizeof(dest); + + err = m_sdk->VmbSetImageInfoFromPixelFormat_t( + frame->pixelFormat, frame->width, frame->height, &src); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Cannot set image info from pixel format!"); + return err; + } + + err = m_sdk->VmbSetImageInfoFromPixelFormat_t( + m_currentPixelFormat.getVmbFormat(), frame->width, frame->height, &dest); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Cannot set image info from pixel format!"); + return err; + } + + err = m_sdk->VmbImageTransform_t(&src, &dest, &info, 0); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Cannot transform image!"); + return err; + } + + return err; +} + void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { if (frame != nullptr && frame->receiveStatus == VmbFrameStatusComplete) { - VmbUint8_t* buffer = reinterpret_cast(frame->imageData); + VmbUint8_t* buffer = nullptr; + size_t frameIndex = reinterpret_cast(frame->context[1]); + VmbError_t err = VmbErrorSuccess; + + if (m_currentPixelFormat.getNumberOfComponents() > 1) { + err = transformImage(frame, frameIndex); + buffer = m_buffer[frameIndex]; + if (err != VmbErrorSuccess) { + // Error logged in transformImage + return; + } + } else { + // For GRAY_SCALE copy as it is without any transform + buffer = reinterpret_cast(frame->buffer); + } // TODO implement metadata Metadata md; md.put("Camera", m_cameraName); - // TODO implement parameters - auto err = GetCoreCallback()->InsertImage(this, buffer, GetImageWidth(), - GetImageHeight(), 1, 1, - md.Serialize().c_str()); + err = GetCoreCallback()->InsertImage( + this, buffer, GetImageWidth(), GetImageHeight(), + m_currentPixelFormat.getBytesPerPixel(), + m_currentPixelFormat.getNumberOfComponents(), md.Serialize().c_str()); if (err == DEVICE_BUFFER_OVERFLOW) { GetCoreCallback()->ClearImageBuffer(this); - // TODO implement parameters - err = GetCoreCallback()->InsertImage(this, buffer, frame->width, - frame->height, 1, 1, - md.Serialize().c_str(), false); + err = GetCoreCallback()->InsertImage( + this, buffer, GetImageWidth(), GetImageHeight(), + m_currentPixelFormat.getBytesPerPixel(), + m_currentPixelFormat.getNumberOfComponents(), md.Serialize().c_str(), + false); } if (IsCapturing()) { diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 5668286d9..f1ff962b0 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -21,6 +21,7 @@ #include #include +#include #include #include "AlliedVisionDeviceBase.h" @@ -54,6 +55,172 @@ static constexpr const char* g_AcquisitionStart = "AcquisitionStart"; static constexpr const char* g_AcquisitionStop = "AcquisitionStop"; static constexpr const char* g_AcqusitionStatus = "AcqusitionStatus"; +/** + * @brief Pixel Format class that contains VMB Pixel Format info and contains + * helper methods to convert these information to the one that uManager + * supports. + * + * [IMPORTANT] uManager supports formats: + * 8bit GRAY [no. component = 1] + * 16bit GRAY [no. component = 1] + * 32bit RGB [no. component = 4] + */ +class PixelFormatConverter { + /////////////////////////////////////////////////////////////////////////////// + // PUBLIC + /////////////////////////////////////////////////////////////////////////////// + public: + /** + * @brief Constructor + */ + PixelFormatConverter() + : m_pixelType{"Mono8"}, + m_components{1}, + m_bitDepth{8}, + m_bytesPerPixel{1}, + m_isMono{true}, + m_vmbFormat{VmbPixelFormatMono8} {} + + /** + * @brief Destructor + */ + virtual ~PixelFormatConverter() = default; + + /** + * @brief Setter for pixel type + * @param[in] type New pixel type (string value from VMB) + */ + void setPixelType(const std::string& type) { + m_pixelType = type; + updateFields(); + } + + /** + * @brief Getter to check if given pixel type is Mono or Color + * @return True if Mono, otherwise false + */ + bool isMono() const { return m_isMono; } + + /** + * @brief Getter for number of components for given pixel type + * uManager supports only 1 or 4 components + * @return Number of components + */ + unsigned getNumberOfComponents() const { return m_components; } + + /** + * @brief Getter for bit depth for given pixel type + * @return Number of bits for one pixel + */ + unsigned getBitDepth() const { return m_bitDepth; } + + /** + * @brief Getter for bytes per pixel + * @return Bytes per pixel + */ + unsigned getBytesPerPixel() const { return m_bytesPerPixel; } + + /** + * @brief Getter of destination VmbPixelFormat that fits into the one, that + * uManager supports. In general uManager supports three pixelFormats: + * 1. Mono8 + * 2. Mono16 + * 3. RGB32 + * These types fits into following VmbPixelTypes: + * 1. VmbPixelFormatMono8 + * 2. VmbPixelFormatMono16 + * 3. VmbPixelFormatBgra8 + * @return Destination VmbPixelFormat + */ + VmbPixelFormatType getVmbFormat() const { return m_vmbFormat; } + + /////////////////////////////////////////////////////////////////////////////// + // PRIVATE + /////////////////////////////////////////////////////////////////////////////// + private: + /** + * @brief Helper method to update info if given format is Mono or Color + */ + void updateMono() { + std::regex re("Mono(\\d+)"); + std::smatch m; + m_isMono = std::regex_search(m_pixelType, m, re); + } + + /** + * @brief Helper method to update number of components for given pixel type + * uManager supports only 1 or 4 components + */ + void updateNumberOfComponents() { m_components = m_isMono ? 1 : 4; } + + /** + * @brief Helper method to update bit depth for given pixel type + */ + void updateBitDepth() { + m_bitDepth = 8; + if (isMono()) { + std::regex re("Mono(\\d+)"); + std::smatch m; + std::regex_search(m_pixelType, m, re); + if (m.size() > 0) { + if (std::atoi(m[1].str().c_str()) == 8) { // TODO check this condition + m_bitDepth = 8; + } else { + m_bitDepth = 16; + } + } else { + // ERROR + } + } else { + m_bitDepth = 32; + } + } + + /** + * @brief Helper method to update bytes per pixel + */ + void updateBytesPerPixel() { m_bytesPerPixel = m_bitDepth / 8; } + + /** + * @brief Helper method to update destination VmbPixelFormatType + */ + void updateVmbFormat() { + switch (m_bytesPerPixel) { + case 1: + m_vmbFormat = VmbPixelFormatMono8; + break; + case 2: + m_vmbFormat = VmbPixelFormatMono16; + break; + case 4: + m_vmbFormat = + VmbPixelFormatBgra8; // TODO check if this is a valid format + break; + default: + break; + } + } + + /** + * @brief Helper method to update all required fields + */ + void updateFields() { + // [IMPORTANT] Keep order of the calls + updateMono(); + updateNumberOfComponents(); + updateBitDepth(); + updateBytesPerPixel(); + updateVmbFormat(); + } + + std::string m_pixelType; //!< Pixel type (in string) - value from VMB + unsigned m_components; //!< Number of components + unsigned m_bitDepth; // m_sdk; // m_frames; // m_buffer; // m_sdk; // m_frames; // + m_buffer; // m_featureToProperty; //!< Map of features name into uManager properties static const std::unordered_multimap diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj index 7106ac0ca..6b1087e6d 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj @@ -110,7 +110,7 @@ true - C:\Program Files\Micro-Manager-2.0 + C:\Program Files\Micro-Manager-2.0\ false diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h index 929d01061..fa73ac5b4 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h @@ -19,9 +19,15 @@ #ifndef CONSTANTS_H #define CONSTANTS_H -static constexpr const char* VIMBA_X_ENV_VAR = "VIMBA_X_HOME"; // #include "VmbC/VmbC.h" +#include "VmbImageTransform/VmbTransform.h" /** * @brief Wrapper for single Windows process @@ -171,12 +172,16 @@ class VimbaXApi { decltype(VmbFeatureFloatIncrementQuery)* VmbFeatureFloatIncrementQuery_t = nullptr; decltype(VmbFeatureCommandIsDone)* VmbFeatureCommandIsDone_t = nullptr; + decltype(VmbSetImageInfoFromPixelFormat)* + VmbSetImageInfoFromPixelFormat_t = nullptr; + decltype(VmbImageTransform)* VmbImageTransform_t = nullptr; /////////////////////////////////////////////////////////////////////////////// // PRIVATE /////////////////////////////////////////////////////////////////////////////// private: - bool m_initialized; // Date: Mon, 31 Jul 2023 17:19:52 +0200 Subject: [PATCH 17/43] Pixel format support Changes: - Fixed some memory leaks - Refactored usage of buffer and its clearing - Refactored image transformation - Refactored buffer preparation and resizing Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 79 +++++++------------ .../AlliedVisionCamera/AlliedVisionCamera.h | 19 +++-- 2 files changed, 41 insertions(+), 57 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index abfeaa4a4..028bf0c2f 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -107,10 +107,8 @@ int AlliedVisionCamera::Initialize() { return err; } - // Init properties and buffer - // TODO handle error - setupProperties(); - + // Ignore errors from setting up properties + (void)setupProperties(); return resizeImageBuffer(); } @@ -164,8 +162,9 @@ VmbError_t AlliedVisionCamera::resizeImageBuffer() { return err; } - m_bufferSize = GetImageWidth() * GetImageHeight() * - m_currentPixelFormat.getBytesPerPixel(); + m_bufferSize = std::max(GetImageWidth() * GetImageHeight() * + m_currentPixelFormat.getBytesPerPixel(), + m_payloadSize); for (size_t i = 0; i < MAX_FRAMES; i++) { delete[] m_buffer[i]; @@ -560,7 +559,6 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, void AlliedVisionCamera::handlePixelFormatChange(const std::string& pixelType) { m_currentPixelFormat.setPixelType(pixelType); - resizeImageBuffer(); } VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, @@ -904,15 +902,8 @@ int AlliedVisionCamera::SnapImage() { resizeImageBuffer(); VmbFrame_t frame; - std::shared_ptr buffer{nullptr}; - if (m_currentPixelFormat.getNumberOfComponents() > 1) { - buffer = std::shared_ptr(new VmbUint8_t[m_payloadSize]); - frame.buffer = buffer.get(); - frame.bufferSize = m_payloadSize; - } else { - frame.buffer = m_buffer[0]; - frame.bufferSize = m_bufferSize; - } + frame.buffer = m_buffer[0]; + frame.bufferSize = m_payloadSize; VmbError_t err = VmbErrorSuccess; err = m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); @@ -947,21 +938,14 @@ int AlliedVisionCamera::SnapImage() { return err; } - if (m_currentPixelFormat.getNumberOfComponents() > 1) { - err = transformImage(&frame, 0); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while snapping image - cannot transform image!"); - (void)StopSequenceAcquisition(); - return err; - } + err = transformImage(&frame); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while snapping image - cannot transform image!"); + (void)StopSequenceAcquisition(); + return err; } (void)StopSequenceAcquisition(); - - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while snapping image!"); - } - return err; } @@ -989,14 +973,8 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, } for (size_t i = 0; i < MAX_FRAMES; i++) { - // Setup frame with buffer - if (m_currentPixelFormat.getNumberOfComponents() > 1) { - m_frames[i].buffer = new VmbUint8_t[m_payloadSize]; - m_frames[i].bufferSize = m_payloadSize; - } else { - m_frames[i].buffer = m_buffer[i]; - m_frames[i].bufferSize = m_bufferSize; - } + m_frames[i].buffer = m_buffer[i]; + m_frames[i].bufferSize = m_payloadSize; m_frames[i].context[0] = this; //(i); //VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); m_isAcquisitionRunning = true; @@ -1078,16 +1057,18 @@ int AlliedVisionCamera::StopSequenceAcquisition() { return UpdateStatus(); } -VmbError_t AlliedVisionCamera::transformImage(VmbFrame_t* frame, - size_t frameIndex) { +VmbError_t AlliedVisionCamera::transformImage(VmbFrame_t* frame) { VmbError_t err = VmbErrorSuccess; VmbImage src{}, dest{}; VmbTransformInfo info{}; + std::shared_ptr tempBuff = + std::shared_ptr(new VmbUint8_t[m_bufferSize]); + auto srcBuff = reinterpret_cast(frame->buffer); - src.Data = frame->buffer; + src.Data = srcBuff; src.Size = sizeof(src); - dest.Data = m_buffer[frameIndex]; + dest.Data = tempBuff.get(); dest.Size = sizeof(dest); err = m_sdk->VmbSetImageInfoFromPixelFormat_t( @@ -1110,31 +1091,25 @@ VmbError_t AlliedVisionCamera::transformImage(VmbFrame_t* frame, return err; } + memcpy(srcBuff, tempBuff.get(), m_bufferSize); return err; } void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { if (frame != nullptr && frame->receiveStatus == VmbFrameStatusComplete) { - VmbUint8_t* buffer = nullptr; - size_t frameIndex = reinterpret_cast(frame->context[1]); VmbError_t err = VmbErrorSuccess; - if (m_currentPixelFormat.getNumberOfComponents() > 1) { - err = transformImage(frame, frameIndex); - buffer = m_buffer[frameIndex]; - if (err != VmbErrorSuccess) { - // Error logged in transformImage - return; - } - } else { - // For GRAY_SCALE copy as it is without any transform - buffer = reinterpret_cast(frame->buffer); + err = transformImage(frame); + if (err != VmbErrorSuccess) { + // Error logged in transformImage + return; } // TODO implement metadata Metadata md; md.put("Camera", m_cameraName); + VmbUint8_t* buffer = reinterpret_cast(frame->buffer); err = GetCoreCallback()->InsertImage( this, buffer, GetImageWidth(), GetImageHeight(), m_currentPixelFormat.getBytesPerPixel(), diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index f1ff962b0..d8eb56439 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -163,10 +163,12 @@ class PixelFormatConverter { std::smatch m; std::regex_search(m_pixelType, m, re); if (m.size() > 0) { - if (std::atoi(m[1].str().c_str()) == 8) { // TODO check this condition - m_bitDepth = 8; - } else { + if (std::atoi(m[1].str().c_str()) == 16) { + // We do transformation to Mono16 only for Mono16, otherwise + // it will always be Mono8 m_bitDepth = 16; + } else { + m_bitDepth = 8; } } else { // ERROR @@ -287,7 +289,7 @@ class AlliedVisionCamera /** * @brief Helper method to handle change of pixel type * @param[in] pixelType New pixel type (as string) - */ + */ void handlePixelFormatChange(const std::string& pixelType); /** @@ -403,7 +405,14 @@ class AlliedVisionCamera std::string adjustValue(VmbFeatureInfo_t& featureInfo, double min, double max, double propertyValue) const; - VmbError_t transformImage(VmbFrame_t* frame, size_t frameIndex); + /** + * @brief Internal method to transform image to the destination format that + * uManager supports (see \ref PixelFormatConverter) and replaces input frame + * with output (transformed) frame + * @param[in] frame Frame with image to transform from and into + * @return Error in case of failure + */ + VmbError_t transformImage(VmbFrame_t* frame); /////////////////////////////////////////////////////////////////////////////// // MEMBERS From f3d288b88c72d7a6fac3170ac554e3e0098465ae Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Mon, 7 Aug 2023 15:11:58 +0200 Subject: [PATCH 18/43] Linux support changes Changes: - Base for Linux support Author(s): - Maciej Scecelek --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 2 -- .../AlliedVisionDeviceBase.h | 2 +- .../SDK/Loader/LibLoader.cpp | 10 +++---- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 26 +++++++++---------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 028bf0c2f..05e827c84 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -20,8 +20,6 @@ #include "AlliedVisionCamera.h" -#include - #include #include #include diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h index fa7d6c30a..deb6c17bf 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h @@ -20,7 +20,7 @@ #define ALLIEDVISIONDEVICEBASE_H #include "DeviceBase.h" -#include "Loader/LibLoader.h" +#include "SDK/Loader/LibLoader.h" #define LOG_ERROR(err, message) logError(err, message, __FUNCTION__, __LINE__) diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp index 9e85a5f2a..f600b4638 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp @@ -121,7 +121,7 @@ LibLoader::LibLoader(const char* lib, const char* libPath) LibLoader::~LibLoader() { if (m_loaded) { - FreeModule(m_module); + FreeModule(static_cast(m_module)); m_module = nullptr; m_loaded = false; m_libName = nullptr; @@ -130,12 +130,12 @@ LibLoader::~LibLoader() { bool LibLoader::isLoaded() const { return m_loaded; } -ProcWrapper LibLoader::resolveFunction(const char* functionName, +SymbolWrapper LibLoader::resolveFunction(const char* functionName, bool& allResolved) const { - FARPROC funPtr = nullptr; + void* funPtr = nullptr; if (allResolved) { - funPtr = GetProcAddress((HMODULE)m_module, functionName); + funPtr = GetProcAddress(static_cast(m_module), functionName); allResolved = allResolved && (funPtr != nullptr); } - return ProcWrapper(funPtr); + return SymbolWrapper(funPtr); } \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h index 583f6b56e..b9221a025 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h @@ -29,16 +29,16 @@ /** * @brief Wrapper for single Windows process */ -class ProcWrapper { +class SymbolWrapper { /////////////////////////////////////////////////////////////////////////////// // PUBLIC /////////////////////////////////////////////////////////////////////////////// public: /** * @brief Constructor of wrapper - * @param[in] funPtr Pointer to the process + * @param[in] funPtr Pointer to the resolved symbol */ - explicit ProcWrapper(FARPROC funPtr) : m_funPtr(funPtr) {} + explicit SymbolWrapper(void* funPtr) : m_funPtr(funPtr) {} /** * @brief Operator () overload to call function @@ -51,7 +51,7 @@ class ProcWrapper { // PRIVATE /////////////////////////////////////////////////////////////////////////////// private: - FARPROC m_funPtr; // Date: Mon, 7 Aug 2023 15:11:58 +0200 Subject: [PATCH 19/43] Linux support changes Changes: - Base for Linux support Author(s): - Maciej Scecelek --- DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h | 4 +++- DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp | 6 ++++-- DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h | 2 -- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h index fa73ac5b4..95f723607 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h @@ -21,8 +21,10 @@ static constexpr const char* VIMBA_X_ENV_VAR = "VIMBA_X_HOME"; // + #include "Constants.h" VimbaXApi::VimbaXApi() @@ -131,11 +133,11 @@ LibLoader::~LibLoader() { bool LibLoader::isLoaded() const { return m_loaded; } SymbolWrapper LibLoader::resolveFunction(const char* functionName, - bool& allResolved) const { + bool& allResolved) const { void* funPtr = nullptr; if (allResolved) { funPtr = GetProcAddress(static_cast(m_module), functionName); allResolved = allResolved && (funPtr != nullptr); } return SymbolWrapper(funPtr); -} \ No newline at end of file +} diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h index b9221a025..7307eedeb 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h @@ -19,8 +19,6 @@ #ifndef LIBLOADER_H #define LIBLOADER_H -#include - #include #include "VmbC/VmbC.h" From e9637bf233dccc9cf8a860e81f2a3f5426b9bc2e Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Mon, 7 Aug 2023 15:09:00 +0200 Subject: [PATCH 20/43] Linux support Changes: - Added changes required for linux build Authros(s): - Maciej Scecelek --- DeviceAdapters/AlliedVisionCamera/Makefile.am | 8 ++++++++ DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h | 7 +++++++ DeviceAdapters/Makefile.am | 1 + DeviceAdapters/configure.ac | 1 + 4 files changed, 17 insertions(+) create mode 100644 DeviceAdapters/AlliedVisionCamera/Makefile.am diff --git a/DeviceAdapters/AlliedVisionCamera/Makefile.am b/DeviceAdapters/AlliedVisionCamera/Makefile.am new file mode 100644 index 000000000..f2229117a --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/Makefile.am @@ -0,0 +1,8 @@ + +AM_CXXFLAGS = $(MMDEVAPI_CXXFLAGS) +deviceadapter_LTLIBRARIES = libmmgr_dal_AlliedVisionCamera.la +libmmgr_dal_AlliedVisionCamera_la_SOURCES = AlliedVisionHub.h AlliedVisionHub.cpp AlliedVisionDeviceBase.h AlliedVisionDeviceBase.cpp AlliedVisionCamera.h AlliedVisionCamera.cpp SDK/Loader/Constants.h SDK/Loader/LibLoader.h SDK/Loader/LibLoader.cpp SDK/VmbC/VmbC.h SDK/VmbC/VmbCommonTypes.h SDK/VmbC/VmbConstants.h SDK/Vmbc/VmbCTypeDefinitions.h SDK/VmbImageTransform/VmbTransform.h SDK/VmbImageTransform/VmbTransformTypes.h +libmmgr_dal_AlliedVisionCamera_la_LIBADD = $(MMDEVAPI_LIBADD) +libmmgr_dal_AlliedVisionCamera_la_LDFLAGS = $(MMDEVAPI_LDFLAGS) + +EXTRA_DIST = AlliedVisionCamera.vcproj AlliedVisionCamera.vcproj.filters AlliedVisionCamera.vcproj.user diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h index 7307eedeb..c8c2a74bd 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h @@ -19,6 +19,13 @@ #ifndef LIBLOADER_H #define LIBLOADER_H +#ifdef __linux__ + #include +#elif _WIN32 + #include +#else + +#endif #include #include "VmbC/VmbC.h" diff --git a/DeviceAdapters/Makefile.am b/DeviceAdapters/Makefile.am index 1fa43090c..225421f0f 100644 --- a/DeviceAdapters/Makefile.am +++ b/DeviceAdapters/Makefile.am @@ -91,6 +91,7 @@ SUBDIRS = \ $(USBMANAGER) \ $(V4L) \ AAAOTF \ + AlliedVisionCamera \ AOTF \ ASIFW1000 \ ASIStage \ diff --git a/DeviceAdapters/configure.ac b/DeviceAdapters/configure.ac index cac90eae8..49596a48f 100644 --- a/DeviceAdapters/configure.ac +++ b/DeviceAdapters/configure.ac @@ -463,6 +463,7 @@ m4_define([device_adapter_dirs], [m4_strip([ ASITiger ASIWPTR Aladdin + AlliedVisionCamera Andor AndorLaserCombiner AndorSDK3 From 1b86a418a54d6ef5157d8192027d885180868f7c Mon Sep 17 00:00:00 2001 From: Maciej Scecelek Date: Wed, 9 Aug 2023 09:40:40 +0200 Subject: [PATCH 21/43] Linux support Changes: - Linux support changes Author(s): - Maciej Scecelek --- .../AlliedVisionDeviceBase.h | 6 +-- .../AlliedVisionCamera/AlliedVisionHub.cpp | 8 +-- .../AlliedVisionCamera/AlliedVisionHub.h | 16 +++--- DeviceAdapters/AlliedVisionCamera/Makefile.am | 3 +- .../AlliedVisionCamera/SDK/Loader/Constants.h | 25 ++++++--- .../SDK/Loader/LibLoader.cpp | 54 ++++++++++++++++--- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 10 +--- 7 files changed, 84 insertions(+), 38 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h index deb6c17bf..825d65118 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h @@ -20,7 +20,7 @@ #define ALLIEDVISIONDEVICEBASE_H #include "DeviceBase.h" -#include "SDK/Loader/LibLoader.h" +#include "Loader/LibLoader.h" #define LOG_ERROR(err, message) logError(err, message, __FUNCTION__, __LINE__) @@ -32,7 +32,7 @@ class AlliedVisionDeviceBase : public CDeviceBase { /////////////////////////////////////////////////////////////////////////////// // PUBLIC /////////////////////////////////////////////////////////////////////////////// - public: +public: /** * @brief Constructor */ @@ -56,7 +56,7 @@ class AlliedVisionDeviceBase : public CDeviceBase { /////////////////////////////////////////////////////////////////////////////// // PRIVATE /////////////////////////////////////////////////////////////////////////////// - private: +private: /** * @brief Setup error messages for Vimba API */ diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp index 74b3bee5e..9d5a11173 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp @@ -10,7 +10,7 @@ int AlliedVisionHub::DetectInstalledDevices() { // Get the number of connected cameras first VmbError_t err = m_sdk->VmbCamerasList_t(nullptr, 0, &camNum, 0); if (VmbErrorSuccess == err) { - VmbCameraInfo_t* camInfo = new VmbCameraInfo_t[camNum]; + VmbCameraInfo_t *camInfo = new VmbCameraInfo_t[camNum]; // Get the cameras err = m_sdk->VmbCamerasList_t(camInfo, camNum, &camNum, sizeof *camInfo); @@ -18,7 +18,7 @@ int AlliedVisionHub::DetectInstalledDevices() { if (err == VmbErrorSuccess) { for (VmbUint32_t i = 0; i < camNum; ++i) { if (camInfo[i].permittedAccess & VmbAccessModeFull) { - MM::Device* pDev = new AlliedVisionCamera(camInfo[i].cameraIdString); + MM::Device *pDev = new AlliedVisionCamera(camInfo[i].cameraIdString); AddInstalledDevice(pDev); } } @@ -47,10 +47,10 @@ int AlliedVisionHub::Shutdown() { return DEVICE_OK; } -void AlliedVisionHub::GetName(char* name) const { +void AlliedVisionHub::GetName(char *name) const { CDeviceUtils::CopyLimitedString(name, g_hubName); } bool AlliedVisionHub::Busy() { return false; } -std::shared_ptr& AlliedVisionHub::getSDK() { return m_sdk; } +std::shared_ptr &AlliedVisionHub::getSDK() { return m_sdk; } diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h index dceb66dc5..00e50b55a 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h @@ -21,11 +21,13 @@ #include "AlliedVisionDeviceBase.h" #include "DeviceBase.h" -#include "SDK/Loader/LibLoader.h" +#include "Loader/LibLoader.h" + +#include /////////////////////////////////////////////////////////////////////////////// // STATIC VARIABLES /////////////////////////////////////////////////////////////////////////////// -static constexpr const char* g_hubName = "AlliedVisionHub"; +static constexpr const char *g_hubName = "AlliedVisionHub"; /** * @brief Class that represents a HUB of supported devices @@ -35,7 +37,7 @@ class AlliedVisionHub /////////////////////////////////////////////////////////////////////////////// // PUBLIC /////////////////////////////////////////////////////////////////////////////// - public: +public: /** * @brief Contructor of a HUB */ @@ -50,7 +52,7 @@ class AlliedVisionHub * @brief SDK getter * @return Pointer to SDK */ - std::shared_ptr& getSDK(); + std::shared_ptr &getSDK(); /////////////////////////////////////////////////////////////////////////////// // uMANAGER API METHODS @@ -58,14 +60,14 @@ class AlliedVisionHub int DetectInstalledDevices() override; int Initialize() override; int Shutdown() override; - void GetName(char* name) const override; + void GetName(char *name) const override; bool Busy() override; /////////////////////////////////////////////////////////////////////////////// // PRIVATE /////////////////////////////////////////////////////////////////////////////// - private: - std::shared_ptr m_sdk; // m_sdk; // +#elif _WIN32 #include +#else +// nothing +#endif #include "Constants.h" VimbaXApi::VimbaXApi() - : m_sdk(VIMBA_X_LIB_NAME, VIMBA_X_LIB_DIR.c_str()), - m_initialized(false), + : m_sdk(VIMBA_X_LIB_NAME, VIMBA_X_LIB_DIR.c_str()), m_initialized(false), m_imageTransform(VIMBA_X_IMAGE_TRANSFORM_NAME, VIMBA_X_LIB_DIR.c_str()) { if (m_sdk.isLoaded() && m_imageTransform.isLoaded()) { bool allResolved = true; @@ -112,7 +117,39 @@ VimbaXApi::~VimbaXApi() { } } -LibLoader::LibLoader(const char* lib, const char* libPath) +bool LibLoader::isLoaded() const { return m_loaded; } +#ifdef __linux__ +LibLoader::LibLoader(const char *lib, const char *libPath) + : m_libName(lib), m_libPath(libPath), m_module(nullptr), m_loaded(false) { + std::string path = std::string(m_libPath) + std::string(m_libName); + dlerror(); + m_module = dlopen(path.c_str(), RTLD_NOW); + if (m_module != nullptr) { + m_loaded = true; + } +} + +LibLoader::~LibLoader() { + if (m_loaded) { + dlclose(m_module); + m_module = nullptr; + m_loaded = false; + m_libName = nullptr; + } +} + +SymbolWrapper LibLoader::resolveFunction(const char *functionName, + bool &allResolved) const { + dlerror(); + void *funPtr = nullptr; + if (allResolved) { + funPtr = dlsym(m_module, functionName); + allResolved = allResolved && (funPtr != nullptr); + } + return SymbolWrapper(funPtr); +} +#elif _WIN32 +LibLoader::LibLoader(const char *lib, const char *libPath) : m_libName(lib), m_libPath(libPath), m_module(nullptr), m_loaded(false) { SetDllDirectoryA(m_libPath); m_module = LoadLibraryA(m_libName); @@ -130,14 +167,15 @@ LibLoader::~LibLoader() { } } -bool LibLoader::isLoaded() const { return m_loaded; } - -SymbolWrapper LibLoader::resolveFunction(const char* functionName, - bool& allResolved) const { - void* funPtr = nullptr; +SymbolWrapper LibLoader::resolveFunction(const char *functionName, + bool &allResolved) const { + void *funPtr = nullptr; if (allResolved) { funPtr = GetProcAddress(static_cast(m_module), functionName); allResolved = allResolved && (funPtr != nullptr); } return SymbolWrapper(funPtr); } +#else +// nothing +#endif diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h index c8c2a74bd..a877e0903 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h @@ -19,14 +19,8 @@ #ifndef LIBLOADER_H #define LIBLOADER_H -#ifdef __linux__ - #include -#elif _WIN32 - #include -#else - -#endif #include +#include #include "VmbC/VmbC.h" #include "VmbImageTransform/VmbTransform.h" @@ -48,7 +42,7 @@ class SymbolWrapper { /** * @brief Operator () overload to call function */ - template >> + template ::value>> operator T*() const { return reinterpret_cast(m_funPtr); } From ca4147422da1068644900536a0e289254fa12c2f Mon Sep 17 00:00:00 2001 From: Florian Klostermann Date: Fri, 18 Aug 2023 16:55:26 +0200 Subject: [PATCH 22/43] Deleted Jenkins folder since Jenkinsfile have been moved to the "micro-manager" repo --- .../jenkins/Windows/Jenkinsfile | 59 ------------------- 1 file changed, 59 deletions(-) delete mode 100644 DeviceAdapters/AlliedVisionCamera/jenkins/Windows/Jenkinsfile diff --git a/DeviceAdapters/AlliedVisionCamera/jenkins/Windows/Jenkinsfile b/DeviceAdapters/AlliedVisionCamera/jenkins/Windows/Jenkinsfile deleted file mode 100644 index 1e904b62e..000000000 --- a/DeviceAdapters/AlliedVisionCamera/jenkins/Windows/Jenkinsfile +++ /dev/null @@ -1,59 +0,0 @@ -properties([ - buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '14')), - [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false], - [$class: 'JobLocalConfiguration', changeReasonComment: ''] -]) - -pipeline { - - agent { label 'Host_Software_Windows_Build_Machine2' } - - stages { - - stage("Build") { - steps { - bat label: 'cmake build Release', script: '''CALL %VS2019_VCVARSALL_BAT% amd64 - msbuild micromanager.sln /p:Configuration=Release /p:Platform=x64 -t:AlliedVisionCamera''' - } - } - - stage("Deploy") { - steps { - script { - def buildDir = "build\\Release\\x64" - def deployDir = "MicroManager_AlliedVisionCamera" - - bat label: 'Create Deploy folder', script: """rd /s /q ${deployDir} - mkdir ${deployDir} - copy /Y /V ${buildDir}\\mmgr_dal_AlliedVisionCamera.dll ${deployDir}""" - - withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-user', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_USER_PW')]) { - bat label: 'Upload to Nexus', script:"""python -m nexus_handler upload --repository hsw_test --group-id avt.hsw.vimba.Win64 --artifact-id MicroManager_AlliedVisionCamera --auto-version --input ${deployDir} --type zip --user %NEXUS_USER% --password "%NEXUS_USER_PW%" """ - } - } - } - } - } - post { - always { - notifyBitbucket(projectKey: "${currentBuild.fullDisplayName}") - } - unstable { - emailext ( - subject: "UNSTABLE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", - body: """The build for the job ${env.JOB_NAME} > #${env.BUILD_NUMBER} failed: -Check console output at ${env.BUILD_URL}""", - recipientProviders: [[$class: 'DevelopersRecipientProvider']] - ) - } - failure { - emailext ( - subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", - body: """The Job ${env.JOB_NAME} resulted in an unexpected error during build ${env.BUILD_NUMBER}. - -Check console output at ${env.BUILD_URL}""", - recipientProviders: [[$class: 'DevelopersRecipientProvider']] - ) - } - } -} \ No newline at end of file From 8329e00502e6d093b09424a1da94c9fad686f19e Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Tue, 12 Sep 2023 16:09:13 +0200 Subject: [PATCH 23/43] Make micro manager binning core property read-only and set a single allowed value to make the binning field in the main window unchangeable --- DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 05e827c84..fdb423678 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -86,7 +86,8 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) m_currentPixelFormat{} { CreateHubIDProperty(); // Binning property is a Core Property, we will have a dummy one - CreateProperty(MM::g_Keyword_Binning, "1", MM::Integer, false, nullptr); + CreateProperty(MM::g_Keyword_Binning, "N/A", MM::String, true, nullptr); + AddAllowedValue(MM::g_Keyword_Binning, "N/A"); } int AlliedVisionCamera::Initialize() { @@ -314,7 +315,7 @@ int AlliedVisionCamera::GetBinning() const { int AlliedVisionCamera::SetBinning(int binSize) { // Binning not supported. We support BinningVertical/Horizontal - return DEVICE_OK; + return DEVICE_ERR; } double AlliedVisionCamera::GetExposure() const { From a9fc9c6b5ecbadda9a5752b755d169aee1cf21e4 Mon Sep 17 00:00:00 2001 From: Florian Klostermann Date: Tue, 12 Sep 2023 17:19:05 +0200 Subject: [PATCH 24/43] Enable readonly properties -> properties will be greyed out in property browser if they are readonly or unavailable --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index fdb423678..5023a00c1 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -450,6 +450,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Init std::vector featureNames = {}; VmbError_t err = VmbErrorSuccess; + MM::Property* pChildProperty = (MM::Property*)pProp; const auto propertyName = pProp->GetName(); // Check property mapping @@ -459,7 +460,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, for (const auto& featureName : featureNames) { // Get Feature Info and Access Mode VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}, featureAvailable{}; + bool rMode{}, wMode{}, readOnly{}, featureAvailable{}; err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), &featureInfo, sizeof(featureInfo)) | m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, @@ -469,15 +470,9 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, return err; } + readOnly = (rMode && !wMode); featureAvailable = rMode || wMode; - if (!featureAvailable) { - LOG_ERROR(VmbErrorFeaturesUnavailable, - "Feature is currently not available! Feature: " + featureName); - return err; - } - // TODO - // Set somehow property to be unavailable when there is no r and w modes - + // Get values std::string propertyValue{}, featureValue{}; pProp->Get(propertyValue); @@ -485,6 +480,35 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Handle property value change switch (eAct) { case MM::ActionType::BeforeGet: //!< Update property from feature + + // Update feature range + if (featureAvailable) + { + err = setAllowedValues(&featureInfo, propertyName.c_str()); + } + // Feature not available -> clear value and range + else { + switch (featureInfo.featureDataType) { + case VmbFeatureDataInt: + case VmbFeatureDataFloat: + err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); + pProp->Set("0"); + break; + case VmbFeatureDataEnum: + case VmbFeatureDataString: + case VmbFeatureDataBool: + case VmbFeatureDataCommand: + ClearAllowedValues(propertyName.c_str()); + pProp->Set(""); + break; + case VmbFeatureDataRaw: + case VmbFeatureDataNone: + default: + // feature type not supported + break; + } + } + if (rMode) { err = getFeatureValue(&featureInfo, featureName.c_str(), featureValue); @@ -511,7 +535,8 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, } } - err = setAllowedValues(&featureInfo, propertyName.c_str()); + // Set property to readonly (grey out in GUI) if it is readonly or unavailable + pChildProperty->SetReadOnly(readOnly || !featureAvailable); break; case MM::ActionType::AfterSet: //!< Update feature from property @@ -831,9 +856,20 @@ VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, VmbError_t err = VmbErrorSuccess; switch (feature->featureDataType) { - case VmbFeatureDataCommand: case VmbFeatureDataBool: { - // Already set in creation + // Already set in creation, but maybe reset when become unavailable + if (GetNumberOfPropertyValues(propertyName) == 0) { + AddAllowedValue(propertyName, g_False); + AddAllowedValue(propertyName, g_True); + } + break; + } + case VmbFeatureDataCommand: { + // Already set in creation, but maybe reset when become unavailable + if (GetNumberOfPropertyValues(propertyName) == 0) { + AddAllowedValue(propertyName, g_Command); + AddAllowedValue(propertyName, g_Execute); + } break; } case VmbFeatureDataFloat: { From 73d2a29db8348cbbe6fc07dd0ef87564a4a19a0e Mon Sep 17 00:00:00 2001 From: Florian Klostermann Date: Wed, 13 Sep 2023 09:09:12 +0200 Subject: [PATCH 25/43] Use dynamic_cast for downcasting; declare const where possible; use Property's GetType() function to determine property type (instead of Vmb feature type) --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 5023a00c1..c7318022e 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -450,17 +450,24 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, // Init std::vector featureNames = {}; VmbError_t err = VmbErrorSuccess; - MM::Property* pChildProperty = (MM::Property*)pProp; + + auto pChildProperty = dynamic_cast(pProp); + if (pChildProperty == nullptr) { + err = VmbErrorBadParameter; + LOG_ERROR(err, "Could not get Property from PropertyBase object"); + return err; + } + const auto propertyName = pProp->GetName(); // Check property mapping mapPropertyNameToFeatureNames(propertyName.c_str(), featureNames); - // Retrive each feature + // Retrieve each feature for (const auto& featureName : featureNames) { // Get Feature Info and Access Mode VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}, readOnly{}, featureAvailable{}; + bool rMode{}, wMode{}; err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), &featureInfo, sizeof(featureInfo)) | m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, @@ -470,8 +477,8 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, return err; } - readOnly = (rMode && !wMode); - featureAvailable = rMode || wMode; + const bool readOnly = (rMode && !wMode); + const bool featureAvailable = (rMode || wMode); // Get values std::string propertyValue{}, featureValue{}; @@ -487,22 +494,17 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, err = setAllowedValues(&featureInfo, propertyName.c_str()); } // Feature not available -> clear value and range - else { - switch (featureInfo.featureDataType) { - case VmbFeatureDataInt: - case VmbFeatureDataFloat: + else { + switch (pProp->GetType()) { + case MM::Float: + case MM::Integer: err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); pProp->Set("0"); break; - case VmbFeatureDataEnum: - case VmbFeatureDataString: - case VmbFeatureDataBool: - case VmbFeatureDataCommand: + case MM::String: ClearAllowedValues(propertyName.c_str()); pProp->Set(""); break; - case VmbFeatureDataRaw: - case VmbFeatureDataNone: default: // feature type not supported break; From bddc46261986a2b7a562007536f71a690f96d65f Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Fri, 8 Sep 2023 11:18:16 +0200 Subject: [PATCH 26/43] Fixed UNI-583 VimbaX shared libraries must be copied to "/usr/local/bin" The Allied Vision Camera Adapter was trying to load the VimbaX shared libraries from the fixed path "/usr/local/bin". This was not good, because "/usr/local/bin" is on linux a location for applications and not for libraries. Instead, now the standard linux dynamic library loading mechanism is used, which tries to automatically resolve the path of the shared library by using the system paths, ld.so.conf and the environment variable LD_LIBRARY_PATH. Adjusted the licence headers, because the micro manager adapter development was not started in 2012. --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 2 +- .../AlliedVisionCamera/AlliedVisionCamera.h | 2 +- .../AlliedVisionDeviceBase.h | 2 +- .../AlliedVisionCamera/AlliedVisionHub.cpp | 18 ++++++++++++++++++ .../AlliedVisionCamera/AlliedVisionHub.h | 2 +- .../AlliedVisionCamera/SDK/Loader/Constants.h | 5 ++--- .../SDK/Loader/LibLoader.cpp | 4 ++-- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 2 +- 8 files changed, 27 insertions(+), 10 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index c7318022e..a3797498f 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. Redistribution of this header file, in original or modified form, without prior written consent of Allied Vision Technologies is prohibited. diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index d8eb56439..6a0bd040b 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. Redistribution of this header file, in original or modified form, without prior written consent of Allied Vision Technologies is prohibited. diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h index 825d65118..cccb06d13 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. Redistribution of this header file, in original or modified form, without prior written consent of Allied Vision Technologies is prohibited. diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp index 9d5a11173..1400542d9 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp @@ -1,3 +1,21 @@ +/*============================================================================= + Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. + + Redistribution of this header file, in original or modified form, without + prior written consent of Allied Vision Technologies is prohibited. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ #include "AlliedVisionHub.h" #include "AlliedVisionCamera.h" diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h index 00e50b55a..c0daf74cd 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. Redistribution of this header file, in original or modified form, without prior written consent of Allied Vision Technologies is prohibited. diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h index 99e9c3c3a..e3c39a896 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2012 - 2023 Allied Vision Technologies. All Rights Reserved. + Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. Redistribution of this header file, in original or modified form, without prior written consent of Allied Vision Technologies is prohibited. @@ -20,8 +20,7 @@ #define CONSTANTS_H #ifdef __linux__ -static std::string VIMBA_X_LIB_DIR = std::string( - "/usr/local/bin/"); // Date: Wed, 13 Sep 2023 11:37:48 +0200 Subject: [PATCH 27/43] Before a feature is read or written the locale is set to the current user locale. --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 278 +++++++++--------- 1 file changed, 144 insertions(+), 134 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index a3797498f..b29de219c 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -447,140 +447,150 @@ bool AlliedVisionCamera::IsCapturing() { return m_isAcquisitionRunning; } int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, MM::ActionType eAct) { - // Init - std::vector featureNames = {}; - VmbError_t err = VmbErrorSuccess; - - auto pChildProperty = dynamic_cast(pProp); - if (pChildProperty == nullptr) { - err = VmbErrorBadParameter; - LOG_ERROR(err, "Could not get Property from PropertyBase object"); - return err; - } - - const auto propertyName = pProp->GetName(); - - // Check property mapping - mapPropertyNameToFeatureNames(propertyName.c_str(), featureNames); - - // Retrieve each feature - for (const auto& featureName : featureNames) { - // Get Feature Info and Access Mode - VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}; - err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), - &featureInfo, sizeof(featureInfo)) | - m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, - &wMode); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting info or access query!"); - return err; - } - - const bool readOnly = (rMode && !wMode); - const bool featureAvailable = (rMode || wMode); - - // Get values - std::string propertyValue{}, featureValue{}; - pProp->Get(propertyValue); - - // Handle property value change - switch (eAct) { - case MM::ActionType::BeforeGet: //!< Update property from feature - - // Update feature range - if (featureAvailable) - { - err = setAllowedValues(&featureInfo, propertyName.c_str()); - } - // Feature not available -> clear value and range - else { - switch (pProp->GetType()) { - case MM::Float: - case MM::Integer: - err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); - pProp->Set("0"); - break; - case MM::String: - ClearAllowedValues(propertyName.c_str()); - pProp->Set(""); - break; - default: - // feature type not supported - break; - } - } - - if (rMode) { - err = - getFeatureValue(&featureInfo, featureName.c_str(), featureValue); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting feature value " + featureName); - return err; - } - - // Update property - if (propertyValue != featureValue) { - pProp->Set(featureValue.c_str()); - err = GetCoreCallback()->OnPropertyChanged( - this, propertyName.c_str(), featureValue.c_str()); - if (propertyName == MM::g_Keyword_PixelType) { - handlePixelFormatChange(featureValue); - } - - if (VmbErrorSuccess != err) { - LOG_ERROR(err, - "Error while calling OnPropertyChanged callback for " + - featureName); - return err; - } - } - } - - // Set property to readonly (grey out in GUI) if it is readonly or unavailable - pChildProperty->SetReadOnly(readOnly || !featureAvailable); - - break; - case MM::ActionType::AfterSet: //!< Update feature from property - err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); - if (err == VmbErrorInvalidValue) { - // Update limits first to have latest min and max - err = setAllowedValues(&featureInfo, propertyName.c_str()); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while setting allowed values for feature " + - featureName); - return err; - } - - // Adjust value - double min{}, max{}; - err = GetPropertyLowerLimit(propertyName.c_str(), min) | - GetPropertyUpperLimit(propertyName.c_str(), max); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting limits for " + propertyName); - return err; - } - std::string adjustedValue = - adjustValue(featureInfo, min, max, std::stod(propertyValue)); - err = - setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); - } - - if (propertyName == MM::g_Keyword_PixelType) { - handlePixelFormatChange(propertyValue); - } - break; - default: - // nothing - break; - } - } - - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while updating property " + propertyName); - } - - return err; + //Set locale to current system locale + const auto oldLocale = std::setlocale(LC_ALL, ""); + + const auto res = [&] { + // Init + std::vector featureNames = {}; + VmbError_t err = VmbErrorSuccess; + + auto pChildProperty = dynamic_cast(pProp); + if (pChildProperty == nullptr) { + err = VmbErrorBadParameter; + LOG_ERROR(err, "Could not get Property from PropertyBase object"); + return err; + } + + const auto propertyName = pProp->GetName(); + + // Check property mapping + mapPropertyNameToFeatureNames(propertyName.c_str(), featureNames); + + // Retrieve each feature + for (const auto& featureName : featureNames) { + // Get Feature Info and Access Mode + VmbFeatureInfo_t featureInfo; + bool rMode{}, wMode{}; + err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), + &featureInfo, sizeof(featureInfo)) | + m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, + &wMode); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting info or access query!"); + return err; + } + + const bool readOnly = (rMode && !wMode); + const bool featureAvailable = (rMode || wMode); + + // Get values + std::string propertyValue{}, featureValue{}; + pProp->Get(propertyValue); + + // Handle property value change + switch (eAct) { + case MM::ActionType::BeforeGet: //!< Update property from feature + + // Update feature range + if (featureAvailable) + { + err = setAllowedValues(&featureInfo, propertyName.c_str()); + } + // Feature not available -> clear value and range + else { + switch (pProp->GetType()) { + case MM::Float: + case MM::Integer: + err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); + pProp->Set("0"); + break; + case MM::String: + ClearAllowedValues(propertyName.c_str()); + pProp->Set(""); + break; + default: + // feature type not supported + break; + } + } + + if (rMode) { + err = + getFeatureValue(&featureInfo, featureName.c_str(), featureValue); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting feature value " + featureName); + return err; + } + + // Update property + if (propertyValue != featureValue) { + pProp->Set(featureValue.c_str()); + err = GetCoreCallback()->OnPropertyChanged( + this, propertyName.c_str(), featureValue.c_str()); + if (propertyName == MM::g_Keyword_PixelType) { + handlePixelFormatChange(featureValue); + } + + if (VmbErrorSuccess != err) { + LOG_ERROR(err, + "Error while calling OnPropertyChanged callback for " + + featureName); + return err; + } + } + } + + // Set property to readonly (grey out in GUI) if it is readonly or unavailable + pChildProperty->SetReadOnly(readOnly || !featureAvailable); + + break; + case MM::ActionType::AfterSet: //!< Update feature from property + err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); + if (err == VmbErrorInvalidValue) { + // Update limits first to have latest min and max + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while setting allowed values for feature " + + featureName); + return err; + } + + // Adjust value + double min{}, max{}; + err = GetPropertyLowerLimit(propertyName.c_str(), min) | + GetPropertyUpperLimit(propertyName.c_str(), max); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting limits for " + propertyName); + return err; + } + std::string adjustedValue = + adjustValue(featureInfo, min, max, std::stod(propertyValue)); + err = + setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); + } + + if (propertyName == MM::g_Keyword_PixelType) { + handlePixelFormatChange(propertyValue); + } + break; + default: + // nothing + break; + } + } + + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while updating property " + propertyName); + } + + + return err; + }(); + + std::setlocale(LC_ALL, oldLocale); + + return res; } void AlliedVisionCamera::handlePixelFormatChange(const std::string& pixelType) { From 3143322cfaa8d87439ff5ceeab6e3540c4ca2755 Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Wed, 13 Sep 2023 17:17:50 +0200 Subject: [PATCH 28/43] Fixed UNI-591 main window exposure setting not working The legacy cameras use the feature "ExposureTimeAbs" instead of "ExposureTime" for setting the expsure time. The adapter was using the "ExposureTime" feature for the main window exposure setting. If the feature "ExposureTime" is available, it is used for the exposure setting. But if it is not available now "ExposureTimeAbs" is used for the exposure setting. The value of the exposure setting now also corrected to milliseconds. --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 352 ++++++++++-------- 1 file changed, 188 insertions(+), 164 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index b29de219c..dcfcb05be 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -32,15 +32,11 @@ /////////////////////////////////////////////////////////////////////////////// // STATIC VALUES /////////////////////////////////////////////////////////////////////////////// -const std::unordered_map - AlliedVisionCamera::m_featureToProperty = { - {g_PixelFormatFeature, MM::g_Keyword_PixelType}, - {g_ExposureFeature, MM::g_Keyword_Exposure}}; -const std::unordered_multimap - AlliedVisionCamera::m_propertyToFeature = { - {MM::g_Keyword_PixelType, g_PixelFormatFeature}, - {MM::g_Keyword_Exposure, g_ExposureFeature}}; +const std::unordered_map AlliedVisionCamera::m_featureToProperty = +{ + {g_PixelFormatFeature, MM::g_Keyword_PixelType } +}; /////////////////////////////////////////////////////////////////////////////// // Exported MMDevice API @@ -83,7 +79,9 @@ AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) m_bufferSize{0}, m_payloadSize{0}, m_isAcquisitionRunning{false}, - m_currentPixelFormat{} { + m_currentPixelFormat{}, + m_propertyToFeature{}, + m_exposureFeatureName{} { CreateHubIDProperty(); // Binning property is a Core Property, we will have a dummy one CreateProperty(MM::g_Keyword_Binning, "N/A", MM::String, true, nullptr); @@ -132,23 +130,47 @@ VmbError_t AlliedVisionCamera::setupProperties() { return err; } - std::shared_ptr features = - std::shared_ptr(new VmbFeatureInfo_t[featureCount]); - err = m_sdk->VmbFeaturesList_t(m_handle, features.get(), featureCount, + std::vector features{featureCount}; + + err = m_sdk->VmbFeaturesList_t(m_handle, features.data(), featureCount, &featureCount, sizeof(VmbFeatureInfo_t)); if (err != VmbErrorSuccess) { LOG_ERROR(err, "Error occurred when obtaining features!"); return err; } - const VmbFeatureInfo_t* end = features.get() + featureCount; - for (VmbFeatureInfo_t* feature = features.get(); feature != end; ++feature) { - err = createPropertyFromFeature(feature); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, - "Error while creating property" + std::string(feature->name)); - continue; - } + const auto exposureTime = std::find_if(features.begin(), features.end(), [](const auto& feat) + { + return std::string(feat.name) == g_ExposureFeature; + }); + + if (exposureTime != features.end()) + { + m_exposureFeatureName = std::string{ exposureTime->name }; + } + else + { + const auto exposureTimeAbs = std::find_if(features.begin(), features.end(), [](const auto& feat) + { + return std::string(feat.name) == g_ExposureAbsFeature; + }); + + if (exposureTimeAbs != features.end()) + { + m_exposureFeatureName = std::string{ exposureTimeAbs->name }; + } + } + + + + for (const auto & feature : features) { + if (feature.visibility != VmbFeatureVisibilityInvisible) + { + err = createPropertyFromFeature(&feature); + if (err != VmbErrorSuccess) { + LOG_ERROR(err, "Error while creating property" + std::string(feature.name)); + } + } } return VmbErrorSuccess; @@ -191,8 +213,20 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( } // Map feature to property name - std::string propertyName = {}; - mapFeatureNameToPropertyName(feature->name, propertyName); + const auto propertyName = [&] { + const auto tempName = mapFeatureNameToPropertyName(feature->name); + + if (tempName != feature->name) + { + if (!m_propertyToFeature.count(tempName)) + { + m_propertyToFeature.emplace(tempName, feature->name); + return tempName; + } + } + + return std::string(feature->name); + }(); // uManager callback CPropertyAction* uManagerCallback = @@ -204,8 +238,7 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature( (void)handle; AlliedVisionCamera* camera = reinterpret_cast(userContext); - std::string propertyName; - camera->mapFeatureNameToPropertyName(name, propertyName); + const auto propertyName = camera->mapFeatureNameToPropertyName(name); auto err = camera->UpdateProperty(propertyName.c_str()); if (err != VmbErrorSuccess) { camera->LOG_ERROR(err, "Property: " + propertyName + " update failed"); @@ -320,17 +353,17 @@ int AlliedVisionCamera::SetBinning(int binSize) { double AlliedVisionCamera::GetExposure() const { std::string value{}; - auto ret = getFeatureValue(g_ExposureFeature, value); + auto ret = getFeatureValue(m_exposureFeatureName.c_str(), value); if (ret != VmbErrorSuccess) { LOG_ERROR(ret, "Error while getting exposure!"); return 0; } - return strtod(value.c_str(), nullptr); + return std::stod(value) / MS_TO_US; } void AlliedVisionCamera::SetExposure(double exp_ms) { - SetProperty(MM::g_Keyword_Exposure, CDeviceUtils::ConvertToString(exp_ms)); + SetProperty(m_exposureFeatureName.c_str(), CDeviceUtils::ConvertToString(exp_ms * MS_TO_US)); GetCoreCallback()->OnExposureChanged(this, exp_ms); } @@ -452,7 +485,6 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, const auto res = [&] { // Init - std::vector featureNames = {}; VmbError_t err = VmbErrorSuccess; auto pChildProperty = dynamic_cast(pProp); @@ -465,120 +497,117 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, const auto propertyName = pProp->GetName(); // Check property mapping - mapPropertyNameToFeatureNames(propertyName.c_str(), featureNames); - - // Retrieve each feature - for (const auto& featureName : featureNames) { - // Get Feature Info and Access Mode - VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}; - err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), - &featureInfo, sizeof(featureInfo)) | - m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, - &wMode); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting info or access query!"); - return err; - } - - const bool readOnly = (rMode && !wMode); - const bool featureAvailable = (rMode || wMode); - - // Get values - std::string propertyValue{}, featureValue{}; - pProp->Get(propertyValue); - - // Handle property value change - switch (eAct) { - case MM::ActionType::BeforeGet: //!< Update property from feature - - // Update feature range - if (featureAvailable) - { - err = setAllowedValues(&featureInfo, propertyName.c_str()); - } - // Feature not available -> clear value and range - else { - switch (pProp->GetType()) { - case MM::Float: - case MM::Integer: - err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); - pProp->Set("0"); - break; - case MM::String: - ClearAllowedValues(propertyName.c_str()); - pProp->Set(""); - break; - default: - // feature type not supported - break; - } - } - - if (rMode) { - err = - getFeatureValue(&featureInfo, featureName.c_str(), featureValue); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting feature value " + featureName); - return err; - } - - // Update property - if (propertyValue != featureValue) { - pProp->Set(featureValue.c_str()); - err = GetCoreCallback()->OnPropertyChanged( - this, propertyName.c_str(), featureValue.c_str()); - if (propertyName == MM::g_Keyword_PixelType) { - handlePixelFormatChange(featureValue); - } - - if (VmbErrorSuccess != err) { - LOG_ERROR(err, - "Error while calling OnPropertyChanged callback for " + - featureName); - return err; - } - } - } - - // Set property to readonly (grey out in GUI) if it is readonly or unavailable - pChildProperty->SetReadOnly(readOnly || !featureAvailable); - - break; - case MM::ActionType::AfterSet: //!< Update feature from property - err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); - if (err == VmbErrorInvalidValue) { - // Update limits first to have latest min and max - err = setAllowedValues(&featureInfo, propertyName.c_str()); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while setting allowed values for feature " + - featureName); - return err; - } - - // Adjust value - double min{}, max{}; - err = GetPropertyLowerLimit(propertyName.c_str(), min) | - GetPropertyUpperLimit(propertyName.c_str(), max); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting limits for " + propertyName); - return err; - } - std::string adjustedValue = - adjustValue(featureInfo, min, max, std::stod(propertyValue)); - err = - setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); - } - - if (propertyName == MM::g_Keyword_PixelType) { - handlePixelFormatChange(propertyValue); - } - break; - default: - // nothing - break; - } - } + auto const featureName = mapPropertyNameToFeatureName(propertyName.c_str()); + + // Get Feature Info and Access Mode + VmbFeatureInfo_t featureInfo; + bool rMode{}, wMode{}; + err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), + &featureInfo, sizeof(featureInfo)) | + m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, + &wMode); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting info or access query!"); + return err; + } + + const bool readOnly = (rMode && !wMode); + const bool featureAvailable = (rMode || wMode); + + // Get values + std::string propertyValue{}, featureValue{}; + pProp->Get(propertyValue); + + // Handle property value change + switch (eAct) { + case MM::ActionType::BeforeGet: //!< Update property from feature + + // Update feature range + if (featureAvailable) + { + err = setAllowedValues(&featureInfo, propertyName.c_str()); + } + // Feature not available -> clear value and range + else { + switch (pProp->GetType()) { + case MM::Float: + case MM::Integer: + err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); + pProp->Set("0"); + break; + case MM::String: + ClearAllowedValues(propertyName.c_str()); + pProp->Set(""); + break; + default: + // feature type not supported + break; + } + } + + if (rMode) { + err = + getFeatureValue(&featureInfo, featureName.c_str(), featureValue); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting feature value " + featureName); + return err; + } + + // Update property + if (propertyValue != featureValue) { + pProp->Set(featureValue.c_str()); + err = GetCoreCallback()->OnPropertyChanged( + this, propertyName.c_str(), featureValue.c_str()); + if (propertyName == MM::g_Keyword_PixelType) { + handlePixelFormatChange(featureValue); + } + + if (VmbErrorSuccess != err) { + LOG_ERROR(err, + "Error while calling OnPropertyChanged callback for " + + featureName); + return err; + } + } + } + + // Set property to readonly (grey out in GUI) if it is readonly or unavailable + pChildProperty->SetReadOnly(readOnly || !featureAvailable); + + break; + case MM::ActionType::AfterSet: //!< Update feature from property + err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); + if (err == VmbErrorInvalidValue) { + // Update limits first to have latest min and max + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while setting allowed values for feature " + + featureName); + return err; + } + + // Adjust value + double min{}, max{}; + err = GetPropertyLowerLimit(propertyName.c_str(), min) | + GetPropertyUpperLimit(propertyName.c_str(), max); + if (VmbErrorSuccess != err) { + LOG_ERROR(err, "Error while getting limits for " + propertyName); + return err; + } + std::string adjustedValue = + adjustValue(featureInfo, min, max, std::stod(propertyValue)); + err = + setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); + } + + if (propertyName == MM::g_Keyword_PixelType) { + handlePixelFormatChange(propertyValue); + } + break; + default: + // nothing + break; + } if (VmbErrorSuccess != err) { LOG_ERROR(err, "Error while updating property " + propertyName); @@ -693,7 +722,6 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, std::stringstream ss(value); bool isDone = false; VmbUint32_t maxLen = 0; - std::string property{}; switch (featureInfo->featureDataType) { case VmbFeatureDataBool: { @@ -733,8 +761,8 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, } case VmbFeatureDataCommand: if (value == g_Execute) { - mapFeatureNameToPropertyName(featureName, property); - if (!property.empty()) { + const auto propertyName = mapFeatureNameToPropertyName(featureName); + if (!propertyName.empty()) { err = m_sdk->VmbFeatureCommandRun_t(m_handle, featureName); if (err != VmbErrorSuccess) { break; @@ -747,8 +775,8 @@ VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, } } // Set back property to "Command" - err = SetProperty(property.c_str(), g_Command); - GetCoreCallback()->OnPropertyChanged(this, property.c_str(), + err = SetProperty(propertyName.c_str(), g_Command); + GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), g_Command); if (err != VmbErrorSuccess) { break; @@ -788,27 +816,23 @@ VmbError_t AlliedVisionCamera::setFeatureValue(const char* featureName, return setFeatureValue(&featureInfo, featureName, value); } -void AlliedVisionCamera::mapFeatureNameToPropertyName( - const char* feature, std::string& property) const { - property = std::string(feature); - auto search = m_featureToProperty.find(property); +std::string AlliedVisionCamera::mapFeatureNameToPropertyName( + const char* feature) const { + + auto search = m_featureToProperty.find(feature); if (search != m_featureToProperty.end()) { - property = search->second; + return search->second; } + + return feature; } -void AlliedVisionCamera::mapPropertyNameToFeatureNames( - const char* property, std::vector& featureNames) const { - // Check property mapping - auto searchRange = m_propertyToFeature.equal_range(property); - if (searchRange.first != m_propertyToFeature.end()) { - // Features that are mapped from property - for (auto it = searchRange.first; it != searchRange.second; ++it) { - featureNames.push_back(it->second); +std::string AlliedVisionCamera::mapPropertyNameToFeatureName(const char* property) const { + auto search = m_propertyToFeature.find(property); + if (search != m_propertyToFeature.end()) { + return search->second; } - } else { - // for rest - featureNames.push_back(property); - } + + return property; } std::string AlliedVisionCamera::adjustValue(VmbFeatureInfo_t& featureInfo, From 486e24fed6e9e4de75ebaa7f15c2b347086c1ee1 Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Wed, 13 Sep 2023 17:18:41 +0200 Subject: [PATCH 29/43] Updated header --- .../AlliedVisionCamera/AlliedVisionCamera.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 6a0bd040b..d34e5ffca 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -28,11 +28,13 @@ #include "DeviceBase.h" #include "Loader/LibLoader.h" + /////////////////////////////////////////////////////////////////////////////// // STATIC FEATURE NAMES (FROM VIMBA) /////////////////////////////////////////////////////////////////////////////// static constexpr const char* g_PixelFormatFeature = "PixelFormat"; static constexpr const char* g_ExposureFeature = "ExposureTime"; +static constexpr const char* g_ExposureAbsFeature = "ExposureTimeAbs"; static constexpr const char* g_BinningHorizontalFeature = "BinningHorizontal"; static constexpr const char* g_BinningVerticalFeature = "BinningVertical"; static constexpr const char* g_Width = "Width"; @@ -55,6 +57,8 @@ static constexpr const char* g_AcquisitionStart = "AcquisitionStart"; static constexpr const char* g_AcquisitionStop = "AcquisitionStop"; static constexpr const char* g_AcqusitionStatus = "AcqusitionStatus"; +static constexpr const double MS_TO_US = 1000.0; + /** * @brief Pixel Format class that contains VMB Pixel Format info and contains * helper methods to convert these information to the one that uManager @@ -370,10 +374,9 @@ class AlliedVisionCamera /** * @brief Helper method to map feature name into property name of uManager * @param[in] feature Vimba Feature name - * @param property uManager property name + * @return uManager property name */ - void mapFeatureNameToPropertyName(const char* feature, - std::string& property) const; + std::string mapFeatureNameToPropertyName(const char* feature) const; /** * @brief Helper method to map uManager property in Vimba feature or features @@ -381,8 +384,7 @@ class AlliedVisionCamera * @param[in] property uManager property name * @param featureNames Vimba feature or features name */ - void mapPropertyNameToFeatureNames( - const char* property, std::vector& featureNames) const; + std::string mapPropertyNameToFeatureName(const char* property) const; /** * @brief In case trying to set invalid value, adjust it to the closest with @@ -428,12 +430,17 @@ class AlliedVisionCamera VmbUint32_t m_payloadSize; // m_featureToProperty; //!< Map of features name into uManager properties - static const std::unordered_multimap + std::unordered_map m_propertyToFeature; //!< Map of uManager properties into Vimba features + }; #endif From 05629546f06e9ca7dfa6b9a065cce3603c9107c2 Mon Sep 17 00:00:00 2001 From: Florian Klostermann Date: Thu, 14 Sep 2023 13:09:33 +0200 Subject: [PATCH 30/43] adjusted Windows VmbC dll search path: use /bin instead of /api/bin --- DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h index e3c39a896..1350187a8 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h @@ -33,7 +33,7 @@ static const char* ENV_VALUE = static std::string VIMBA_X_LIB_DIR = std::string(ENV_VALUE != nullptr ? ENV_VALUE : "") + std::string( - "\\api\\bin"); // Date: Thu, 14 Sep 2023 14:52:08 +0200 Subject: [PATCH 31/43] refactored code with clang-format --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 2060 +++++++++-------- .../AlliedVisionCamera/AlliedVisionCamera.h | 793 ++++--- .../AlliedVisionDeviceBase.cpp | 2 - .../AlliedVisionDeviceBase.h | 108 +- .../AlliedVisionCamera/AlliedVisionHub.cpp | 94 +- .../AlliedVisionCamera/AlliedVisionHub.h | 60 +- .../AlliedVisionCamera/SDK/Loader/Constants.h | 24 +- .../SDK/Loader/LibLoader.cpp | 262 +-- .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 284 +-- 9 files changed, 1909 insertions(+), 1778 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index dcfcb05be..d736fc617 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -16,7 +16,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ -#define NOMINMAX // AlliedVisionCamera::m_featureToProperty = -{ - {g_PixelFormatFeature, MM::g_Keyword_PixelType } -}; +const std::unordered_map AlliedVisionCamera::m_featureToProperty = { { g_PixelFormatFeature, + MM::g_Keyword_PixelType } }; /////////////////////////////////////////////////////////////////////////////// // Exported MMDevice API /////////////////////////////////////////////////////////////////////////////// -MODULE_API void InitializeModuleData() { - RegisterDevice(g_hubName, MM::HubDevice, "Allied Vision Hub"); +MODULE_API void InitializeModuleData() +{ + RegisterDevice(g_hubName, MM::HubDevice, "Allied Vision Hub"); } -MODULE_API MM::Device* CreateDevice(const char* deviceName) { - if (deviceName == nullptr) { - return nullptr; - } +MODULE_API MM::Device *CreateDevice(const char *deviceName) +{ + if (deviceName == nullptr) + { + return nullptr; + } - if (std::string(deviceName) == std::string(g_hubName)) { - return new AlliedVisionHub(); - } else { - return new AlliedVisionCamera(deviceName); - } + if (std::string(deviceName) == std::string(g_hubName)) + { + return new AlliedVisionHub(); + } + else + { + return new AlliedVisionCamera(deviceName); + } } -MODULE_API void DeleteDevice(MM::Device* pDevice) { delete pDevice; } +MODULE_API void DeleteDevice(MM::Device *pDevice) +{ + delete pDevice; +} /////////////////////////////////////////////////////////////////////////////// // AlliedVisionCamera /////////////////////////////////////////////////////////////////////////////// -AlliedVisionCamera::~AlliedVisionCamera() { - m_handle = nullptr; +AlliedVisionCamera::~AlliedVisionCamera() +{ + m_handle = nullptr; - for (size_t i = 0; i < MAX_FRAMES; i++) { - delete[] m_buffer[i]; - } + for (size_t i = 0; i < MAX_FRAMES; i++) + { + delete[] m_buffer[i]; + } } -AlliedVisionCamera::AlliedVisionCamera(const char* deviceName) - : m_sdk(nullptr), - m_handle{nullptr}, - m_cameraName{deviceName}, - m_frames{}, - m_buffer{}, - m_bufferSize{0}, - m_payloadSize{0}, - m_isAcquisitionRunning{false}, - m_currentPixelFormat{}, - m_propertyToFeature{}, - m_exposureFeatureName{} { - CreateHubIDProperty(); - // Binning property is a Core Property, we will have a dummy one - CreateProperty(MM::g_Keyword_Binning, "N/A", MM::String, true, nullptr); - AddAllowedValue(MM::g_Keyword_Binning, "N/A"); +AlliedVisionCamera::AlliedVisionCamera(const char *deviceName) : + m_sdk(nullptr), + m_handle{ nullptr }, + m_cameraName{ deviceName }, + m_frames{}, + m_buffer{}, + m_bufferSize{ 0 }, + m_payloadSize{ 0 }, + m_isAcquisitionRunning{ false }, + m_currentPixelFormat{}, + m_propertyToFeature{}, + m_exposureFeatureName{} +{ + CreateHubIDProperty(); + // Binning property is a Core Property, we will have a dummy one + CreateProperty(MM::g_Keyword_Binning, "N/A", MM::String, true, nullptr); + AddAllowedValue(MM::g_Keyword_Binning, "N/A"); } -int AlliedVisionCamera::Initialize() { - auto parentHub = dynamic_cast(GetParentHub()); - if (parentHub == nullptr) { - LOG_ERROR(VmbErrorBadParameter, "Parent HUB not found!"); - return VmbErrorBadParameter; - } - m_sdk = parentHub->getSDK(); - - LogMessage("Opening camera: " + m_cameraName); - VmbError_t err = m_sdk->VmbCameraOpen_t( - m_cameraName.c_str(), VmbAccessModeType::VmbAccessModeFull, &m_handle); - if (err != VmbErrorSuccess || m_handle == nullptr) { - LOG_ERROR(err, "Error while opening camera or handle is NULL!"); - return err; - } +int AlliedVisionCamera::Initialize() +{ + auto parentHub = dynamic_cast(GetParentHub()); + if (parentHub == nullptr) + { + LOG_ERROR(VmbErrorBadParameter, "Parent HUB not found!"); + return VmbErrorBadParameter; + } + m_sdk = parentHub->getSDK(); + + LogMessage("Opening camera: " + m_cameraName); + VmbError_t err = m_sdk->VmbCameraOpen_t(m_cameraName.c_str(), VmbAccessModeType::VmbAccessModeFull, &m_handle); + if (err != VmbErrorSuccess || m_handle == nullptr) + { + LOG_ERROR(err, "Error while opening camera or handle is NULL!"); + return err; + } - // Ignore errors from setting up properties - (void)setupProperties(); - return resizeImageBuffer(); + // Ignore errors from setting up properties + (void)setupProperties(); + return resizeImageBuffer(); } -int AlliedVisionCamera::Shutdown() { - LogMessage("Shutting down camera: " + m_cameraName); - VmbError_t err = VmbErrorSuccess; - if (m_sdk != nullptr && m_sdk->isInitialized()) { - if (m_handle != nullptr) { - err = m_sdk->VmbCameraClose_t(m_handle); +int AlliedVisionCamera::Shutdown() +{ + LogMessage("Shutting down camera: " + m_cameraName); + VmbError_t err = VmbErrorSuccess; + if (m_sdk != nullptr && m_sdk->isInitialized()) + { + if (m_handle != nullptr) + { + err = m_sdk->VmbCameraClose_t(m_handle); + } } - } - return err; + return err; } -VmbError_t AlliedVisionCamera::setupProperties() { - VmbUint32_t featureCount = 0; - VmbError_t err = m_sdk->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, - sizeof(VmbFeatureInfo_t)); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error occurred when obtaining features count!"); - return err; - } +VmbError_t AlliedVisionCamera::setupProperties() +{ + VmbUint32_t featureCount = 0; + VmbError_t err = m_sdk->VmbFeaturesList_t(m_handle, NULL, 0, &featureCount, sizeof(VmbFeatureInfo_t)); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error occurred when obtaining features count!"); + return err; + } - std::vector features{featureCount}; + std::vector features{ featureCount }; - err = m_sdk->VmbFeaturesList_t(m_handle, features.data(), featureCount, - &featureCount, sizeof(VmbFeatureInfo_t)); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error occurred when obtaining features!"); - return err; - } - - const auto exposureTime = std::find_if(features.begin(), features.end(), [](const auto& feat) - { - return std::string(feat.name) == g_ExposureFeature; - }); - - if (exposureTime != features.end()) - { - m_exposureFeatureName = std::string{ exposureTime->name }; - } - else - { - const auto exposureTimeAbs = std::find_if(features.begin(), features.end(), [](const auto& feat) - { - return std::string(feat.name) == g_ExposureAbsFeature; - }); - - if (exposureTimeAbs != features.end()) - { - m_exposureFeatureName = std::string{ exposureTimeAbs->name }; - } - } - - - - for (const auto & feature : features) { - if (feature.visibility != VmbFeatureVisibilityInvisible) - { - err = createPropertyFromFeature(&feature); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while creating property" + std::string(feature.name)); - } - } - } - - return VmbErrorSuccess; + err = m_sdk->VmbFeaturesList_t(m_handle, features.data(), featureCount, &featureCount, sizeof(VmbFeatureInfo_t)); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error occurred when obtaining features!"); + return err; + } + + const auto exposureTime = + std::find_if(features.begin(), features.end(), [](const auto &feat) { return std::string(feat.name) == g_ExposureFeature; }); + + if (exposureTime != features.end()) + { + m_exposureFeatureName = std::string{ exposureTime->name }; + } + else + { + const auto exposureTimeAbs = + std::find_if(features.begin(), features.end(), [](const auto &feat) { return std::string(feat.name) == g_ExposureAbsFeature; }); + + if (exposureTimeAbs != features.end()) + { + m_exposureFeatureName = std::string{ exposureTimeAbs->name }; + } + } + + for (const auto &feature : features) + { + if (feature.visibility != VmbFeatureVisibilityInvisible) + { + err = createPropertyFromFeature(&feature); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while creating property" + std::string(feature.name)); + } + } + } + + return VmbErrorSuccess; } -VmbError_t AlliedVisionCamera::resizeImageBuffer() { - VmbError_t err = m_sdk->VmbPayloadSizeGet_t(m_handle, &m_payloadSize); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while reading payload size"); - return err; - } +VmbError_t AlliedVisionCamera::resizeImageBuffer() +{ + VmbError_t err = m_sdk->VmbPayloadSizeGet_t(m_handle, &m_payloadSize); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while reading payload size"); + return err; + } - m_bufferSize = std::max(GetImageWidth() * GetImageHeight() * - m_currentPixelFormat.getBytesPerPixel(), - m_payloadSize); + m_bufferSize = std::max(GetImageWidth() * GetImageHeight() * m_currentPixelFormat.getBytesPerPixel(), m_payloadSize); - for (size_t i = 0; i < MAX_FRAMES; i++) { - delete[] m_buffer[i]; - m_buffer[i] = new VmbUint8_t[m_bufferSize]; - } + for (size_t i = 0; i < MAX_FRAMES; i++) + { + delete[] m_buffer[i]; + m_buffer[i] = new VmbUint8_t[m_bufferSize]; + } - return VmbErrorSuccess; + return VmbErrorSuccess; } -VmbError_t AlliedVisionCamera::createPropertyFromFeature( - const VmbFeatureInfo_t* feature) { - if (feature == nullptr) { - LogMessage("Cannot create feature. It is NULL"); - return VmbErrorInvalidValue; - } - - VmbError_t err = VmbErrorSuccess; - // Skip Event, Chunk, RAW features - std::string featureCategory = feature->category; - if (featureCategory.find(g_EventCategory) != std::string::npos || - featureCategory.find(g_ChunkCategory) != std::string::npos || - feature->featureDataType == VmbFeatureDataRaw) { - // Skip - return err; - } - - // Map feature to property name - const auto propertyName = [&] { - const auto tempName = mapFeatureNameToPropertyName(feature->name); - - if (tempName != feature->name) - { - if (!m_propertyToFeature.count(tempName)) - { - m_propertyToFeature.emplace(tempName, feature->name); - return tempName; - } - } - - return std::string(feature->name); - }(); - - // uManager callback - CPropertyAction* uManagerCallback = - new CPropertyAction(this, &AlliedVisionCamera::onProperty); - - // Vimba callback - auto vmbCallback = [](VmbHandle_t handle, const char* name, - void* userContext) { - (void)handle; - AlliedVisionCamera* camera = - reinterpret_cast(userContext); - const auto propertyName = camera->mapFeatureNameToPropertyName(name); - auto err = camera->UpdateProperty(propertyName.c_str()); - if (err != VmbErrorSuccess) { - camera->LOG_ERROR(err, "Property: " + propertyName + " update failed"); - } - }; - - // Register VMB callback for given feature - err = m_sdk->VmbFeatureInvalidationRegister_t(m_handle, feature->name, - vmbCallback, this); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while registering invalidation callback for " + - std::string(feature->name)); - return err; - } - - switch (feature->featureDataType) { - case VmbFeatureDataInt: { - err = CreateIntegerProperty(propertyName.c_str(), 0, false, - uManagerCallback); - break; - } - case VmbFeatureDataBool: { - err = CreateStringProperty(propertyName.c_str(), g_False, false, - uManagerCallback); - AddAllowedValue(propertyName.c_str(), g_False); - AddAllowedValue(propertyName.c_str(), g_True); - break; - } - case VmbFeatureDataCommand: { - err = CreateStringProperty(propertyName.c_str(), g_Command, false, - uManagerCallback); - AddAllowedValue(propertyName.c_str(), g_Command); - AddAllowedValue(propertyName.c_str(), g_Execute); - break; +VmbError_t AlliedVisionCamera::createPropertyFromFeature(const VmbFeatureInfo_t *feature) +{ + if (feature == nullptr) + { + LogMessage("Cannot create feature. It is NULL"); + return VmbErrorInvalidValue; + } + + VmbError_t err = VmbErrorSuccess; + // Skip Event, Chunk, RAW features + std::string featureCategory = feature->category; + if (featureCategory.find(g_EventCategory) != std::string::npos || featureCategory.find(g_ChunkCategory) != std::string::npos || + feature->featureDataType == VmbFeatureDataRaw) + { + // Skip + return err; + } + + // Map feature to property name + const auto propertyName = [&] + { + const auto tempName = mapFeatureNameToPropertyName(feature->name); + + if (tempName != feature->name) + { + if (!m_propertyToFeature.count(tempName)) + { + m_propertyToFeature.emplace(tempName, feature->name); + return tempName; + } + } + + return std::string(feature->name); + }(); + + // uManager callback + CPropertyAction *uManagerCallback = new CPropertyAction(this, &AlliedVisionCamera::onProperty); + + // Vimba callback + auto vmbCallback = [](VmbHandle_t handle, const char *name, void *userContext) + { + (void)handle; + AlliedVisionCamera *camera = reinterpret_cast(userContext); + const auto propertyName = camera->mapFeatureNameToPropertyName(name); + auto err = camera->UpdateProperty(propertyName.c_str()); + if (err != VmbErrorSuccess) + { + camera->LOG_ERROR(err, "Property: " + propertyName + " update failed"); + } + }; + + // Register VMB callback for given feature + err = m_sdk->VmbFeatureInvalidationRegister_t(m_handle, feature->name, vmbCallback, this); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while registering invalidation callback for " + std::string(feature->name)); + return err; + } + + switch (feature->featureDataType) + { + case VmbFeatureDataInt: + { + err = CreateIntegerProperty(propertyName.c_str(), 0, false, uManagerCallback); + break; + } + case VmbFeatureDataBool: + { + err = CreateStringProperty(propertyName.c_str(), g_False, false, uManagerCallback); + AddAllowedValue(propertyName.c_str(), g_False); + AddAllowedValue(propertyName.c_str(), g_True); + break; + } + case VmbFeatureDataCommand: + { + err = CreateStringProperty(propertyName.c_str(), g_Command, false, uManagerCallback); + AddAllowedValue(propertyName.c_str(), g_Command); + AddAllowedValue(propertyName.c_str(), g_Execute); + break; } case VmbFeatureDataEnum: - case VmbFeatureDataString: { - err = CreateStringProperty(propertyName.c_str(), "", false, - uManagerCallback); - break; + case VmbFeatureDataString: + { + err = CreateStringProperty(propertyName.c_str(), "", false, uManagerCallback); + break; } - case VmbFeatureDataFloat: { - err = CreateFloatProperty(propertyName.c_str(), 0.0, false, - uManagerCallback); - break; + case VmbFeatureDataFloat: + { + err = CreateFloatProperty(propertyName.c_str(), 0.0, false, uManagerCallback); + break; } case VmbFeatureDataUnknown: case VmbFeatureDataRaw: case VmbFeatureDataNone: default: - // nothing - break; - } + // nothing + break; + } - if (err != VmbErrorSuccess) { - LOG_ERROR(err, - "Error while creating property " + std::string(feature->name)); - } + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while creating property " + std::string(feature->name)); + } - return err; + return err; } -const unsigned char* AlliedVisionCamera::GetImageBuffer() { - return reinterpret_cast(m_buffer[0]); +const unsigned char *AlliedVisionCamera::GetImageBuffer() +{ + return reinterpret_cast(m_buffer[0]); } -unsigned AlliedVisionCamera::GetImageWidth() const { - std::string value{}; - auto ret = getFeatureValue(g_Width, value); - if (ret != VmbErrorSuccess) { - LOG_ERROR(ret, "Error while getting image width!"); - return 0; - } +unsigned AlliedVisionCamera::GetImageWidth() const +{ + std::string value{}; + auto ret = getFeatureValue(g_Width, value); + if (ret != VmbErrorSuccess) + { + LOG_ERROR(ret, "Error while getting image width!"); + return 0; + } - return atoi(value.c_str()); + return atoi(value.c_str()); } -unsigned AlliedVisionCamera::GetImageHeight() const { - std::string value{}; - auto ret = getFeatureValue(g_Height, value); - if (ret != VmbErrorSuccess) { - LOG_ERROR(ret, "Error while getting image height!"); - return 0; - } +unsigned AlliedVisionCamera::GetImageHeight() const +{ + std::string value{}; + auto ret = getFeatureValue(g_Height, value); + if (ret != VmbErrorSuccess) + { + LOG_ERROR(ret, "Error while getting image height!"); + return 0; + } - return atoi(value.c_str()); + return atoi(value.c_str()); } -unsigned AlliedVisionCamera::GetImageBytesPerPixel() const { - return m_currentPixelFormat.getBytesPerPixel(); +unsigned AlliedVisionCamera::GetImageBytesPerPixel() const +{ + return m_currentPixelFormat.getBytesPerPixel(); } -long AlliedVisionCamera::GetImageBufferSize() const { return m_bufferSize; } +long AlliedVisionCamera::GetImageBufferSize() const +{ + return m_bufferSize; +} -unsigned AlliedVisionCamera::GetBitDepth() const { - return m_currentPixelFormat.getBitDepth(); +unsigned AlliedVisionCamera::GetBitDepth() const +{ + return m_currentPixelFormat.getBitDepth(); } -unsigned AlliedVisionCamera::GetNumberOfComponents() const { - return m_currentPixelFormat.getNumberOfComponents(); +unsigned AlliedVisionCamera::GetNumberOfComponents() const +{ + return m_currentPixelFormat.getNumberOfComponents(); } -int AlliedVisionCamera::GetBinning() const { - // Binning not supported. We support BinningVertical/Horizontal - return 1; +int AlliedVisionCamera::GetBinning() const +{ + // Binning not supported. We support BinningVertical/Horizontal + return 1; } -int AlliedVisionCamera::SetBinning(int binSize) { - // Binning not supported. We support BinningVertical/Horizontal - return DEVICE_ERR; +int AlliedVisionCamera::SetBinning(int binSize) +{ + // Binning not supported. We support BinningVertical/Horizontal + return DEVICE_ERR; } -double AlliedVisionCamera::GetExposure() const { - std::string value{}; - auto ret = getFeatureValue(m_exposureFeatureName.c_str(), value); - if (ret != VmbErrorSuccess) { - LOG_ERROR(ret, "Error while getting exposure!"); - return 0; - } +double AlliedVisionCamera::GetExposure() const +{ + std::string value{}; + auto ret = getFeatureValue(m_exposureFeatureName.c_str(), value); + if (ret != VmbErrorSuccess) + { + LOG_ERROR(ret, "Error while getting exposure!"); + return 0; + } - return std::stod(value) / MS_TO_US; + return std::stod(value) / MS_TO_US; } -void AlliedVisionCamera::SetExposure(double exp_ms) { - SetProperty(m_exposureFeatureName.c_str(), CDeviceUtils::ConvertToString(exp_ms * MS_TO_US)); - GetCoreCallback()->OnExposureChanged(this, exp_ms); +void AlliedVisionCamera::SetExposure(double exp_ms) +{ + SetProperty(m_exposureFeatureName.c_str(), CDeviceUtils::ConvertToString(exp_ms * MS_TO_US)); + GetCoreCallback()->OnExposureChanged(this, exp_ms); } -int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, - unsigned ySize) { - auto width = GetImageWidth(); - auto height = GetImageHeight(); - VmbError_t err = VmbErrorSuccess; +int AlliedVisionCamera::SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) +{ + auto width = GetImageWidth(); + auto height = GetImageHeight(); + VmbError_t err = VmbErrorSuccess; - std::function setOffsetXProperty = [this](long x) { - auto err = SetProperty(g_OffsetX, CDeviceUtils::ConvertToString(x)); - if (err) { - LOG_ERROR(err, "Error while ROI Offset X!"); + std::function setOffsetXProperty = [this](long x) + { + auto err = SetProperty(g_OffsetX, CDeviceUtils::ConvertToString(x)); + if (err) + { + LOG_ERROR(err, "Error while ROI Offset X!"); + } + return err; + }; + std::function setOffsetYProperty = [this](long y) + { + auto err = SetProperty(g_OffsetY, CDeviceUtils::ConvertToString(y)); + if (err) + { + LOG_ERROR(err, "Error while ROI Offset Y!"); + } + return err; + }; + std::function setWidthProperty = [this](long xSize) + { + auto err = SetProperty(g_Width, CDeviceUtils::ConvertToString(xSize)); + if (err) + { + LOG_ERROR(err, "Error while ROI X!"); + } + return err; + }; + std::function setHeightProperty = [this](long ySize) + { + auto err = SetProperty(g_Height, CDeviceUtils::ConvertToString(ySize)); + if (err) + { + LOG_ERROR(err, "Error while ROI Y!"); + } + return err; + }; + + if (xSize > width) + { + err = setOffsetXProperty(x) || setWidthProperty(xSize); } - return err; - }; - std::function setOffsetYProperty = [this](long y) { - auto err = SetProperty(g_OffsetY, CDeviceUtils::ConvertToString(y)); - if (err) { - LOG_ERROR(err, "Error while ROI Offset Y!"); + else + { + err = setWidthProperty(xSize) || setOffsetXProperty(x); } - return err; - }; - std::function setWidthProperty = [this](long xSize) { - auto err = SetProperty(g_Width, CDeviceUtils::ConvertToString(xSize)); - if (err) { - LOG_ERROR(err, "Error while ROI X!"); + + if (ySize > height) + { + err = setOffsetYProperty(y) || setHeightProperty(ySize); } - return err; - }; - std::function setHeightProperty = [this](long ySize) { - auto err = SetProperty(g_Height, CDeviceUtils::ConvertToString(ySize)); - if (err) { - LOG_ERROR(err, "Error while ROI Y!"); + else + { + err = setHeightProperty(ySize) || setOffsetYProperty(y); } - return err; - }; - - if (xSize > width) { - err = setOffsetXProperty(x) || setWidthProperty(xSize); - } else { - err = setWidthProperty(xSize) || setOffsetXProperty(x); - } - if (ySize > height) { - err = setOffsetYProperty(y) || setHeightProperty(ySize); - } else { - err = setHeightProperty(ySize) || setOffsetYProperty(y); - } - - if (err != VmbErrorSuccess) { - return err; - } + if (err != VmbErrorSuccess) + { + return err; + } - return resizeImageBuffer(); + return resizeImageBuffer(); } -int AlliedVisionCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, - unsigned& ySize) { - std::map fields = { - {g_OffsetX, x}, {g_OffsetY, y}, {g_Width, xSize}, {g_Height, ySize}}; +int AlliedVisionCamera::GetROI(unsigned &x, unsigned &y, unsigned &xSize, unsigned &ySize) +{ + std::map fields = { { g_OffsetX, x }, { g_OffsetY, y }, { g_Width, xSize }, { g_Height, ySize } }; - VmbError_t err = VmbErrorSuccess; - for (auto& field : fields) { - std::string value{}; - err = getFeatureValue(field.first, value); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while getting ROI!"); - break; + VmbError_t err = VmbErrorSuccess; + for (auto &field : fields) + { + std::string value{}; + err = getFeatureValue(field.first, value); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while getting ROI!"); + break; + } + field.second = atoi(value.data()); } - field.second = atoi(value.data()); - } - return err; + return err; } -int AlliedVisionCamera::ClearROI() { - std::string maxWidth, maxHeight; - VmbError_t err = getFeatureValue(g_WidthMax, maxWidth) | - getFeatureValue(g_HeightMax, maxHeight); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while clearing ROI!"); - return err; - } +int AlliedVisionCamera::ClearROI() +{ + std::string maxWidth, maxHeight; + VmbError_t err = getFeatureValue(g_WidthMax, maxWidth) | getFeatureValue(g_HeightMax, maxHeight); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while clearing ROI!"); + return err; + } - // Keep the order of the fields - std::vector> fields = { - {g_OffsetX, "0"}, - {g_OffsetY, "0"}, - {g_Width, maxWidth}, - {g_Height, maxHeight}}; + // Keep the order of the fields + std::vector> fields = { + { g_OffsetX, "0" }, { g_OffsetY, "0" }, { g_Width, maxWidth }, { g_Height, maxHeight } + }; - for (auto& field : fields) { - err = setFeatureValue(field.first, field.second); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while clearing ROI!"); - break; + for (auto &field : fields) + { + err = setFeatureValue(field.first, field.second); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while clearing ROI!"); + break; + } } - } - return resizeImageBuffer(); + return resizeImageBuffer(); } -int AlliedVisionCamera::IsExposureSequenceable(bool& isSequenceable) const { - // TODO implement - return VmbErrorSuccess; +int AlliedVisionCamera::IsExposureSequenceable(bool &isSequenceable) const +{ + // TODO implement + return VmbErrorSuccess; } -void AlliedVisionCamera::GetName(char* name) const { - CDeviceUtils::CopyLimitedString(name, m_cameraName.c_str()); +void AlliedVisionCamera::GetName(char *name) const +{ + CDeviceUtils::CopyLimitedString(name, m_cameraName.c_str()); +} + +bool AlliedVisionCamera::IsCapturing() +{ + return m_isAcquisitionRunning; } -bool AlliedVisionCamera::IsCapturing() { return m_isAcquisitionRunning; } - -int AlliedVisionCamera::onProperty(MM::PropertyBase* pProp, - MM::ActionType eAct) { - //Set locale to current system locale - const auto oldLocale = std::setlocale(LC_ALL, ""); - - const auto res = [&] { - // Init - VmbError_t err = VmbErrorSuccess; - - auto pChildProperty = dynamic_cast(pProp); - if (pChildProperty == nullptr) { - err = VmbErrorBadParameter; - LOG_ERROR(err, "Could not get Property from PropertyBase object"); - return err; - } - - const auto propertyName = pProp->GetName(); - - // Check property mapping - auto const featureName = mapPropertyNameToFeatureName(propertyName.c_str()); - - // Get Feature Info and Access Mode - VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}; - err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), - &featureInfo, sizeof(featureInfo)) | - m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, - &wMode); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting info or access query!"); - return err; - } - - const bool readOnly = (rMode && !wMode); - const bool featureAvailable = (rMode || wMode); - - // Get values - std::string propertyValue{}, featureValue{}; - pProp->Get(propertyValue); - - // Handle property value change - switch (eAct) { - case MM::ActionType::BeforeGet: //!< Update property from feature - - // Update feature range - if (featureAvailable) - { - err = setAllowedValues(&featureInfo, propertyName.c_str()); - } - // Feature not available -> clear value and range - else { - switch (pProp->GetType()) { - case MM::Float: - case MM::Integer: - err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); - pProp->Set("0"); - break; - case MM::String: - ClearAllowedValues(propertyName.c_str()); - pProp->Set(""); - break; - default: - // feature type not supported - break; - } - } - - if (rMode) { - err = - getFeatureValue(&featureInfo, featureName.c_str(), featureValue); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting feature value " + featureName); - return err; - } - - // Update property - if (propertyValue != featureValue) { - pProp->Set(featureValue.c_str()); - err = GetCoreCallback()->OnPropertyChanged( - this, propertyName.c_str(), featureValue.c_str()); - if (propertyName == MM::g_Keyword_PixelType) { - handlePixelFormatChange(featureValue); - } - - if (VmbErrorSuccess != err) { - LOG_ERROR(err, - "Error while calling OnPropertyChanged callback for " + - featureName); - return err; - } - } - } - - // Set property to readonly (grey out in GUI) if it is readonly or unavailable - pChildProperty->SetReadOnly(readOnly || !featureAvailable); - - break; - case MM::ActionType::AfterSet: //!< Update feature from property - err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); - if (err == VmbErrorInvalidValue) { - // Update limits first to have latest min and max - err = setAllowedValues(&featureInfo, propertyName.c_str()); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while setting allowed values for feature " + - featureName); - return err; - } - - // Adjust value - double min{}, max{}; - err = GetPropertyLowerLimit(propertyName.c_str(), min) | - GetPropertyUpperLimit(propertyName.c_str(), max); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting limits for " + propertyName); - return err; - } - std::string adjustedValue = - adjustValue(featureInfo, min, max, std::stod(propertyValue)); - err = - setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); - } - - if (propertyName == MM::g_Keyword_PixelType) { - handlePixelFormatChange(propertyValue); - } - break; - default: - // nothing - break; - } - - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while updating property " + propertyName); - } - - - return err; - }(); - - std::setlocale(LC_ALL, oldLocale); - - return res; +int AlliedVisionCamera::onProperty(MM::PropertyBase *pProp, MM::ActionType eAct) +{ + // Set locale to current system locale + const auto oldLocale = std::setlocale(LC_ALL, ""); + + const auto res = [&] + { + // Init + VmbError_t err = VmbErrorSuccess; + + auto pChildProperty = dynamic_cast(pProp); + if (pChildProperty == nullptr) + { + err = VmbErrorBadParameter; + LOG_ERROR(err, "Could not get Property from PropertyBase object"); + return err; + } + + const auto propertyName = pProp->GetName(); + + // Check property mapping + auto const featureName = mapPropertyNameToFeatureName(propertyName.c_str()); + + // Get Feature Info and Access Mode + VmbFeatureInfo_t featureInfo; + bool rMode{}, wMode{}; + err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), &featureInfo, sizeof(featureInfo)) | + m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, &wMode); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while getting info or access query!"); + return err; + } + + const bool readOnly = (rMode && !wMode); + const bool featureAvailable = (rMode || wMode); + + // Get values + std::string propertyValue{}, featureValue{}; + pProp->Get(propertyValue); + + // Handle property value change + switch (eAct) + { + case MM::ActionType::BeforeGet: //!< Update property from feature + + // Update feature range + if (featureAvailable) + { + err = setAllowedValues(&featureInfo, propertyName.c_str()); + } + // Feature not available -> clear value and range + else + { + switch (pProp->GetType()) + { + case MM::Float: + case MM::Integer: + err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); + pProp->Set("0"); + break; + case MM::String: + ClearAllowedValues(propertyName.c_str()); + pProp->Set(""); + break; + default: + // feature type not supported + break; + } + } + + if (rMode) + { + err = getFeatureValue(&featureInfo, featureName.c_str(), featureValue); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while getting feature value " + featureName); + return err; + } + + // Update property + if (propertyValue != featureValue) + { + pProp->Set(featureValue.c_str()); + err = GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), featureValue.c_str()); + if (propertyName == MM::g_Keyword_PixelType) + { + handlePixelFormatChange(featureValue); + } + + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while calling OnPropertyChanged callback for " + featureName); + return err; + } + } + } + + // Set property to readonly (grey out in GUI) if it is readonly or unavailable + pChildProperty->SetReadOnly(readOnly || !featureAvailable); + + break; + case MM::ActionType::AfterSet: //!< Update feature from property + err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); + if (err == VmbErrorInvalidValue) + { + // Update limits first to have latest min and max + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while setting allowed values for feature " + featureName); + return err; + } + + // Adjust value + double min{}, max{}; + err = GetPropertyLowerLimit(propertyName.c_str(), min) | GetPropertyUpperLimit(propertyName.c_str(), max); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while getting limits for " + propertyName); + return err; + } + std::string adjustedValue = adjustValue(featureInfo, min, max, std::stod(propertyValue)); + err = setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); + } + + if (propertyName == MM::g_Keyword_PixelType) + { + handlePixelFormatChange(propertyValue); + } + break; + default: + // nothing + break; + } + + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while updating property " + propertyName); + } + + return err; + }(); + + std::setlocale(LC_ALL, oldLocale); + + return res; } -void AlliedVisionCamera::handlePixelFormatChange(const std::string& pixelType) { - m_currentPixelFormat.setPixelType(pixelType); +void AlliedVisionCamera::handlePixelFormatChange(const std::string &pixelType) +{ + m_currentPixelFormat.setPixelType(pixelType); } -VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t* featureInfo, - const char* featureName, - std::string& value) const { - VmbError_t err = VmbErrorSuccess; - switch (featureInfo->featureDataType) { - case VmbFeatureDataBool: { - VmbBool_t out; - err = m_sdk->VmbFeatureBoolGet_t(m_handle, featureName, &out); - if (err != VmbErrorSuccess) { +VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t *featureInfo, const char *featureName, std::string &value) const +{ + VmbError_t err = VmbErrorSuccess; + switch (featureInfo->featureDataType) + { + case VmbFeatureDataBool: + { + VmbBool_t out; + err = m_sdk->VmbFeatureBoolGet_t(m_handle, featureName, &out); + if (err != VmbErrorSuccess) + { + break; + } + value = (out ? g_True : g_False); break; - } - value = (out ? g_True : g_False); - break; - } - case VmbFeatureDataEnum: { - const char* out = nullptr; - err = m_sdk->VmbFeatureEnumGet_t(m_handle, featureName, &out); - if (err != VmbErrorSuccess) { + } + case VmbFeatureDataEnum: + { + const char *out = nullptr; + err = m_sdk->VmbFeatureEnumGet_t(m_handle, featureName, &out); + if (err != VmbErrorSuccess) + { + break; + } + value = std::string(out); break; - } - value = std::string(out); - break; - } - case VmbFeatureDataFloat: { - double out; - err = m_sdk->VmbFeatureFloatGet_t(m_handle, featureName, &out); - if (err != VmbErrorSuccess) { + } + case VmbFeatureDataFloat: + { + double out; + err = m_sdk->VmbFeatureFloatGet_t(m_handle, featureName, &out); + if (err != VmbErrorSuccess) + { + break; + } + value = std::to_string(out); break; - } - value = std::to_string(out); - break; - } - case VmbFeatureDataInt: { - VmbInt64_t out; - err = m_sdk->VmbFeatureIntGet_t(m_handle, featureName, &out); - if (err != VmbErrorSuccess) { + } + case VmbFeatureDataInt: + { + VmbInt64_t out; + err = m_sdk->VmbFeatureIntGet_t(m_handle, featureName, &out); + if (err != VmbErrorSuccess) + { + break; + } + value = std::to_string(out); break; - } - value = std::to_string(out); - break; - } - case VmbFeatureDataString: { - VmbUint32_t size = 0; - err = m_sdk->VmbFeatureStringGet_t(m_handle, featureName, nullptr, 0, - &size); - if (VmbErrorSuccess == err && size > 0) { - std::shared_ptr buff = std::shared_ptr(new char[size]); - err = m_sdk->VmbFeatureStringGet_t(m_handle, featureName, buff.get(), - size, &size); - if (err != VmbErrorSuccess) { - break; + } + case VmbFeatureDataString: + { + VmbUint32_t size = 0; + err = m_sdk->VmbFeatureStringGet_t(m_handle, featureName, nullptr, 0, &size); + if (VmbErrorSuccess == err && size > 0) + { + std::shared_ptr buff = std::shared_ptr(new char[size]); + err = m_sdk->VmbFeatureStringGet_t(m_handle, featureName, buff.get(), size, &size); + if (err != VmbErrorSuccess) + { + break; + } + value = std::string(buff.get()); } - value = std::string(buff.get()); - } - break; + break; } case VmbFeatureDataCommand: - value = std::string(g_Command); - break; + value = std::string(g_Command); + break; case VmbFeatureDataUnknown: case VmbFeatureDataRaw: case VmbFeatureDataNone: default: - // nothing - break; - } + // nothing + break; + } - if (VmbErrorSuccess != err) { - LOG_ERROR(err, - "Error while getting feature value " + std::string(featureName)); - } + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while getting feature value " + std::string(featureName)); + } - return err; + return err; } -VmbError_t AlliedVisionCamera::getFeatureValue(const char* featureName, - std::string& value) const { - VmbFeatureInfo_t featureInfo; - VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( - m_handle, featureName, &featureInfo, sizeof(featureInfo)); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, - "Error while getting feature value " + std::string(featureName)); - return err; - } +VmbError_t AlliedVisionCamera::getFeatureValue(const char *featureName, std::string &value) const +{ + VmbFeatureInfo_t featureInfo; + VmbError_t err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName, &featureInfo, sizeof(featureInfo)); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while getting feature value " + std::string(featureName)); + return err; + } - return getFeatureValue(&featureInfo, featureName, value); + return getFeatureValue(&featureInfo, featureName, value); } -VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t* featureInfo, - const char* featureName, - std::string& value) { - VmbError_t err = VmbErrorSuccess; - std::stringstream ss(value); - bool isDone = false; - VmbUint32_t maxLen = 0; - - switch (featureInfo->featureDataType) { - case VmbFeatureDataBool: { - VmbBool_t out = (value == g_True ? true : false); - err = m_sdk->VmbFeatureBoolSet_t(m_handle, featureName, out); - break; - } - case VmbFeatureDataEnum: { - err = m_sdk->VmbFeatureEnumSet_t(m_handle, featureName, value.c_str()); - break; - } - case VmbFeatureDataFloat: { - double out; - ss >> out; - err = m_sdk->VmbFeatureFloatSet_t(m_handle, featureName, out); - break; - } - case VmbFeatureDataInt: { - VmbInt64_t out; - ss >> out; - err = m_sdk->VmbFeatureIntSet_t(m_handle, featureName, out); - break; - } - case VmbFeatureDataString: { - err = m_sdk->VmbFeatureStringMaxlengthQuery_t(m_handle, featureName, - &maxLen); - if (err != VmbErrorSuccess) { +VmbError_t AlliedVisionCamera::setFeatureValue(VmbFeatureInfo_t *featureInfo, const char *featureName, std::string &value) +{ + VmbError_t err = VmbErrorSuccess; + std::stringstream ss(value); + bool isDone = false; + VmbUint32_t maxLen = 0; + + switch (featureInfo->featureDataType) + { + case VmbFeatureDataBool: + { + VmbBool_t out = (value == g_True ? true : false); + err = m_sdk->VmbFeatureBoolSet_t(m_handle, featureName, out); break; - } - if (value.size() > maxLen) { - err = VmbErrorInvalidValue; - } else { - err = - m_sdk->VmbFeatureStringSet_t(m_handle, featureName, value.c_str()); - } - break; } - case VmbFeatureDataCommand: - if (value == g_Execute) { - const auto propertyName = mapFeatureNameToPropertyName(featureName); - if (!propertyName.empty()) { - err = m_sdk->VmbFeatureCommandRun_t(m_handle, featureName); - if (err != VmbErrorSuccess) { + case VmbFeatureDataEnum: + { + err = m_sdk->VmbFeatureEnumSet_t(m_handle, featureName, value.c_str()); + break; + } + case VmbFeatureDataFloat: + { + double out; + ss >> out; + err = m_sdk->VmbFeatureFloatSet_t(m_handle, featureName, out); + break; + } + case VmbFeatureDataInt: + { + VmbInt64_t out; + ss >> out; + err = m_sdk->VmbFeatureIntSet_t(m_handle, featureName, out); + break; + } + case VmbFeatureDataString: + { + err = m_sdk->VmbFeatureStringMaxlengthQuery_t(m_handle, featureName, &maxLen); + if (err != VmbErrorSuccess) + { break; - } - while (!isDone) { - err = m_sdk->VmbFeatureCommandIsDone_t(m_handle, featureName, - &isDone); - if (err != VmbErrorSuccess) { - break; + } + if (value.size() > maxLen) + { + err = VmbErrorInvalidValue; + } + else + { + err = m_sdk->VmbFeatureStringSet_t(m_handle, featureName, value.c_str()); + } + break; + } + case VmbFeatureDataCommand: + if (value == g_Execute) + { + const auto propertyName = mapFeatureNameToPropertyName(featureName); + if (!propertyName.empty()) + { + err = m_sdk->VmbFeatureCommandRun_t(m_handle, featureName); + if (err != VmbErrorSuccess) + { + break; + } + while (!isDone) + { + err = m_sdk->VmbFeatureCommandIsDone_t(m_handle, featureName, &isDone); + if (err != VmbErrorSuccess) + { + break; + } + } + // Set back property to "Command" + err = SetProperty(propertyName.c_str(), g_Command); + GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), g_Command); + if (err != VmbErrorSuccess) + { + break; + } + } + else + { + err = VmbErrorInvalidValue; } - } - // Set back property to "Command" - err = SetProperty(propertyName.c_str(), g_Command); - GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), - g_Command); - if (err != VmbErrorSuccess) { - break; - } - } else { - err = VmbErrorInvalidValue; } - } - break; + break; case VmbFeatureDataUnknown: case VmbFeatureDataRaw: case VmbFeatureDataNone: default: - // nothing - break; - } + // nothing + break; + } - if (VmbErrorSuccess != err) { - LOG_ERROR(err, - "Error while setting feature value " + std::string(featureName)); - } + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while setting feature value " + std::string(featureName)); + } - return err; + return err; } -VmbError_t AlliedVisionCamera::setFeatureValue(const char* featureName, - std::string& value) { - VmbFeatureInfo_t featureInfo; - VmbError_t err = m_sdk->VmbFeatureInfoQuery_t( - m_handle, featureName, &featureInfo, sizeof(featureInfo)); - if (VmbErrorSuccess != err) { - LOG_ERROR(err, - "Error while setting feature value " + std::string(featureName)); - return err; - } +VmbError_t AlliedVisionCamera::setFeatureValue(const char *featureName, std::string &value) +{ + VmbFeatureInfo_t featureInfo; + VmbError_t err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName, &featureInfo, sizeof(featureInfo)); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while setting feature value " + std::string(featureName)); + return err; + } - return setFeatureValue(&featureInfo, featureName, value); + return setFeatureValue(&featureInfo, featureName, value); } -std::string AlliedVisionCamera::mapFeatureNameToPropertyName( - const char* feature) const { - - auto search = m_featureToProperty.find(feature); - if (search != m_featureToProperty.end()) { - return search->second; - } +std::string AlliedVisionCamera::mapFeatureNameToPropertyName(const char *feature) const +{ - return feature; + auto search = m_featureToProperty.find(feature); + if (search != m_featureToProperty.end()) + { + return search->second; + } + + return feature; } -std::string AlliedVisionCamera::mapPropertyNameToFeatureName(const char* property) const { +std::string AlliedVisionCamera::mapPropertyNameToFeatureName(const char *property) const +{ auto search = m_propertyToFeature.find(property); - if (search != m_propertyToFeature.end()) { + if (search != m_propertyToFeature.end()) + { return search->second; } return property; } -std::string AlliedVisionCamera::adjustValue(VmbFeatureInfo_t& featureInfo, - double min, double max, - double propertyValue) const { - VmbError_t err = VmbErrorSuccess; - double step = 1.0; - VmbInt64_t stepI = 1; - bool isIncremental = true; - switch (featureInfo.featureDataType) { +std::string AlliedVisionCamera::adjustValue(VmbFeatureInfo_t &featureInfo, double min, double max, double propertyValue) const +{ + VmbError_t err = VmbErrorSuccess; + double step = 1.0; + VmbInt64_t stepI = 1; + bool isIncremental = true; + switch (featureInfo.featureDataType) + { case VmbFeatureDataFloat: - err = m_sdk->VmbFeatureFloatIncrementQuery_t(m_handle, featureInfo.name, - &isIncremental, &step); - break; + err = m_sdk->VmbFeatureFloatIncrementQuery_t(m_handle, featureInfo.name, &isIncremental, &step); + break; case VmbFeatureDataInt: - err = m_sdk->VmbFeatureIntIncrementQuery_t(m_handle, featureInfo.name, - &stepI); - step = static_cast(stepI); - break; + err = m_sdk->VmbFeatureIntIncrementQuery_t(m_handle, featureInfo.name, &stepI); + step = static_cast(stepI); + break; default: - // nothing - break; - } - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting increment query for feature " + - std::string(featureInfo.name)); - return std::to_string(propertyValue); - } - - if (!isIncremental) { - return std::to_string(propertyValue); - } - - if (propertyValue > max) { - return std::to_string(max); - } - if (propertyValue < min) { - return std::to_string(min); - } - - VmbInt64_t factor = static_cast((propertyValue - min) / step); - double prev = min + factor * step; - double next = min + (factor + 1) * step; - - double prevDiff = abs(propertyValue - prev); - double nextDiff = abs(next - propertyValue); - - return (nextDiff < prevDiff) ? std::to_string(next) : std::to_string(prev); + // nothing + break; + } + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while getting increment query for feature " + std::string(featureInfo.name)); + return std::to_string(propertyValue); + } + + if (!isIncremental) + { + return std::to_string(propertyValue); + } + + if (propertyValue > max) + { + return std::to_string(max); + } + if (propertyValue < min) + { + return std::to_string(min); + } + + VmbInt64_t factor = static_cast((propertyValue - min) / step); + double prev = min + factor * step; + double next = min + (factor + 1) * step; + + double prevDiff = abs(propertyValue - prev); + double nextDiff = abs(next - propertyValue); + + return (nextDiff < prevDiff) ? std::to_string(next) : std::to_string(prev); } -VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t* feature, - const char* propertyName) { - if (feature == nullptr || propertyName == nullptr) { - return VmbErrorInvalidValue; - } - - VmbError_t err = VmbErrorSuccess; - - switch (feature->featureDataType) { - case VmbFeatureDataBool: { - // Already set in creation, but maybe reset when become unavailable - if (GetNumberOfPropertyValues(propertyName) == 0) { - AddAllowedValue(propertyName, g_False); - AddAllowedValue(propertyName, g_True); - } - break; - } - case VmbFeatureDataCommand: { - // Already set in creation, but maybe reset when become unavailable - if (GetNumberOfPropertyValues(propertyName) == 0) { - AddAllowedValue(propertyName, g_Command); - AddAllowedValue(propertyName, g_Execute); - } - break; - } - case VmbFeatureDataFloat: { - double min, max; - err = m_sdk->VmbFeatureFloatRangeQuery_t(m_handle, feature->name, &min, - &max); - if (VmbErrorSuccess != err || min == max) { +VmbError_t AlliedVisionCamera::setAllowedValues(const VmbFeatureInfo_t *feature, const char *propertyName) +{ + if (feature == nullptr || propertyName == nullptr) + { + return VmbErrorInvalidValue; + } + + VmbError_t err = VmbErrorSuccess; + + switch (feature->featureDataType) + { + case VmbFeatureDataBool: + { + // Already set in creation, but maybe reset when become unavailable + if (GetNumberOfPropertyValues(propertyName) == 0) + { + AddAllowedValue(propertyName, g_False); + AddAllowedValue(propertyName, g_True); + } break; - } - - err = SetPropertyLimits(propertyName, min, max); - break; - } - case VmbFeatureDataEnum: { - std::array values; - std::vector strValues; - VmbUint32_t valuesNum = 0; - err = m_sdk->VmbFeatureEnumRangeQuery_t( - m_handle, feature->name, values.data(), MM::MaxStrLength, &valuesNum); - if (VmbErrorSuccess != err) { + } + case VmbFeatureDataCommand: + { + // Already set in creation, but maybe reset when become unavailable + if (GetNumberOfPropertyValues(propertyName) == 0) + { + AddAllowedValue(propertyName, g_Command); + AddAllowedValue(propertyName, g_Execute); + } break; - } - - for (size_t i = 0; i < valuesNum; i++) { - strValues.push_back(values[i]); - } - err = SetAllowedValues(propertyName, strValues); + } + case VmbFeatureDataFloat: + { + double min, max; + err = m_sdk->VmbFeatureFloatRangeQuery_t(m_handle, feature->name, &min, &max); + if (VmbErrorSuccess != err || min == max) + { + break; + } - break; + err = SetPropertyLimits(propertyName, min, max); + break; } - case VmbFeatureDataInt: { - VmbInt64_t min, max; - std::vector strValues; + case VmbFeatureDataEnum: + { + std::array values; + std::vector strValues; + VmbUint32_t valuesNum = 0; + err = m_sdk->VmbFeatureEnumRangeQuery_t(m_handle, feature->name, values.data(), MM::MaxStrLength, &valuesNum); + if (VmbErrorSuccess != err) + { + break; + } + + for (size_t i = 0; i < valuesNum; i++) + { + strValues.push_back(values[i]); + } + err = SetAllowedValues(propertyName, strValues); - err = - m_sdk->VmbFeatureIntRangeQuery_t(m_handle, feature->name, &min, &max); - if (VmbErrorSuccess != err || min == max) { break; - } + } + case VmbFeatureDataInt: + { + VmbInt64_t min, max; + std::vector strValues; - err = SetPropertyLimits(propertyName, static_cast(min), - static_cast(max)); - break; + err = m_sdk->VmbFeatureIntRangeQuery_t(m_handle, feature->name, &min, &max); + if (VmbErrorSuccess != err || min == max) + { + break; + } + + err = SetPropertyLimits(propertyName, static_cast(min), static_cast(max)); + break; } case VmbFeatureDataString: case VmbFeatureDataRaw: case VmbFeatureDataNone: default: - // nothing - break; - } + // nothing + break; + } - if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while setting allowed values for feature " + - std::string(feature->name)); - } + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while setting allowed values for feature " + std::string(feature->name)); + } - return err; + return err; } -int AlliedVisionCamera::SnapImage() { - if (IsCapturing()) { - return DEVICE_CAMERA_BUSY_ACQUIRING; - } - resizeImageBuffer(); +int AlliedVisionCamera::SnapImage() +{ + if (IsCapturing()) + { + return DEVICE_CAMERA_BUSY_ACQUIRING; + } + resizeImageBuffer(); - VmbFrame_t frame; - frame.buffer = m_buffer[0]; - frame.bufferSize = m_payloadSize; + VmbFrame_t frame; + frame.buffer = m_buffer[0]; + frame.bufferSize = m_payloadSize; - VmbError_t err = VmbErrorSuccess; - err = m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while snapping image!"); - (void)StopSequenceAcquisition(); - return err; - } - err = m_sdk->VmbCaptureStart_t(m_handle); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while snapping image!"); - (void)StopSequenceAcquisition(); - return err; - } - err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while snapping image!"); - (void)StopSequenceAcquisition(); - return err; - } - err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while snapping image!"); - (void)StopSequenceAcquisition(); - return err; - } - m_isAcquisitionRunning = true; - err = m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while snapping image!"); - (void)StopSequenceAcquisition(); - return err; - } + VmbError_t err = VmbErrorSuccess; + err = m_sdk->VmbFrameAnnounce_t(m_handle, &frame, sizeof(VmbFrame_t)); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + err = m_sdk->VmbCaptureStart_t(m_handle); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &frame, nullptr); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + m_isAcquisitionRunning = true; + err = m_sdk->VmbCaptureFrameWait_t(m_handle, &frame, 3000); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while snapping image!"); + (void)StopSequenceAcquisition(); + return err; + } + + err = transformImage(&frame); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while snapping image - cannot transform image!"); + (void)StopSequenceAcquisition(); + return err; + } - err = transformImage(&frame); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while snapping image - cannot transform image!"); (void)StopSequenceAcquisition(); return err; - } - - (void)StopSequenceAcquisition(); - return err; } -int AlliedVisionCamera::StartSequenceAcquisition(long numImages, - double interval_ms, - bool stopOnOverflow) { - (void)stopOnOverflow; - (void)interval_ms; - (void)numImages; - - if (IsCapturing()) { - return DEVICE_CAMERA_BUSY_ACQUIRING; - } +int AlliedVisionCamera::StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow) +{ + (void)stopOnOverflow; + (void)interval_ms; + (void)numImages; - int err = GetCoreCallback()->PrepareForAcq(this); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error while preparing for acquisition!"); - return err; - } + if (IsCapturing()) + { + return DEVICE_CAMERA_BUSY_ACQUIRING; + } - err = resizeImageBuffer(); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error during frame praparation for continous acquisition!"); - return err; - } - - for (size_t i = 0; i < MAX_FRAMES; i++) { - m_frames[i].buffer = m_buffer[i]; - m_frames[i].bufferSize = m_payloadSize; - m_frames[i].context[0] = this; //(i); //(frame->context[0]) - ->insertFrame(frame); - }; + int err = GetCoreCallback()->PrepareForAcq(this); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error while preparing for acquisition!"); + return err; + } - err = - m_sdk->VmbFrameAnnounce_t(m_handle, &(m_frames[i]), sizeof(VmbFrame_t)); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, - "Error during frame praparation for continous acquisition!"); - return err; + err = resizeImageBuffer(); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during frame praparation for continous acquisition!"); + return err; } - err = - m_sdk->VmbCaptureFrameQueue_t(m_handle, &(m_frames[i]), frameCallback); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, - "Error during frame praparation for continous acquisition!"); - return err; + for (size_t i = 0; i < MAX_FRAMES; i++) + { + m_frames[i].buffer = m_buffer[i]; + m_frames[i].bufferSize = m_payloadSize; + m_frames[i].context[0] = this; //(i); //(frame->context[0])->insertFrame(frame); + }; + + err = m_sdk->VmbFrameAnnounce_t(m_handle, &(m_frames[i]), sizeof(VmbFrame_t)); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during frame praparation for continous acquisition!"); + return err; + } + + err = m_sdk->VmbCaptureFrameQueue_t(m_handle, &(m_frames[i]), frameCallback); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during frame praparation for continous acquisition!"); + return err; + } } - } - err = m_sdk->VmbCaptureStart_t(m_handle); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error during frame praparation for continous acquisition!"); - return err; - } + err = m_sdk->VmbCaptureStart_t(m_handle); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during frame praparation for continous acquisition!"); + return err; + } - err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); - m_isAcquisitionRunning = true; + err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStart); + m_isAcquisitionRunning = true; - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error during start acquisition!"); - return err; - } + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during start acquisition!"); + return err; + } - return UpdateStatus(); + return UpdateStatus(); } -int AlliedVisionCamera::StartSequenceAcquisition(double interval_ms) { - return StartSequenceAcquisition(LONG_MAX, interval_ms, true); +int AlliedVisionCamera::StartSequenceAcquisition(double interval_ms) +{ + return StartSequenceAcquisition(LONG_MAX, interval_ms, true); } -int AlliedVisionCamera::StopSequenceAcquisition() { - // This method shall never return any error - VmbError_t err = VmbErrorSuccess; - if (IsCapturing()) { - err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStop); - m_isAcquisitionRunning = false; - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error during stopping acquisition command!"); - return err; - } - } - - err = m_sdk->VmbCaptureEnd_t(m_handle); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error during stop acquisition!"); - return err; - } - - err = m_sdk->VmbCaptureQueueFlush_t(m_handle); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error during stop acquisition!"); - return err; - } +int AlliedVisionCamera::StopSequenceAcquisition() +{ + // This method shall never return any error + VmbError_t err = VmbErrorSuccess; + if (IsCapturing()) + { + err = m_sdk->VmbFeatureCommandRun_t(m_handle, g_AcquisitionStop); + m_isAcquisitionRunning = false; + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during stopping acquisition command!"); + return err; + } + } - err = m_sdk->VmbFrameRevokeAll_t(m_handle); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Error during stop acquisition!"); - return err; - } + err = m_sdk->VmbCaptureEnd_t(m_handle); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during stop acquisition!"); + return err; + } - return UpdateStatus(); -} + err = m_sdk->VmbCaptureQueueFlush_t(m_handle); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during stop acquisition!"); + return err; + } -VmbError_t AlliedVisionCamera::transformImage(VmbFrame_t* frame) { - VmbError_t err = VmbErrorSuccess; - VmbImage src{}, dest{}; - VmbTransformInfo info{}; - std::shared_ptr tempBuff = - std::shared_ptr(new VmbUint8_t[m_bufferSize]); - auto srcBuff = reinterpret_cast(frame->buffer); + err = m_sdk->VmbFrameRevokeAll_t(m_handle); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Error during stop acquisition!"); + return err; + } - src.Data = srcBuff; - src.Size = sizeof(src); + return UpdateStatus(); +} - dest.Data = tempBuff.get(); - dest.Size = sizeof(dest); +VmbError_t AlliedVisionCamera::transformImage(VmbFrame_t *frame) +{ + VmbError_t err = VmbErrorSuccess; + VmbImage src{}, dest{}; + VmbTransformInfo info{}; + std::shared_ptr tempBuff = std::shared_ptr(new VmbUint8_t[m_bufferSize]); + auto srcBuff = reinterpret_cast(frame->buffer); + + src.Data = srcBuff; + src.Size = sizeof(src); + + dest.Data = tempBuff.get(); + dest.Size = sizeof(dest); + + err = m_sdk->VmbSetImageInfoFromPixelFormat_t(frame->pixelFormat, frame->width, frame->height, &src); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Cannot set image info from pixel format!"); + return err; + } - err = m_sdk->VmbSetImageInfoFromPixelFormat_t( - frame->pixelFormat, frame->width, frame->height, &src); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Cannot set image info from pixel format!"); - return err; - } + err = m_sdk->VmbSetImageInfoFromPixelFormat_t(m_currentPixelFormat.getVmbFormat(), frame->width, frame->height, &dest); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Cannot set image info from pixel format!"); + return err; + } - err = m_sdk->VmbSetImageInfoFromPixelFormat_t( - m_currentPixelFormat.getVmbFormat(), frame->width, frame->height, &dest); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Cannot set image info from pixel format!"); - return err; - } + err = m_sdk->VmbImageTransform_t(&src, &dest, &info, 0); + if (err != VmbErrorSuccess) + { + LOG_ERROR(err, "Cannot transform image!"); + return err; + } - err = m_sdk->VmbImageTransform_t(&src, &dest, &info, 0); - if (err != VmbErrorSuccess) { - LOG_ERROR(err, "Cannot transform image!"); + memcpy(srcBuff, tempBuff.get(), m_bufferSize); return err; - } - - memcpy(srcBuff, tempBuff.get(), m_bufferSize); - return err; } -void AlliedVisionCamera::insertFrame(VmbFrame_t* frame) { - if (frame != nullptr && frame->receiveStatus == VmbFrameStatusComplete) { - VmbError_t err = VmbErrorSuccess; - - err = transformImage(frame); - if (err != VmbErrorSuccess) { - // Error logged in transformImage - return; - } +void AlliedVisionCamera::insertFrame(VmbFrame_t *frame) +{ + if (frame != nullptr && frame->receiveStatus == VmbFrameStatusComplete) + { + VmbError_t err = VmbErrorSuccess; + + err = transformImage(frame); + if (err != VmbErrorSuccess) + { + // Error logged in transformImage + return; + } - // TODO implement metadata - Metadata md; - md.put("Camera", m_cameraName); + // TODO implement metadata + Metadata md; + md.put("Camera", m_cameraName); - VmbUint8_t* buffer = reinterpret_cast(frame->buffer); - err = GetCoreCallback()->InsertImage( - this, buffer, GetImageWidth(), GetImageHeight(), - m_currentPixelFormat.getBytesPerPixel(), - m_currentPixelFormat.getNumberOfComponents(), md.Serialize().c_str()); + VmbUint8_t *buffer = reinterpret_cast(frame->buffer); + err = GetCoreCallback()->InsertImage(this, buffer, GetImageWidth(), GetImageHeight(), m_currentPixelFormat.getBytesPerPixel(), + m_currentPixelFormat.getNumberOfComponents(), md.Serialize().c_str()); - if (err == DEVICE_BUFFER_OVERFLOW) { - GetCoreCallback()->ClearImageBuffer(this); - err = GetCoreCallback()->InsertImage( - this, buffer, GetImageWidth(), GetImageHeight(), - m_currentPixelFormat.getBytesPerPixel(), - m_currentPixelFormat.getNumberOfComponents(), md.Serialize().c_str(), - false); - } + if (err == DEVICE_BUFFER_OVERFLOW) + { + GetCoreCallback()->ClearImageBuffer(this); + err = GetCoreCallback()->InsertImage(this, buffer, GetImageWidth(), GetImageHeight(), m_currentPixelFormat.getBytesPerPixel(), + m_currentPixelFormat.getNumberOfComponents(), md.Serialize().c_str(), false); + } - if (IsCapturing()) { - m_sdk->VmbCaptureFrameQueue_t( - m_handle, frame, - [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, - VmbFrame_t* frame) { - (void)cameraHandle; - (void)streamHandle; - reinterpret_cast(frame->context[0]) - ->insertFrame(frame); - }); + if (IsCapturing()) + { + m_sdk->VmbCaptureFrameQueue_t(m_handle, frame, + [](const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, VmbFrame_t *frame) + { + (void)cameraHandle; + (void)streamHandle; + reinterpret_cast(frame->context[0])->insertFrame(frame); + }); + } } - } } \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index d34e5ffca..017042cd5 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -28,34 +28,33 @@ #include "DeviceBase.h" #include "Loader/LibLoader.h" - /////////////////////////////////////////////////////////////////////////////// // STATIC FEATURE NAMES (FROM VIMBA) /////////////////////////////////////////////////////////////////////////////// -static constexpr const char* g_PixelFormatFeature = "PixelFormat"; -static constexpr const char* g_ExposureFeature = "ExposureTime"; -static constexpr const char* g_ExposureAbsFeature = "ExposureTimeAbs"; -static constexpr const char* g_BinningHorizontalFeature = "BinningHorizontal"; -static constexpr const char* g_BinningVerticalFeature = "BinningVertical"; -static constexpr const char* g_Width = "Width"; -static constexpr const char* g_Height = "Height"; -static constexpr const char* g_OffsetX = "OffsetX"; -static constexpr const char* g_OffsetY = "OffsetY"; -static constexpr const char* g_WidthMax = "WidthMax"; -static constexpr const char* g_HeightMax = "HeightMax"; +static constexpr const char *g_PixelFormatFeature = "PixelFormat"; +static constexpr const char *g_ExposureFeature = "ExposureTime"; +static constexpr const char *g_ExposureAbsFeature = "ExposureTimeAbs"; +static constexpr const char *g_BinningHorizontalFeature = "BinningHorizontal"; +static constexpr const char *g_BinningVerticalFeature = "BinningVertical"; +static constexpr const char *g_Width = "Width"; +static constexpr const char *g_Height = "Height"; +static constexpr const char *g_OffsetX = "OffsetX"; +static constexpr const char *g_OffsetY = "OffsetY"; +static constexpr const char *g_WidthMax = "WidthMax"; +static constexpr const char *g_HeightMax = "HeightMax"; /////////////////////////////////////////////////////////////////////////////// // STATIC VARIABLES /////////////////////////////////////////////////////////////////////////////// -static constexpr const char* g_True = "True"; -static constexpr const char* g_False = "False"; -static constexpr const char* g_Execute = "Execute"; -static constexpr const char* g_Command = "Command"; -static constexpr const char* g_ChunkCategory = "ChunkDataControl"; -static constexpr const char* g_EventCategory = "EventControl"; -static constexpr const char* g_AcquisitionStart = "AcquisitionStart"; -static constexpr const char* g_AcquisitionStop = "AcquisitionStop"; -static constexpr const char* g_AcqusitionStatus = "AcqusitionStatus"; +static constexpr const char *g_True = "True"; +static constexpr const char *g_False = "False"; +static constexpr const char *g_Execute = "Execute"; +static constexpr const char *g_Command = "Command"; +static constexpr const char *g_ChunkCategory = "ChunkDataControl"; +static constexpr const char *g_EventCategory = "EventControl"; +static constexpr const char *g_AcquisitionStart = "AcquisitionStart"; +static constexpr const char *g_AcquisitionStop = "AcquisitionStop"; +static constexpr const char *g_AcqusitionStatus = "AcqusitionStatus"; static constexpr const double MS_TO_US = 1000.0; @@ -69,378 +68,402 @@ static constexpr const double MS_TO_US = 1000.0; * 16bit GRAY [no. component = 1] * 32bit RGB [no. component = 4] */ -class PixelFormatConverter { - /////////////////////////////////////////////////////////////////////////////// - // PUBLIC - /////////////////////////////////////////////////////////////////////////////// - public: - /** - * @brief Constructor - */ - PixelFormatConverter() - : m_pixelType{"Mono8"}, - m_components{1}, - m_bitDepth{8}, - m_bytesPerPixel{1}, - m_isMono{true}, - m_vmbFormat{VmbPixelFormatMono8} {} - - /** - * @brief Destructor - */ - virtual ~PixelFormatConverter() = default; - - /** - * @brief Setter for pixel type - * @param[in] type New pixel type (string value from VMB) - */ - void setPixelType(const std::string& type) { - m_pixelType = type; - updateFields(); - } - - /** - * @brief Getter to check if given pixel type is Mono or Color - * @return True if Mono, otherwise false - */ - bool isMono() const { return m_isMono; } - - /** - * @brief Getter for number of components for given pixel type - * uManager supports only 1 or 4 components - * @return Number of components - */ - unsigned getNumberOfComponents() const { return m_components; } - - /** - * @brief Getter for bit depth for given pixel type - * @return Number of bits for one pixel - */ - unsigned getBitDepth() const { return m_bitDepth; } - - /** - * @brief Getter for bytes per pixel - * @return Bytes per pixel - */ - unsigned getBytesPerPixel() const { return m_bytesPerPixel; } - - /** - * @brief Getter of destination VmbPixelFormat that fits into the one, that - * uManager supports. In general uManager supports three pixelFormats: - * 1. Mono8 - * 2. Mono16 - * 3. RGB32 - * These types fits into following VmbPixelTypes: - * 1. VmbPixelFormatMono8 - * 2. VmbPixelFormatMono16 - * 3. VmbPixelFormatBgra8 - * @return Destination VmbPixelFormat - */ - VmbPixelFormatType getVmbFormat() const { return m_vmbFormat; } - - /////////////////////////////////////////////////////////////////////////////// - // PRIVATE - /////////////////////////////////////////////////////////////////////////////// - private: - /** - * @brief Helper method to update info if given format is Mono or Color - */ - void updateMono() { - std::regex re("Mono(\\d+)"); - std::smatch m; - m_isMono = std::regex_search(m_pixelType, m, re); - } - - /** - * @brief Helper method to update number of components for given pixel type - * uManager supports only 1 or 4 components - */ - void updateNumberOfComponents() { m_components = m_isMono ? 1 : 4; } - - /** - * @brief Helper method to update bit depth for given pixel type - */ - void updateBitDepth() { - m_bitDepth = 8; - if (isMono()) { - std::regex re("Mono(\\d+)"); - std::smatch m; - std::regex_search(m_pixelType, m, re); - if (m.size() > 0) { - if (std::atoi(m[1].str().c_str()) == 16) { - // We do transformation to Mono16 only for Mono16, otherwise - // it will always be Mono8 - m_bitDepth = 16; - } else { - m_bitDepth = 8; +class PixelFormatConverter +{ + /////////////////////////////////////////////////////////////////////////////// + // PUBLIC + /////////////////////////////////////////////////////////////////////////////// +public: + /** + * @brief Constructor + */ + PixelFormatConverter() : + m_pixelType{ "Mono8" }, + m_components{ 1 }, + m_bitDepth{ 8 }, + m_bytesPerPixel{ 1 }, + m_isMono{ true }, + m_vmbFormat{ VmbPixelFormatMono8 } + { + } + + /** + * @brief Destructor + */ + virtual ~PixelFormatConverter() = default; + + /** + * @brief Setter for pixel type + * @param[in] type New pixel type (string value from VMB) + */ + void setPixelType(const std::string &type) + { + m_pixelType = type; + updateFields(); + } + + /** + * @brief Getter to check if given pixel type is Mono or Color + * @return True if Mono, otherwise false + */ + bool isMono() const + { + return m_isMono; + } + + /** + * @brief Getter for number of components for given pixel type + * uManager supports only 1 or 4 components + * @return Number of components + */ + unsigned getNumberOfComponents() const + { + return m_components; + } + + /** + * @brief Getter for bit depth for given pixel type + * @return Number of bits for one pixel + */ + unsigned getBitDepth() const + { + return m_bitDepth; + } + + /** + * @brief Getter for bytes per pixel + * @return Bytes per pixel + */ + unsigned getBytesPerPixel() const + { + return m_bytesPerPixel; + } + + /** + * @brief Getter of destination VmbPixelFormat that fits into the one, that + * uManager supports. In general uManager supports three pixelFormats: + * 1. Mono8 + * 2. Mono16 + * 3. RGB32 + * These types fits into following VmbPixelTypes: + * 1. VmbPixelFormatMono8 + * 2. VmbPixelFormatMono16 + * 3. VmbPixelFormatBgra8 + * @return Destination VmbPixelFormat + */ + VmbPixelFormatType getVmbFormat() const + { + return m_vmbFormat; + } + + /////////////////////////////////////////////////////////////////////////////// + // PRIVATE + /////////////////////////////////////////////////////////////////////////////// +private: + /** + * @brief Helper method to update info if given format is Mono or Color + */ + void updateMono() + { + std::regex re("Mono(\\d+)"); + std::smatch m; + m_isMono = std::regex_search(m_pixelType, m, re); + } + + /** + * @brief Helper method to update number of components for given pixel type + * uManager supports only 1 or 4 components + */ + void updateNumberOfComponents() + { + m_components = m_isMono ? 1 : 4; + } + + /** + * @brief Helper method to update bit depth for given pixel type + */ + void updateBitDepth() + { + m_bitDepth = 8; + if (isMono()) + { + std::regex re("Mono(\\d+)"); + std::smatch m; + std::regex_search(m_pixelType, m, re); + if (m.size() > 0) + { + if (std::atoi(m[1].str().c_str()) == 16) + { + // We do transformation to Mono16 only for Mono16, otherwise + // it will always be Mono8 + m_bitDepth = 16; + } + else + { + m_bitDepth = 8; + } + } + else + { + // ERROR + } + } + else + { + m_bitDepth = 32; + } + } + + /** + * @brief Helper method to update bytes per pixel + */ + void updateBytesPerPixel() + { + m_bytesPerPixel = m_bitDepth / 8; + } + + /** + * @brief Helper method to update destination VmbPixelFormatType + */ + void updateVmbFormat() + { + switch (m_bytesPerPixel) + { + case 1: + m_vmbFormat = VmbPixelFormatMono8; + break; + case 2: + m_vmbFormat = VmbPixelFormatMono16; + break; + case 4: + m_vmbFormat = VmbPixelFormatBgra8; // TODO check if this is a valid format + break; + default: + break; } - } else { - // ERROR - } - } else { - m_bitDepth = 32; } - } - - /** - * @brief Helper method to update bytes per pixel - */ - void updateBytesPerPixel() { m_bytesPerPixel = m_bitDepth / 8; } - - /** - * @brief Helper method to update destination VmbPixelFormatType - */ - void updateVmbFormat() { - switch (m_bytesPerPixel) { - case 1: - m_vmbFormat = VmbPixelFormatMono8; - break; - case 2: - m_vmbFormat = VmbPixelFormatMono16; - break; - case 4: - m_vmbFormat = - VmbPixelFormatBgra8; // TODO check if this is a valid format - break; - default: - break; + + /** + * @brief Helper method to update all required fields + */ + void updateFields() + { + // [IMPORTANT] Keep order of the calls + updateMono(); + updateNumberOfComponents(); + updateBitDepth(); + updateBytesPerPixel(); + updateVmbFormat(); } - } - - /** - * @brief Helper method to update all required fields - */ - void updateFields() { - // [IMPORTANT] Keep order of the calls - updateMono(); - updateNumberOfComponents(); - updateBitDepth(); - updateBytesPerPixel(); - updateVmbFormat(); - } - - std::string m_pixelType; //!< Pixel type (in string) - value from VMB - unsigned m_components; //!< Number of components - unsigned m_bitDepth; //, - AlliedVisionCamera> { - /////////////////////////////////////////////////////////////////////////////// - // PUBLIC - /////////////////////////////////////////////////////////////////////////////// - public: - /** - * @brief Contructor of Allied Vision Camera - * @param[in] deviceName Device name - */ - AlliedVisionCamera(const char* deviceName); - /** - * @brief Allied Vision Camera destructor - */ - virtual ~AlliedVisionCamera(); - - /////////////////////////////////////////////////////////////////////////////// - // uMANAGER API METHODS - /////////////////////////////////////////////////////////////////////////////// - int Initialize() override; - int Shutdown() override; - const unsigned char* GetImageBuffer() override; - unsigned GetImageWidth() const override; - unsigned GetImageHeight() const override; - unsigned GetImageBytesPerPixel() const override; - int SnapImage() override; - long GetImageBufferSize() const override; - unsigned GetBitDepth() const override; - int GetBinning() const override; - int SetBinning(int binSize) override; - void SetExposure(double exp_ms) override; - double GetExposure() const override; - int SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) override; - int GetROI(unsigned& x, unsigned& y, unsigned& xSize, - unsigned& ySize) override; - int ClearROI() override; - int IsExposureSequenceable(bool& isSequenceable) const override; - void GetName(char* name) const override; - int StartSequenceAcquisition(double interval_ms) override; - int StartSequenceAcquisition(long numImages, double interval_ms, - bool stopOnOverflow) override; - int StopSequenceAcquisition() override; - bool IsCapturing() override; - unsigned GetNumberOfComponents() const override; - - /////////////////////////////////////////////////////////////////////////////// - // uMANAGER CALLBACKS - /////////////////////////////////////////////////////////////////////////////// - int onProperty(MM::PropertyBase* pProp, - MM::ActionType eAct); //!<< General property callback - - /////////////////////////////////////////////////////////////////////////////// - // PRIVATE - /////////////////////////////////////////////////////////////////////////////// - private: - // Static variables - static constexpr const VmbUint8_t MAX_FRAMES = - 7; //!<< Max frame number in the buffer - - /** - * @brief Helper method to handle change of pixel type - * @param[in] pixelType New pixel type (as string) - */ - void handlePixelFormatChange(const std::string& pixelType); - - /** - * @brief Resize all buffers for image frames - * @return VmbError_t - */ - VmbError_t resizeImageBuffer(); - - /** - * @brief Setup uManager properties from Vimba features - * @return VmbError_t - */ - VmbError_t setupProperties(); - - /** - * @brief Helper method to create single uManager property from Vimba feature - * @param[in] feature Pointer to the Vimba feature - * @return VmbError_t - */ - VmbError_t createPropertyFromFeature(const VmbFeatureInfo_t* feature); - - /** - * @brief Helper method to set allowed values for given property, based on - * its feature type - * @param[in] feature Vimba feature name - * @param[in] propertyName uManager propery name (if differs from - * feature name) - * @return - */ - VmbError_t setAllowedValues(const VmbFeatureInfo_t* feature, - const char* propertyName); - - /** - * @brief Insert ready frame to the uManager - * @param[in] frame Pointer to the frame - */ - void insertFrame(VmbFrame_t* frame); - - /** - * @brief Method to get feature value, based on its type. Feature value is - * always a string type. - * @param[in] featureInfo Feature info object - * @param[in] featureName Feature name - * @param[out] value Value of feature, read from device - * @return VmbError_t - */ - VmbError_t getFeatureValue(VmbFeatureInfo_t* featureInfo, - const char* featureName, std::string& value) const; - /** - * @brief Method to get feature value, based on its type. Feature value is - * always a string type. - * @param[in] featureName Feature name - * @param[out] value Value of feature, read from device - * @return VmbError_t - */ - VmbError_t getFeatureValue(const char* featureName, std::string& value) const; - - /** - * @brief Method to set a feature value, bases on its type. Feature value is - * always a string type. - * @param[in] featureInfo Feature info object - * @param[in] featureName Feature name - * @param[in] value Value of feature to be set - * @return VmbError_t - */ - VmbError_t setFeatureValue(VmbFeatureInfo_t* featureInfo, - const char* featureName, std::string& value); - - /** - * @brief Method to set a feature value, bases on its type. Feature value is - * always a string type. - * @param[in] featureName Feature name - * @param[in] value Value of feature to be set - * @return VmbError_t - */ - VmbError_t setFeatureValue(const char* featureName, std::string& value); - - /** - * @brief Helper method to map feature name into property name of uManager - * @param[in] feature Vimba Feature name - * @return uManager property name - */ - std::string mapFeatureNameToPropertyName(const char* feature) const; - - /** - * @brief Helper method to map uManager property in Vimba feature or features - * name - * @param[in] property uManager property name - * @param featureNames Vimba feature or features name - */ - std::string mapPropertyNameToFeatureName(const char* property) const; - - /** - * @brief In case trying to set invalid value, adjust it to the closest with - * inceremntal step - - * @param[in] step Incremental step - - * @return Adjusted value resresented as a string - */ - - /** - * @brief In case trying to set invalid value, adjust it to the closest with - * inceremntal step - * @param[in] featureInfo Feature info object - * @param[in] min Minimum for given property - * @param[in] max Maximum for given property - * @param[in] propertyValue Value that was tried to be set - * @return Adjusted value resresented as a string - */ - std::string adjustValue(VmbFeatureInfo_t& featureInfo, double min, double max, - double propertyValue) const; - - /** - * @brief Internal method to transform image to the destination format that - * uManager supports (see \ref PixelFormatConverter) and replaces input frame - * with output (transformed) frame - * @param[in] frame Frame with image to transform from and into - * @return Error in case of failure - */ - VmbError_t transformImage(VmbFrame_t* frame); - - /////////////////////////////////////////////////////////////////////////////// - // MEMBERS - /////////////////////////////////////////////////////////////////////////////// - std::shared_ptr m_sdk; // m_frames; // - m_buffer; // - m_featureToProperty; //!< Map of features name into uManager properties - std::unordered_map - m_propertyToFeature; //!< Map of uManager properties into Vimba features - +class AlliedVisionCamera : public AlliedVisionDeviceBase, AlliedVisionCamera> +{ + /////////////////////////////////////////////////////////////////////////////// + // PUBLIC + /////////////////////////////////////////////////////////////////////////////// +public: + /** + * @brief Contructor of Allied Vision Camera + * @param[in] deviceName Device name + */ + AlliedVisionCamera(const char *deviceName); + /** + * @brief Allied Vision Camera destructor + */ + virtual ~AlliedVisionCamera(); + + /////////////////////////////////////////////////////////////////////////////// + // uMANAGER API METHODS + /////////////////////////////////////////////////////////////////////////////// + int Initialize() override; + int Shutdown() override; + const unsigned char *GetImageBuffer() override; + unsigned GetImageWidth() const override; + unsigned GetImageHeight() const override; + unsigned GetImageBytesPerPixel() const override; + int SnapImage() override; + long GetImageBufferSize() const override; + unsigned GetBitDepth() const override; + int GetBinning() const override; + int SetBinning(int binSize) override; + void SetExposure(double exp_ms) override; + double GetExposure() const override; + int SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) override; + int GetROI(unsigned &x, unsigned &y, unsigned &xSize, unsigned &ySize) override; + int ClearROI() override; + int IsExposureSequenceable(bool &isSequenceable) const override; + void GetName(char *name) const override; + int StartSequenceAcquisition(double interval_ms) override; + int StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow) override; + int StopSequenceAcquisition() override; + bool IsCapturing() override; + unsigned GetNumberOfComponents() const override; + + /////////////////////////////////////////////////////////////////////////////// + // uMANAGER CALLBACKS + /////////////////////////////////////////////////////////////////////////////// + int onProperty(MM::PropertyBase *pProp, + MM::ActionType eAct); //!<< General property callback + + /////////////////////////////////////////////////////////////////////////////// + // PRIVATE + /////////////////////////////////////////////////////////////////////////////// +private: + // Static variables + static constexpr const VmbUint8_t MAX_FRAMES = 7; //!<< Max frame number in the buffer + + /** + * @brief Helper method to handle change of pixel type + * @param[in] pixelType New pixel type (as string) + */ + void handlePixelFormatChange(const std::string &pixelType); + + /** + * @brief Resize all buffers for image frames + * @return VmbError_t + */ + VmbError_t resizeImageBuffer(); + + /** + * @brief Setup uManager properties from Vimba features + * @return VmbError_t + */ + VmbError_t setupProperties(); + + /** + * @brief Helper method to create single uManager property from Vimba feature + * @param[in] feature Pointer to the Vimba feature + * @return VmbError_t + */ + VmbError_t createPropertyFromFeature(const VmbFeatureInfo_t *feature); + + /** + * @brief Helper method to set allowed values for given property, based on + * its feature type + * @param[in] feature Vimba feature name + * @param[in] propertyName uManager propery name (if differs from + * feature name) + * @return + */ + VmbError_t setAllowedValues(const VmbFeatureInfo_t *feature, const char *propertyName); + + /** + * @brief Insert ready frame to the uManager + * @param[in] frame Pointer to the frame + */ + void insertFrame(VmbFrame_t *frame); + + /** + * @brief Method to get feature value, based on its type. Feature value is + * always a string type. + * @param[in] featureInfo Feature info object + * @param[in] featureName Feature name + * @param[out] value Value of feature, read from device + * @return VmbError_t + */ + VmbError_t getFeatureValue(VmbFeatureInfo_t *featureInfo, const char *featureName, std::string &value) const; + /** + * @brief Method to get feature value, based on its type. Feature value is + * always a string type. + * @param[in] featureName Feature name + * @param[out] value Value of feature, read from device + * @return VmbError_t + */ + VmbError_t getFeatureValue(const char *featureName, std::string &value) const; + + /** + * @brief Method to set a feature value, bases on its type. Feature value is + * always a string type. + * @param[in] featureInfo Feature info object + * @param[in] featureName Feature name + * @param[in] value Value of feature to be set + * @return VmbError_t + */ + VmbError_t setFeatureValue(VmbFeatureInfo_t *featureInfo, const char *featureName, std::string &value); + + /** + * @brief Method to set a feature value, bases on its type. Feature value is + * always a string type. + * @param[in] featureName Feature name + * @param[in] value Value of feature to be set + * @return VmbError_t + */ + VmbError_t setFeatureValue(const char *featureName, std::string &value); + + /** + * @brief Helper method to map feature name into property name of uManager + * @param[in] feature Vimba Feature name + * @return uManager property name + */ + std::string mapFeatureNameToPropertyName(const char *feature) const; + + /** + * @brief Helper method to map uManager property in Vimba feature or features + * name + * @param[in] property uManager property name + * @param featureNames Vimba feature or features name + */ + std::string mapPropertyNameToFeatureName(const char *property) const; + + /** + * @brief In case trying to set invalid value, adjust it to the closest with + * inceremntal step + + * @param[in] step Incremental step + + * @return Adjusted value resresented as a string + */ + + /** + * @brief In case trying to set invalid value, adjust it to the closest with + * inceremntal step + * @param[in] featureInfo Feature info object + * @param[in] min Minimum for given property + * @param[in] max Maximum for given property + * @param[in] propertyValue Value that was tried to be set + * @return Adjusted value resresented as a string + */ + std::string adjustValue(VmbFeatureInfo_t &featureInfo, double min, double max, double propertyValue) const; + + /** + * @brief Internal method to transform image to the destination format that + * uManager supports (see \ref PixelFormatConverter) and replaces input frame + * with output (transformed) frame + * @param[in] frame Frame with image to transform from and into + * @return Error in case of failure + */ + VmbError_t transformImage(VmbFrame_t *frame); + + /////////////////////////////////////////////////////////////////////////////// + // MEMBERS + /////////////////////////////////////////////////////////////////////////////// + std::shared_ptr m_sdk; // m_frames; // m_buffer; // m_featureToProperty; //!< Map of features name into uManager properties + std::unordered_map m_propertyToFeature; //!< Map of uManager properties into Vimba features }; #endif diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.cpp index 64e692022..6e1430cb5 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.cpp @@ -1,3 +1 @@ #include "AlliedVisionDeviceBase.h" - - diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h index cccb06d13..642fa566e 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h @@ -27,71 +27,59 @@ /** * @brief Base class for Allied Vision devices */ -template -class AlliedVisionDeviceBase : public CDeviceBase { - /////////////////////////////////////////////////////////////////////////////// - // PUBLIC - /////////////////////////////////////////////////////////////////////////////// +template class AlliedVisionDeviceBase : public CDeviceBase +{ + /////////////////////////////////////////////////////////////////////////////// + // PUBLIC + /////////////////////////////////////////////////////////////////////////////// public: - /** - * @brief Constructor - */ - AlliedVisionDeviceBase() { - CDeviceBase::InitializeDefaultErrorMessages(); - setApiErrorMessages(); - }; + /** + * @brief Constructor + */ + AlliedVisionDeviceBase() + { + CDeviceBase::InitializeDefaultErrorMessages(); + setApiErrorMessages(); + }; - /** - * @brief Destructor - */ - virtual ~AlliedVisionDeviceBase() = default; + /** + * @brief Destructor + */ + virtual ~AlliedVisionDeviceBase() = default; - void logError(int error, std::string message, std::string function = "", - int line = 0) const { - std::string prefix = "[" + function + "():" + std::to_string(line) + "] "; - CDeviceBase::LogMessage(prefix + message); - CDeviceBase::LogMessageCode(error); - } + void logError(int error, std::string message, std::string function = "", int line = 0) const + { + std::string prefix = "[" + function + "():" + std::to_string(line) + "] "; + CDeviceBase::LogMessage(prefix + message); + CDeviceBase::LogMessageCode(error); + } - /////////////////////////////////////////////////////////////////////////////// - // PRIVATE - /////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////// + // PRIVATE + /////////////////////////////////////////////////////////////////////////////// private: - /** - * @brief Setup error messages for Vimba API - */ - void setApiErrorMessages() { - CDeviceBase::SetErrorText(VmbErrorApiNotStarted, - "Vimba X API not started"); - CDeviceBase::SetErrorText(VmbErrorNotFound, "Device cannot be found"); - CDeviceBase::SetErrorText(VmbErrorDeviceNotOpen, - "Device cannot be opened"); - CDeviceBase::SetErrorText(VmbErrorBadParameter, - "Invalid parameter passed to the function"); - CDeviceBase::SetErrorText(VmbErrorNotImplemented, - "Feature not implemented"); - CDeviceBase::SetErrorText(VmbErrorNotSupported, - "Feature not supported"); - CDeviceBase::SetErrorText(VmbErrorUnknown, "Unknown error"); - CDeviceBase::SetErrorText( - VmbErrorInvalidValue, - "The value is not valid: either out of bounds or not an " - "increment of the minimum"); - CDeviceBase::SetErrorText(VmbErrorBadHandle, - "Given device handle is not valid"); - CDeviceBase::SetErrorText( - VmbErrorInvalidAccess, - "Operation is invalid with the current access mode"); - CDeviceBase::SetErrorText(VmbErrorTimeout, "Timeout occured"); - CDeviceBase::SetErrorText(VmbErrorNotAvailable, - "Something is not available"); - CDeviceBase::SetErrorText(VmbErrorNotInitialized, - "Something is not initialized"); - CDeviceBase::SetErrorText(VmbErrorAlready, - "The operation has been already done"); - CDeviceBase::SetErrorText(VmbErrorFeaturesUnavailable, - "Feature is currently unavailable"); - } + /** + * @brief Setup error messages for Vimba API + */ + void setApiErrorMessages() + { + CDeviceBase::SetErrorText(VmbErrorApiNotStarted, "Vimba X API not started"); + CDeviceBase::SetErrorText(VmbErrorNotFound, "Device cannot be found"); + CDeviceBase::SetErrorText(VmbErrorDeviceNotOpen, "Device cannot be opened"); + CDeviceBase::SetErrorText(VmbErrorBadParameter, "Invalid parameter passed to the function"); + CDeviceBase::SetErrorText(VmbErrorNotImplemented, "Feature not implemented"); + CDeviceBase::SetErrorText(VmbErrorNotSupported, "Feature not supported"); + CDeviceBase::SetErrorText(VmbErrorUnknown, "Unknown error"); + CDeviceBase::SetErrorText(VmbErrorInvalidValue, "The value is not valid: either out of bounds or not an " + "increment of the minimum"); + CDeviceBase::SetErrorText(VmbErrorBadHandle, "Given device handle is not valid"); + CDeviceBase::SetErrorText(VmbErrorInvalidAccess, "Operation is invalid with the current access mode"); + CDeviceBase::SetErrorText(VmbErrorTimeout, "Timeout occured"); + CDeviceBase::SetErrorText(VmbErrorNotAvailable, "Something is not available"); + CDeviceBase::SetErrorText(VmbErrorNotInitialized, "Something is not initialized"); + CDeviceBase::SetErrorText(VmbErrorAlready, "The operation has been already done"); + CDeviceBase::SetErrorText(VmbErrorFeaturesUnavailable, "Feature is currently unavailable"); + } }; #endif diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp index 1400542d9..59276c8c6 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp @@ -20,55 +20,77 @@ #include "AlliedVisionCamera.h" -AlliedVisionHub::AlliedVisionHub() : m_sdk(std::make_shared()) {} +AlliedVisionHub::AlliedVisionHub() : + m_sdk(std::make_shared()) +{ +} -int AlliedVisionHub::DetectInstalledDevices() { - LogMessage("Detecting installed cameras..."); - VmbUint32_t camNum; - // Get the number of connected cameras first - VmbError_t err = m_sdk->VmbCamerasList_t(nullptr, 0, &camNum, 0); - if (VmbErrorSuccess == err) { - VmbCameraInfo_t *camInfo = new VmbCameraInfo_t[camNum]; +int AlliedVisionHub::DetectInstalledDevices() +{ + LogMessage("Detecting installed cameras..."); + VmbUint32_t camNum; + // Get the number of connected cameras first + VmbError_t err = m_sdk->VmbCamerasList_t(nullptr, 0, &camNum, 0); + if (VmbErrorSuccess == err) + { + VmbCameraInfo_t *camInfo = new VmbCameraInfo_t[camNum]; - // Get the cameras - err = m_sdk->VmbCamerasList_t(camInfo, camNum, &camNum, sizeof *camInfo); + // Get the cameras + err = m_sdk->VmbCamerasList_t(camInfo, camNum, &camNum, sizeof *camInfo); - if (err == VmbErrorSuccess) { - for (VmbUint32_t i = 0; i < camNum; ++i) { - if (camInfo[i].permittedAccess & VmbAccessModeFull) { - MM::Device *pDev = new AlliedVisionCamera(camInfo[i].cameraIdString); - AddInstalledDevice(pDev); + if (err == VmbErrorSuccess) + { + for (VmbUint32_t i = 0; i < camNum; ++i) + { + if (camInfo[i].permittedAccess & VmbAccessModeFull) + { + MM::Device *pDev = new AlliedVisionCamera(camInfo[i].cameraIdString); + AddInstalledDevice(pDev); + } + } } - } + + delete[] camInfo; + } + else + { + LOG_ERROR(err, "Cannot get installed devices!"); } - delete[] camInfo; - } else { - LOG_ERROR(err, "Cannot get installed devices!"); - } + return err; +} - return err; +int AlliedVisionHub::Initialize() +{ + LogMessage("Init HUB"); + if (m_sdk->isInitialized()) + { + return DEVICE_OK; + } + else + { + LOG_ERROR(VmbErrorApiNotStarted, "SDK not initialized!"); + return VmbErrorApiNotStarted; + } } -int AlliedVisionHub::Initialize() { - LogMessage("Init HUB"); - if (m_sdk->isInitialized()) { +int AlliedVisionHub::Shutdown() +{ + LogMessage("Shutting down HUB"); return DEVICE_OK; - } else { - LOG_ERROR(VmbErrorApiNotStarted, "SDK not initialized!"); - return VmbErrorApiNotStarted; - } } -int AlliedVisionHub::Shutdown() { - LogMessage("Shutting down HUB"); - return DEVICE_OK; +void AlliedVisionHub::GetName(char *name) const +{ + CDeviceUtils::CopyLimitedString(name, g_hubName); } -void AlliedVisionHub::GetName(char *name) const { - CDeviceUtils::CopyLimitedString(name, g_hubName); +bool AlliedVisionHub::Busy() +{ + return false; } -bool AlliedVisionHub::Busy() { return false; } - -std::shared_ptr &AlliedVisionHub::getSDK() { return m_sdk; } +std::shared_ptr &AlliedVisionHub::getSDK() +{ + return m_sdk; +} diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h index c0daf74cd..6ecc4a37a 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h @@ -32,42 +32,42 @@ static constexpr const char *g_hubName = "AlliedVisionHub"; /** * @brief Class that represents a HUB of supported devices */ -class AlliedVisionHub - : public AlliedVisionDeviceBase, AlliedVisionHub> { - /////////////////////////////////////////////////////////////////////////////// - // PUBLIC - /////////////////////////////////////////////////////////////////////////////// +class AlliedVisionHub : public AlliedVisionDeviceBase, AlliedVisionHub> +{ + /////////////////////////////////////////////////////////////////////////////// + // PUBLIC + /////////////////////////////////////////////////////////////////////////////// public: - /** - * @brief Contructor of a HUB - */ - AlliedVisionHub(); + /** + * @brief Contructor of a HUB + */ + AlliedVisionHub(); - /** - * @brief Destructor of a HUB - */ - virtual ~AlliedVisionHub() = default; + /** + * @brief Destructor of a HUB + */ + virtual ~AlliedVisionHub() = default; - /** - * @brief SDK getter - * @return Pointer to SDK - */ - std::shared_ptr &getSDK(); + /** + * @brief SDK getter + * @return Pointer to SDK + */ + std::shared_ptr &getSDK(); - /////////////////////////////////////////////////////////////////////////////// - // uMANAGER API METHODS - /////////////////////////////////////////////////////////////////////////////// - int DetectInstalledDevices() override; - int Initialize() override; - int Shutdown() override; - void GetName(char *name) const override; - bool Busy() override; + /////////////////////////////////////////////////////////////////////////////// + // uMANAGER API METHODS + /////////////////////////////////////////////////////////////////////////////// + int DetectInstalledDevices() override; + int Initialize() override; + int Shutdown() override; + void GetName(char *name) const override; + bool Busy() override; - /////////////////////////////////////////////////////////////////////////////// - // PRIVATE - /////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////// + // PRIVATE + /////////////////////////////////////////////////////////////////////////////// private: - std::shared_ptr m_sdk; // m_sdk; //(m_module)); - m_module = nullptr; - m_loaded = false; - m_libName = nullptr; - } +LibLoader::~LibLoader() +{ + if (m_loaded) + { + FreeModule(static_cast(m_module)); + m_module = nullptr; + m_loaded = false; + m_libName = nullptr; + } } -SymbolWrapper LibLoader::resolveFunction(const char *functionName, - bool &allResolved) const { - void *funPtr = nullptr; - if (allResolved) { - funPtr = GetProcAddress(static_cast(m_module), functionName); - allResolved = allResolved && (funPtr != nullptr); - } - return SymbolWrapper(funPtr); +SymbolWrapper LibLoader::resolveFunction(const char *functionName, bool &allResolved) const +{ + void *funPtr = nullptr; + if (allResolved) + { + funPtr = GetProcAddress(static_cast(m_module), functionName); + allResolved = allResolved && (funPtr != nullptr); + } + return SymbolWrapper(funPtr); } #else // nothing diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h index dcfdb78c7..675ff7230 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h +++ b/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h @@ -28,159 +28,159 @@ /** * @brief Wrapper for single Windows process */ -class SymbolWrapper { - /////////////////////////////////////////////////////////////////////////////// - // PUBLIC - /////////////////////////////////////////////////////////////////////////////// - public: - /** - * @brief Constructor of wrapper - * @param[in] funPtr Pointer to the resolved symbol - */ - explicit SymbolWrapper(void* funPtr) : m_funPtr(funPtr) {} - - /** - * @brief Operator () overload to call function - */ - template ::value>> - operator T*() const { - return reinterpret_cast(m_funPtr); - } - /////////////////////////////////////////////////////////////////////////////// - // PRIVATE - /////////////////////////////////////////////////////////////////////////////// - private: - void* m_funPtr; //::value>> operator T *() const + { + return reinterpret_cast(m_funPtr); + } + /////////////////////////////////////////////////////////////////////////////// + // PRIVATE + /////////////////////////////////////////////////////////////////////////////// +private: + void *m_funPtr; // Date: Thu, 14 Sep 2023 15:07:03 +0200 Subject: [PATCH 32/43] Added missing locale include --- DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index d736fc617..7d582e85b 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "AlliedVisionHub.h" #include "ModuleInterface.h" From 656266349582fd9a19b0d9bc9362b5817f037f3b Mon Sep 17 00:00:00 2001 From: Florian Klostermann Date: Thu, 14 Sep 2023 16:27:47 +0200 Subject: [PATCH 33/43] Run GVSPAdjustPacketSize after opening a GigE camera --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 23 ++++++++++++++++++- .../AlliedVisionCamera/AlliedVisionCamera.h | 3 +-- .../SDK/Loader/LibLoader.cpp | 1 + .../AlliedVisionCamera/SDK/Loader/LibLoader.h | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 7d582e85b..ae7815b37 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -21,10 +21,10 @@ #include "AlliedVisionCamera.h" #include +#include #include #include #include -#include #include "AlliedVisionHub.h" #include "ModuleInterface.h" @@ -34,6 +34,8 @@ // STATIC VALUES /////////////////////////////////////////////////////////////////////////////// +constexpr const char *ADJUST_PACKAGE_SIZE_COMMAND = "GVSPAdjustPacketSize"; + const std::unordered_map AlliedVisionCamera::m_featureToProperty = { { g_PixelFormatFeature, MM::g_Keyword_PixelType } }; @@ -117,6 +119,25 @@ int AlliedVisionCamera::Initialize() return err; } + // Try to execute custom command available to Allied Vision GigE Cameras to ensure the packet size is chosen well + VmbCameraInfo_t info; + err = m_sdk->VmbCameraInfoQuery_t(m_cameraName.c_str(), &info, sizeof(info)); + if (err == VmbErrorSuccess && info.streamCount > 0) + { + VmbHandle_t stream = info.streamHandles[0]; + if (m_sdk->VmbFeatureCommandRun_t(stream, ADJUST_PACKAGE_SIZE_COMMAND) == VmbErrorSuccess) + { + VmbBool_t isCommandDone = VmbBoolFalse; + do + { + if (m_sdk->VmbFeatureCommandIsDone_t(stream, ADJUST_PACKAGE_SIZE_COMMAND, &isCommandDone) != VmbErrorSuccess) + { + break; + } + } while (isCommandDone == VmbBoolFalse); + } + } + // Ignore errors from setting up properties (void)setupProperties(); return resizeImageBuffer(); diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 017042cd5..052ca0852 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -456,8 +456,7 @@ class AlliedVisionCamera : public AlliedVisionDeviceBase Date: Thu, 14 Sep 2023 17:27:02 +0200 Subject: [PATCH 34/43] Ip and mac address features are now displayed correctly --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 47 ++++++++++++++++++- .../AlliedVisionCamera/AlliedVisionCamera.h | 4 ++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index ae7815b37..6a8dd90ae 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -38,6 +38,19 @@ constexpr const char *ADJUST_PACKAGE_SIZE_COMMAND = "GVSPAdjustPacketSize"; const std::unordered_map AlliedVisionCamera::m_featureToProperty = { { g_PixelFormatFeature, MM::g_Keyword_PixelType } }; +const std::unordered_set AlliedVisionCamera::m_ipAddressFeatures = { + "MulticastIPAddress", + "GevCurrentSubnetMask", + "GevCurrentIPAddress", + "GevCurrentDefaultGateway", + "GevPersistentIPAddress", + "GevPersistentDefaultGateway", + "GevPersistentSubnetMask", +}; + +const std::unordered_set AlliedVisionCamera::m_macAddressFeatures = { + "GevMACAddress" +}; /////////////////////////////////////////////////////////////////////////////// // Exported MMDevice API @@ -289,6 +302,12 @@ VmbError_t AlliedVisionCamera::createPropertyFromFeature(const VmbFeatureInfo_t return err; } + if (m_ipAddressFeatures.count(feature->name) || m_macAddressFeatures.count(feature->name)) + { + err = CreateStringProperty(propertyName.c_str(), "", true, uManagerCallback); + return err; + } + switch (feature->featureDataType) { case VmbFeatureDataInt: @@ -586,6 +605,10 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase *pProp, MM::ActionType eAct) return err; } + if (m_ipAddressFeatures.count(featureName)) { + wMode = false; + } + const bool readOnly = (rMode && !wMode); const bool featureAvailable = (rMode || wMode); @@ -752,7 +775,29 @@ VmbError_t AlliedVisionCamera::getFeatureValue(VmbFeatureInfo_t *featureInfo, co { break; } - value = std::to_string(out); + if (m_ipAddressFeatures.count(featureName)) + { + std::stringstream ipAddressStream; + ipAddressStream << (0xFF & (out >> 24)) << "." << (0xFF & (out >> 16)) << "." << (0xFF & (out >> 8)) << "." << (0xFF & out); + + value = ipAddressStream.str(); + } + else if (m_macAddressFeatures.count(featureName)) + { + std::stringstream macAddressStream; + macAddressStream << std::hex + << std::setw(2) << std::setfill('0') << static_cast(0xFF & (out >> 40)) << ":" + << std::setw(2) << std::setfill('0') << static_cast(0xFF & (out >> 32)) << ":" + << std::setw(2) << std::setfill('0') << static_cast(0xFF & (out >> 24)) << ":" + << std::setw(2) << std::setfill('0') << static_cast(0xFF & (out >> 16)) << ":" + << std::setw(2) << std::setfill('0') << static_cast(0xFF & (out >> 8)) << ":" + << std::setw(2) << std::setfill('0') << static_cast(0xFF & out); + value = macAddressStream.str(); + } + else + { + value = std::to_string(out); + } break; } case VmbFeatureDataString: diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 052ca0852..2dd14f1c1 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "AlliedVisionDeviceBase.h" #include "DeviceBase.h" @@ -463,6 +464,9 @@ class AlliedVisionCamera : public AlliedVisionDeviceBase m_featureToProperty; //!< Map of features name into uManager properties std::unordered_map m_propertyToFeature; //!< Map of uManager properties into Vimba features + + static const std::unordered_set m_ipAddressFeatures; + static const std::unordered_set m_macAddressFeatures; }; #endif From 16037a21c81fc78578aa3a63f5ae3095aae890fe Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Thu, 14 Sep 2023 17:31:55 +0200 Subject: [PATCH 35/43] Fixed formatting --- DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 6a8dd90ae..cf3fc90fb 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -605,7 +605,8 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase *pProp, MM::ActionType eAct) return err; } - if (m_ipAddressFeatures.count(featureName)) { + if (m_ipAddressFeatures.count(featureName)) + { wMode = false; } From 40afa77caf6c0cf598779d389abfbb02a65deca0 Mon Sep 17 00:00:00 2001 From: Florian Klostermann Date: Thu, 14 Sep 2023 18:11:54 +0200 Subject: [PATCH 36/43] ignore return from SetPropertyLimits when disabling a feature --- DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index cf3fc90fb..52edeab0f 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -634,7 +634,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase *pProp, MM::ActionType eAct) { case MM::Float: case MM::Integer: - err = SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); + SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); pProp->Set("0"); break; case MM::String: From cfa656e57b4b35b42cf678b47ac9154568a3b4bd Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Fri, 15 Sep 2023 15:45:30 +0200 Subject: [PATCH 37/43] Revert: Before a feature is read or written the locale is set to the current user locale. Reverted chaning the locale. OnExposureChanged is now called every time the exposure feature changes. --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 216 +++++++++--------- 1 file changed, 106 insertions(+), 110 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 52edeab0f..279cdbe00 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -573,156 +573,152 @@ bool AlliedVisionCamera::IsCapturing() int AlliedVisionCamera::onProperty(MM::PropertyBase *pProp, MM::ActionType eAct) { - // Set locale to current system locale - const auto oldLocale = std::setlocale(LC_ALL, ""); + // Init + VmbError_t err = VmbErrorSuccess; - const auto res = [&] + auto pChildProperty = dynamic_cast(pProp); + if (pChildProperty == nullptr) { - // Init - VmbError_t err = VmbErrorSuccess; + err = VmbErrorBadParameter; + LOG_ERROR(err, "Could not get Property from PropertyBase object"); + return err; + } - auto pChildProperty = dynamic_cast(pProp); - if (pChildProperty == nullptr) - { - err = VmbErrorBadParameter; - LOG_ERROR(err, "Could not get Property from PropertyBase object"); - return err; - } + const auto propertyName = pProp->GetName(); - const auto propertyName = pProp->GetName(); + // Check property mapping + auto const featureName = mapPropertyNameToFeatureName(propertyName.c_str()); - // Check property mapping - auto const featureName = mapPropertyNameToFeatureName(propertyName.c_str()); + // Get Feature Info and Access Mode + VmbFeatureInfo_t featureInfo; + bool rMode{}, wMode{}; + err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), &featureInfo, sizeof(featureInfo)) | + m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, &wMode); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while getting info or access query!"); + return err; + } - // Get Feature Info and Access Mode - VmbFeatureInfo_t featureInfo; - bool rMode{}, wMode{}; - err = m_sdk->VmbFeatureInfoQuery_t(m_handle, featureName.c_str(), &featureInfo, sizeof(featureInfo)) | - m_sdk->VmbFeatureAccessQuery_t(m_handle, featureName.c_str(), &rMode, &wMode); - if (VmbErrorSuccess != err) - { - LOG_ERROR(err, "Error while getting info or access query!"); - return err; - } + if (m_ipAddressFeatures.count(featureName)) + { + wMode = false; + } - if (m_ipAddressFeatures.count(featureName)) - { - wMode = false; - } + const bool readOnly = (rMode && !wMode); + const bool featureAvailable = (rMode || wMode); - const bool readOnly = (rMode && !wMode); - const bool featureAvailable = (rMode || wMode); + // Get values + std::string propertyValue{}, featureValue{}; + pProp->Get(propertyValue); - // Get values - std::string propertyValue{}, featureValue{}; - pProp->Get(propertyValue); + // Handle property value change + switch (eAct) + { + case MM::ActionType::BeforeGet: //!< Update property from feature - // Handle property value change - switch (eAct) + // Update feature range + if (featureAvailable) { - case MM::ActionType::BeforeGet: //!< Update property from feature + err = setAllowedValues(&featureInfo, propertyName.c_str()); + } + // Feature not available -> clear value and range + else + { + switch (pProp->GetType()) + { + case MM::Float: + case MM::Integer: + SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); + pProp->Set("0"); + break; + case MM::String: + ClearAllowedValues(propertyName.c_str()); + pProp->Set(""); + break; + default: + // feature type not supported + break; + } + } - // Update feature range - if (featureAvailable) + if (rMode) + { + err = getFeatureValue(&featureInfo, featureName.c_str(), featureValue); + if (VmbErrorSuccess != err) { - err = setAllowedValues(&featureInfo, propertyName.c_str()); + LOG_ERROR(err, "Error while getting feature value " + featureName); + return err; } - // Feature not available -> clear value and range - else + + // Update property + if (propertyValue != featureValue) { - switch (pProp->GetType()) + pProp->Set(featureValue.c_str()); + err = GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), featureValue.c_str()); + if (propertyName == MM::g_Keyword_PixelType) { - case MM::Float: - case MM::Integer: - SetPropertyLimits(propertyName.c_str(), 0.0, 0.0); - pProp->Set("0"); - break; - case MM::String: - ClearAllowedValues(propertyName.c_str()); - pProp->Set(""); - break; - default: - // feature type not supported - break; + handlePixelFormatChange(featureValue); } - } - if (rMode) - { - err = getFeatureValue(&featureInfo, featureName.c_str(), featureValue); if (VmbErrorSuccess != err) { - LOG_ERROR(err, "Error while getting feature value " + featureName); + LOG_ERROR(err, "Error while calling OnPropertyChanged callback for " + featureName); return err; } - // Update property - if (propertyValue != featureValue) + if (m_exposureFeatureName == featureName) { - pProp->Set(featureValue.c_str()); - err = GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), featureValue.c_str()); - if (propertyName == MM::g_Keyword_PixelType) - { - handlePixelFormatChange(featureValue); - } - - if (VmbErrorSuccess != err) - { - LOG_ERROR(err, "Error while calling OnPropertyChanged callback for " + featureName); - return err; - } + GetCoreCallback()->OnExposureChanged(this, std::stod(featureValue) / MS_TO_US); } } + } - // Set property to readonly (grey out in GUI) if it is readonly or unavailable - pChildProperty->SetReadOnly(readOnly || !featureAvailable); + // Set property to readonly (grey out in GUI) if it is readonly or unavailable + pChildProperty->SetReadOnly(readOnly || !featureAvailable); - break; - case MM::ActionType::AfterSet: //!< Update feature from property - err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); - if (err == VmbErrorInvalidValue) + break; + case MM::ActionType::AfterSet: //!< Update feature from property + err = setFeatureValue(&featureInfo, featureName.c_str(), propertyValue); + if (err == VmbErrorInvalidValue) + { + // Update limits first to have latest min and max + err = setAllowedValues(&featureInfo, propertyName.c_str()); + if (VmbErrorSuccess != err) { - // Update limits first to have latest min and max - err = setAllowedValues(&featureInfo, propertyName.c_str()); - if (VmbErrorSuccess != err) - { - LOG_ERROR(err, "Error while setting allowed values for feature " + featureName); - return err; - } - - // Adjust value - double min{}, max{}; - err = GetPropertyLowerLimit(propertyName.c_str(), min) | GetPropertyUpperLimit(propertyName.c_str(), max); - if (VmbErrorSuccess != err) - { - LOG_ERROR(err, "Error while getting limits for " + propertyName); - return err; - } - std::string adjustedValue = adjustValue(featureInfo, min, max, std::stod(propertyValue)); - err = setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); + LOG_ERROR(err, "Error while setting allowed values for feature " + featureName); + return err; } - if (propertyName == MM::g_Keyword_PixelType) + // Adjust value + double min{}, max{}; + err = GetPropertyLowerLimit(propertyName.c_str(), min) | GetPropertyUpperLimit(propertyName.c_str(), max); + if (VmbErrorSuccess != err) { - handlePixelFormatChange(propertyValue); + LOG_ERROR(err, "Error while getting limits for " + propertyName); + return err; } - break; - default: - // nothing - break; + std::string adjustedValue = adjustValue(featureInfo, min, max, std::stod(propertyValue)); + err = setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); } - if (VmbErrorSuccess != err) + if (propertyName == MM::g_Keyword_PixelType) { - LOG_ERROR(err, "Error while updating property " + propertyName); + handlePixelFormatChange(propertyValue); } + break; + default: + // nothing + break; + } - return err; - }(); + if (VmbErrorSuccess != err) + { + LOG_ERROR(err, "Error while updating property " + propertyName); + } - std::setlocale(LC_ALL, oldLocale); + return err; - return res; } void AlliedVisionCamera::handlePixelFormatChange(const std::string &pixelType) From 3522d5a2c8b42d378414d94b728e34a46985ce8a Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Tue, 19 Sep 2023 15:05:42 +0200 Subject: [PATCH 38/43] Added missing changes --- DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 279cdbe00..e0e2856ae 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -1253,6 +1253,8 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, double interval return err; } + GetCoreCallback()->OnPropertiesChanged(); + return UpdateStatus(); } @@ -1296,6 +1298,8 @@ int AlliedVisionCamera::StopSequenceAcquisition() return err; } + GetCoreCallback()->OnPropertiesChanged(); + return UpdateStatus(); } From 684f73476fa08e3137e716929ce6ad9b0adbba9d Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Tue, 19 Sep 2023 15:03:06 +0200 Subject: [PATCH 39/43] Fixed float property change always called Inside onProperty for every float property the OnPropertyChanged callback was always called even when the value has not changed, because for the comparison the float were converted to strings with a different count of decimal places. On stream start and stop now OnPropertiesChanged is called to update the ReadOnly status of all properties in the gui. --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index e0e2856ae..12d0b0842 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -585,6 +585,24 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase *pProp, MM::ActionType eAct) } const auto propertyName = pProp->GetName(); + + auto valueEqual = [pProp](const std::string& newValue) -> bool { + switch (pProp->GetType()) + { + case MM::PropertyType::Float: + { + double oldValue{}; + pProp->Get(oldValue); + return oldValue == std::stod(newValue); + } + default: + { + std::string oldValue{}; + pProp->Get(oldValue); + return oldValue == newValue; + } + } + }; // Check property mapping auto const featureName = mapPropertyNameToFeatureName(propertyName.c_str()); @@ -652,7 +670,7 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase *pProp, MM::ActionType eAct) } // Update property - if (propertyValue != featureValue) + if (!valueEqual(featureValue)) { pProp->Set(featureValue.c_str()); err = GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), featureValue.c_str()); @@ -700,7 +718,16 @@ int AlliedVisionCamera::onProperty(MM::PropertyBase *pProp, MM::ActionType eAct) } std::string adjustedValue = adjustValue(featureInfo, min, max, std::stod(propertyValue)); err = setFeatureValue(&featureInfo, featureName.c_str(), adjustedValue); + if (err == VmbErrorSuccess) + { + err = GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), adjustedValue.c_str()); + } + } + else if (err == VmbErrorSuccess) + { + err = GetCoreCallback()->OnPropertyChanged(this, propertyName.c_str(), propertyValue.c_str()); } + if (propertyName == MM::g_Keyword_PixelType) { From ea54eeb865c725ac6d78b1a37d21d4ea0749f9a1 Mon Sep 17 00:00:00 2001 From: Dennis Langenkamp Date: Tue, 19 Sep 2023 15:48:52 +0200 Subject: [PATCH 40/43] Added missing this to OnPropertiesChanged calls --- DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 12d0b0842..48552f1f1 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -1280,7 +1280,7 @@ int AlliedVisionCamera::StartSequenceAcquisition(long numImages, double interval return err; } - GetCoreCallback()->OnPropertiesChanged(); + GetCoreCallback()->OnPropertiesChanged(this); return UpdateStatus(); } @@ -1325,7 +1325,7 @@ int AlliedVisionCamera::StopSequenceAcquisition() return err; } - GetCoreCallback()->OnPropertiesChanged(); + GetCoreCallback()->OnPropertiesChanged(this); return UpdateStatus(); } From f5b7296db4750d67b07b481d8b1cb2f1054756d7 Mon Sep 17 00:00:00 2001 From: "Florian Klostermann [Allied Vision]" Date: Mon, 2 Oct 2023 16:22:46 +0200 Subject: [PATCH 41/43] Pull request #16: Prepare Micro Manager Pull Request Merge in HSW_SDK/mmcoreanddevices from feature/adjust-license to feature/allied-vision-camera-micro-manager-v2.0.2 Squashed commit of the following: commit faba693dfdb1b1f3bea6fe97256bc0fa9ba8c9ae Author: Florian Klostermann Date: Mon Oct 2 15:53:45 2023 +0200 fixed AVT Makefile.am commit 12869688f62ebfe237e9444303ee9931ac7fb114 Author: Florian Klostermann Date: Mon Oct 2 14:56:00 2023 +0200 adjusted additional include directory for AlliedVisionCamera commit dff1da08a9873eb955d3151711221faee92e5c55 Author: Florian Klostermann Date: Mon Oct 2 14:45:10 2023 +0200 adjsted project files after removing sdk headers from repo commit a06627c0ff2d28c164e6ea706984e2af0ff3e2a6 Author: Florian Klostermann Date: Mon Oct 2 14:36:32 2023 +0200 removed SDK Headers from repo, adjusted Makefile to use VIMBA_X_HOME variable commit 94959ad944621b870d09513826bab5897cbb29a5 Author: Florian Klostermann Date: Mon Oct 2 14:12:34 2023 +0200 adjusted license headers commit 5dd1d42e94e3d2a6a8d5a63057f5d7b40373358c Author: Florian Klostermann Date: Thu Sep 21 17:53:45 2023 +0200 adjusted license header --- .../AlliedVisionCamera/AlliedVisionCamera.cpp | 4 +- .../AlliedVisionCamera/AlliedVisionCamera.h | 4 +- .../AlliedVisionCamera.vcxproj | 18 +- .../AlliedVisionCamera.vcxproj.filters | 32 +- .../AlliedVisionDeviceBase.h | 4 +- .../AlliedVisionCamera/AlliedVisionHub.cpp | 4 +- .../AlliedVisionCamera/AlliedVisionHub.h | 4 +- .../{SDK => }/Loader/Constants.h | 4 +- .../{SDK => }/Loader/LibLoader.cpp | 4 +- .../{SDK => }/Loader/LibLoader.h | 4 +- DeviceAdapters/AlliedVisionCamera/Makefile.am | 4 +- .../AlliedVisionCamera/SDK/VmbC/VmbC.h | 2182 ----------------- .../SDK/VmbC/VmbCTypeDefinitions.h | 610 ----- .../SDK/VmbC/VmbCommonTypes.h | 444 ---- .../SDK/VmbC/VmbConstants.h | 85 - .../SDK/VmbImageTransform/VmbTransform.h | 336 --- .../SDK/VmbImageTransform/VmbTransformTypes.h | 1018 -------- DeviceAdapters/AlliedVisionCamera/license.txt | 25 + 18 files changed, 57 insertions(+), 4729 deletions(-) rename DeviceAdapters/AlliedVisionCamera/{SDK => }/Loader/Constants.h (93%) rename DeviceAdapters/AlliedVisionCamera/{SDK => }/Loader/LibLoader.cpp (98%) rename DeviceAdapters/AlliedVisionCamera/{SDK => }/Loader/LibLoader.h (98%) delete mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbC.h delete mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCTypeDefinitions.h delete mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCommonTypes.h delete mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbConstants.h delete mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransform.h delete mode 100644 DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransformTypes.h create mode 100644 DeviceAdapters/AlliedVisionCamera/license.txt diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp index 48552f1f1..fbc80e37c 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.cpp @@ -1,8 +1,8 @@ /*============================================================================= Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. + This file is distributed under the BSD license. + License text is included with the source distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h index 2dd14f1c1..ec0e2660c 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.h @@ -1,8 +1,8 @@ /*============================================================================= Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. + This file is distributed under the BSD license. + License text is included with the source distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj index 6b1087e6d..96b6f5ded 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj @@ -22,20 +22,14 @@ - - - - - - - - + + - + @@ -123,6 +117,7 @@ true Use pch.h + $(VIMBA_X_HOME)/api/include;%(AdditionalIncludeDirectories) Windows @@ -140,6 +135,7 @@ true Use pch.h + $(VIMBA_X_HOME)/api/include;%(AdditionalIncludeDirectories) Windows @@ -155,7 +151,7 @@ _DEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - $(ProjectDir)SDK;%(AdditionalIncludeDirectories) + $(VIMBA_X_HOME)/api/include;%(AdditionalIncludeDirectories) Windows @@ -171,7 +167,7 @@ NDEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - $(ProjectDir)SDK;%(AdditionalIncludeDirectories) + $(VIMBA_X_HOME)/api/include;%(AdditionalIncludeDirectories) Windows diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters index bdb569ec1..cbb7c0517 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj.filters @@ -18,34 +18,16 @@ Header Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - + Header Files - + Header Files - + Header Files - + Header Files @@ -53,14 +35,14 @@ Source Files - - Source Files - Source Files Source Files + + Source Files + \ No newline at end of file diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h index 642fa566e..a719d772e 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionDeviceBase.h @@ -1,8 +1,8 @@ /*============================================================================= Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. + This file is distributed under the BSD license. + License text is included with the source distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp index 59276c8c6..aa3147fea 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.cpp @@ -1,8 +1,8 @@ /*============================================================================= Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. + This file is distributed under the BSD license. + License text is included with the source distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h index 6ecc4a37a..7d47f4b96 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionHub.h @@ -1,8 +1,8 @@ /*============================================================================= Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. + This file is distributed under the BSD license. + License text is included with the source distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h b/DeviceAdapters/AlliedVisionCamera/Loader/Constants.h similarity index 93% rename from DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h rename to DeviceAdapters/AlliedVisionCamera/Loader/Constants.h index 17540091b..3ca10d69a 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/Constants.h +++ b/DeviceAdapters/AlliedVisionCamera/Loader/Constants.h @@ -1,8 +1,8 @@ /*============================================================================= Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. + This file is distributed under the BSD license. + License text is included with the source distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp b/DeviceAdapters/AlliedVisionCamera/Loader/LibLoader.cpp similarity index 98% rename from DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp rename to DeviceAdapters/AlliedVisionCamera/Loader/LibLoader.cpp index 118a642a9..de8d8d512 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.cpp +++ b/DeviceAdapters/AlliedVisionCamera/Loader/LibLoader.cpp @@ -1,8 +1,8 @@ /*============================================================================= Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. + This file is distributed under the BSD license. + License text is included with the source distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h b/DeviceAdapters/AlliedVisionCamera/Loader/LibLoader.h similarity index 98% rename from DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h rename to DeviceAdapters/AlliedVisionCamera/Loader/LibLoader.h index adf944f7a..fc63ea663 100644 --- a/DeviceAdapters/AlliedVisionCamera/SDK/Loader/LibLoader.h +++ b/DeviceAdapters/AlliedVisionCamera/Loader/LibLoader.h @@ -1,8 +1,8 @@ /*============================================================================= Copyright (C) 2023 Allied Vision Technologies. All Rights Reserved. - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. + This file is distributed under the BSD license. + License text is included with the source distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, diff --git a/DeviceAdapters/AlliedVisionCamera/Makefile.am b/DeviceAdapters/AlliedVisionCamera/Makefile.am index b5d08b4fa..1f4fa159a 100644 --- a/DeviceAdapters/AlliedVisionCamera/Makefile.am +++ b/DeviceAdapters/AlliedVisionCamera/Makefile.am @@ -1,8 +1,8 @@ AUTOMAKE_OPTIONS = subdir-objects -AM_CXXFLAGS = $(MMDEVAPI_CXXFLAGS) -ISDK +AM_CXXFLAGS = $(MMDEVAPI_CXXFLAGS) -I$(VIMBA_X_HOME)/api/include deviceadapter_LTLIBRARIES = libmmgr_dal_AlliedVisionCamera.la -libmmgr_dal_AlliedVisionCamera_la_SOURCES = AlliedVisionHub.h AlliedVisionHub.cpp AlliedVisionDeviceBase.h AlliedVisionDeviceBase.cpp AlliedVisionCamera.h AlliedVisionCamera.cpp SDK/Loader/Constants.h SDK/Loader/LibLoader.h SDK/Loader/LibLoader.cpp SDK/VmbC/VmbC.h SDK/VmbC/VmbCommonTypes.h SDK/VmbC/VmbConstants.h SDK/Vmbc/VmbCTypeDefinitions.h SDK/VmbImageTransform/VmbTransform.h SDK/VmbImageTransform/VmbTransformTypes.h +libmmgr_dal_AlliedVisionCamera_la_SOURCES = AlliedVisionHub.h AlliedVisionHub.cpp AlliedVisionDeviceBase.h AlliedVisionDeviceBase.cpp AlliedVisionCamera.h AlliedVisionCamera.cpp Loader/Constants.h Loader/LibLoader.h Loader/LibLoader.cpp $(VIMBA_X_HOME)/api/include/VmbC/VmbC.h $(VIMBA_X_HOME)/api/include/VmbC/VmbCommonTypes.h $(VIMBA_X_HOME)/api/include/VmbC/VmbConstants.h $(VIMBA_X_HOME)/api/include/VmbC/VmbCTypeDefinitions.h $(VIMBA_X_HOME)/api/include/VmbImageTransform/VmbTransform.h $(VIMBA_X_HOME)/api/include/VmbImageTransform/VmbTransformTypes.h libmmgr_dal_AlliedVisionCamera_la_LIBADD = $(MMDEVAPI_LIBADD) libmmgr_dal_AlliedVisionCamera_la_LDFLAGS = $(MMDEVAPI_LDFLAGS) diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbC.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbC.h deleted file mode 100644 index 8347195d0..000000000 --- a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbC.h +++ /dev/null @@ -1,2182 +0,0 @@ -/*============================================================================= - Copyright (C) 2012 - 2022 Allied Vision Technologies. All Rights Reserved. - - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. - -------------------------------------------------------------------------------- - - File: VmbC.h - -------------------------------------------------------------------------------- - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, - NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -=============================================================================*/ - -/** - * \file - * \brief Main header file for the VmbC API. - * - * This file describes all necessary definitions for using Allied Vision's - * VmbC API. These type definitions are designed to be portable from other - * languages and other operating systems. - * - * General conventions: - * - Method names are composed in the following manner: - * - Vmb"Action" example: ::VmbStartup() - * - Vmb"Entity""Action" or Vmb"ActionTarget""Action" example: ::VmbCameraOpen() - * - Vmb"Entity""SubEntity/ActionTarget""Action" example: ::VmbFeatureCommandRun() - * - * - Strings (generally declared as "const char *") are assumed to have a trailing 0 character - * - All pointer parameters should of course be valid, except if stated otherwise. - * - To ensure compatibility with older programs linked against a former version of the API, - * all struct* parameters have an accompanying sizeofstruct parameter. - * - Functions returning lists are usually called twice: once with a zero buffer - * to get the length of the list, and then again with a buffer of the correct length. - */ - -#ifndef VMBC_H_INCLUDE_ -#define VMBC_H_INCLUDE_ - -#include -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \brief Timeout parameter signaling a blocking call. - */ -#define VMBINFINITE 0xFFFFFFFF - -/** - * \brief Define for the handle to use for accessing the Vmb system features cast to a given type - * - * Note: The primary purpose of this macro is the use in the VmbC sources. - * API users should use ::gVmbHandle instead. - */ -#define VMB_API_HANDLE(typeName) ((typeName)((((VmbUint64_t)1) << (VmbUint64_t)(sizeof(VmbHandle_t) * 8 - 4)) | ((VmbUint64_t) 1))) - -/** - * \brief Constant for the Vmb handle to be able to access Vmb system features. - */ -static const VmbHandle_t gVmbHandle = VMB_API_HANDLE(VmbHandle_t); - -//===== FUNCTION PROTOTYPES =================================================== - -/** - * \defgroup Functions Vmb C API Functions - * \{ - */ - -/** - * \name API Version - * \defgroup Version API Version - * \{ - */ - -/** - * \brief Retrieve the version number of VmbC. - * - * This function can be called at anytime, even before the API is - * initialized. All other version numbers may be queried via feature access. - * - * \param[out] versionInfo Pointer to the struct where version information resides - * \param[in] sizeofVersionInfo Size of structure in bytes - * - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback. - * - * \retval ::VmbErrorStructSize The given struct size is not valid for this version of the API - * - * \retval ::VmbErrorBadParameter \p versionInfo is null. - * - */ -IMEXPORTC VmbError_t VMB_CALL VmbVersionQuery ( VmbVersionInfo_t* versionInfo, - VmbUint32_t sizeofVersionInfo ); -/** - * \} - */ - -/** - * \name API Initialization - * \{ - * \defgroup Init API Initialization - * \{ - */ - -/** - * \brief Initializes the VmbC API. - * - * Note: This function must be called before any VmbC function other than ::VmbVersionQuery() is run. - * - * \param[in] pathConfiguration A string containing a semicolon (Windows) or colon (other os) separated list of paths. The paths contain directories to search for .cti files, - * paths to .cti files and optionally the path to a configuration xml file. If null is passed the parameter is the cti files found in the paths - * the GENICAM_GENTL{32|64}_PATH environment variable are considered - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorAlready This function was called before and call to ::VmbShutdown has been executed on a non-callback thread - * - * \retval ::VmbErrorInvalidCall If called from a callback or ::VmbShutdown is currently running - * - * \retval ::VmbErrorXml If parsing the settings xml is unsuccessful; a missing default xml file does not result in this error. - * - * \retval ::VmbErrorTLNotFound A transport layer that was marked as required was not found. - * - * \retval ::VmbErrorNoTL No transport layer was found on the system; note that some of the transport layers may have been filtered out via the settings file. - * - * \retval ::VmbErrorIO A log file should be written according to the settings xml file, but this log file could not be opened. - * - * \retval ::VmbErrorBadParameter \p pathConfiguration contains only separator and whitespace chars. - * - */ -IMEXPORTC VmbError_t VMB_CALL VmbStartup (const VmbFilePathChar_t* pathConfiguration); - -/** - * \brief Perform a shutdown of the API. - * - * This frees some resources and deallocates all physical resources if applicable. - * - * The call is silently ignored, if executed from a callback. - * - */ -IMEXPORTC void VMB_CALL VmbShutdown ( void ); - -/** - * \} \} - */ - -/** - * \name Camera Enumeration & Information - * \{ - * \defgroup CameraInfo Camera Enumeration & Information - * \{ - */ - -/** - * List all the cameras that are currently visible to the API. - * - * Note: This function is usually called twice: once with an empty array to query the length - * of the list, and then again with an array of the correct length. - * If camera lists change between the calls, numFound may deviate from the query return. - * - * \param[in,out] cameraInfo Array of VmbCameraInfo_t, allocated by the caller. - * The camera list is copied here. May be null. - * - * \param[in] listLength Number of entries in the callers cameraInfo array. - * - * \param[in,out] numFound Number of cameras found. Can be more than listLength. - * - * \param[in] sizeofCameraInfo Size of one VmbCameraInfo_t entry (if \p cameraInfo is null, this parameter is ignored). - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p numFound is null - * - * \retval ::VmbErrorStructSize The given struct size is not valid for this API version and \p cameraInfo is not null - * - * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries - */ -IMEXPORTC VmbError_t VMB_CALL VmbCamerasList ( VmbCameraInfo_t* cameraInfo, - VmbUint32_t listLength, - VmbUint32_t* numFound, - VmbUint32_t sizeofCameraInfo ); - -/** - * \brief Retrieve information about a single camera given its handle. - * - * Note: Some information is only filled for opened cameras. - * - * \param[in] cameraHandle The handle of the camera; both remote and local device handles are permitted - * - * \param[in,out] info Structure where information will be copied - * - * \param[in] sizeofCameraInfo Size of the structure - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorStructSize The given struct size is not valid for this API version - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorBadParameter \p info is null - * - * \retval ::VmbErrorBadHandle The handle does not correspond to a camera - */ -IMEXPORTC VmbError_t VMB_CALL VmbCameraInfoQueryByHandle( VmbHandle_t cameraHandle, - VmbCameraInfo_t* info, - VmbUint32_t sizeofCameraInfo); - -/** - * \brief Retrieve information about a single camera given the ID of the camera. - * - * Note: Some information is only filled for opened cameras. - * - * \param[in] idString ID of the camera - * - * \param[in,out] info Structure where information will be copied - * - * \param[in] sizeofCameraInfo Size of the structure - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p idString or \p info are null or \p idString is the empty string - * - * \retval ::VmbErrorNotFound No camera with the given id is found - * - * \retval ::VmbErrorStructSize The given struct size is not valid for this API version - */ -IMEXPORTC VmbError_t VMB_CALL VmbCameraInfoQuery ( const char* idString, - VmbCameraInfo_t* info, - VmbUint32_t sizeofCameraInfo ); - -/** - * \brief Open the specified camera. - * - * \param[in] idString ID of the camera. - * \param[in] accessMode The desired access mode. - * \param[out] cameraHandle The remote device handle of the camera, if opened successfully. - * - * A camera may be opened in a specific access mode, which determines - * the level of control you have on a camera. - * Examples for idString: - * - * "DEV_81237473991" for an ID given by a transport layer, - * "169.254.12.13" for an IP address, - * "000F314C4BE5" for a MAC address or - * "DEV_1234567890" for an ID as reported by Vmb - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInUse The camera with the given ID is already opened - * - * \retval ::VmbErrorInvalidCall If called from frame callback or chunk access callback - * - * \retval ::VmbErrorBadParameter If \p idString or \p cameraHandle are null - * - * \retval ::VmbErrorInvalidAccess A camera with the given id was found, but could not be opened - * - * \retval ::VmbErrorNotFound The designated camera cannot be found - */ -IMEXPORTC VmbError_t VMB_CALL VmbCameraOpen ( const char* idString, - VmbAccessMode_t accessMode, - VmbHandle_t* cameraHandle ); - -/** - * \brief Close the specified camera. - * - * Depending on the access mode this camera was opened with, events are killed, - * callbacks are unregistered, and camera control is released. - * - * \param[in] cameraHandle A valid camera handle - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInUse The camera is currently in use with ::VmbChunkDataAccess - * - * \retval ::VmbErrorBadHandle The handle does not correspond to an open camera - * - * \retval ::VmbErrorInvalidCall If called from frame callback or chunk access callback - */ -IMEXPORTC VmbError_t VMB_CALL VmbCameraClose ( const VmbHandle_t cameraHandle ); - -/** - * \} \} - */ - -//----- Features ---------------------------------------------------------- - -/** - * \name General Feature Functions - * \{ - * \defgroup GeneralFeatures General Feature Functions - * \{ - */ - -/** - * \brief List all the features for this entity. - * - * This function lists all implemented features, whether they are currently available or not. - * The list of features does not change as long as the entity is connected. - * - * This function is usually called twice: once with an empty list to query the length - * of the list, and then again with a list of the correct length. - * - * If ::VmbErrorMoreData is returned and \p numFound is non-null, the total number of features has been written to \p numFound. - * - * If there are more elements in \p featureInfoList than features available, the remaining elements - * are filled with zero-initialized ::VmbFeatureInfo_t structs. - * - * \param[in] handle Handle for an entity that exposes features - * \param[out] featureInfoList An array of ::VmbFeatureInfo_t to be filled by the API. May be null if \p numFund is used for size query. - * \param[in] listLength Number of ::VmbFeatureInfo_t elements provided - * \param[out] numFound Number of ::VmbFeatureInfo_t elements found. May be null if \p featureInfoList is not null. - * \param[in] sizeofFeatureInfo Size of a ::VmbFeatureInfo_t entry - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorStructSize The given struct size of ::VmbFeatureInfo_t is not valid for this version of the API - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter Both \p featureInfoList and \p numFound are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeaturesList ( VmbHandle_t handle, - VmbFeatureInfo_t* featureInfoList, - VmbUint32_t listLength, - VmbUint32_t* numFound, - VmbUint32_t sizeofFeatureInfo ); - -/** - * \brief Query information about the constant properties of a feature. - * - * Users provide a pointer to ::VmbFeatureInfo_t, which is then set to the internal representation. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] featureInfo The feature info to query - * \param[in] sizeofFeatureInfo Size of the structure - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorStructSize The given struct size of ::VmbFeatureInfo_t is not valid for this version of the API - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name or \p featureInfo are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound A feature with the given name does not exist. - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureInfoQuery ( const VmbHandle_t handle, - const char* name, - VmbFeatureInfo_t* featureInfo, - VmbUint32_t sizeofFeatureInfo ); - -/** - * \brief List all the features selected by a given feature for this module. - * - * This function lists all selected features, whether they are currently available or not. - * Features with selected features ("selectors") have no direct impact on the camera, - * but only influence the register address that selected features point to. - * The list of features does not change while the camera/interface is connected. - * This function is usually called twice: once with an empty array to query the length - * of the list, and then again with an array of the correct length. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] featureInfoList An array of ::VmbFeatureInfo_t to be filled by the API. May be null if \p numFound is used for size query. - * \param[in] listLength Number of ::VmbFeatureInfo_t elements provided - * \param[out] numFound Number of ::VmbFeatureInfo_t elements found. May be null if \p featureInfoList is not null. - * \param[in] sizeofFeatureInfo Size of a ::VmbFeatureInfo_t entry - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorBadParameter \p name is null or both \p featureInfoList and \p numFound are null - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorStructSize The given struct size of ::VmbFeatureInfo_t is not valid for this version of the API - * - * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureListSelected ( const VmbHandle_t handle, - const char* name, - VmbFeatureInfo_t* featureInfoList, - VmbUint32_t listLength, - VmbUint32_t* numFound, - VmbUint32_t sizeofFeatureInfo ); - -/** - * \brief Return the dynamic read and write capabilities of this feature. - * - * The access mode of a feature may change. For example, if "PacketSize" - * is locked while image data is streamed, it is only readable. - * - * \param[in] handle Handle for an entity that exposes features. - * \param[in] name Name of the feature. - * \param[out] isReadable Indicates if this feature is readable. May be null. - * \param[out] isWriteable Indicates if this feature is writable. May be null. - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name is null or both \p isReadable and \p isWriteable are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureAccessQuery ( const VmbHandle_t handle, - const char* name, - VmbBool_t * isReadable, - VmbBool_t * isWriteable ); - -/** - * \} \} - */ - -/** - * \name Integer Feature Access - * \{ - * \defgroup IntAccess Integer Feature Access - * \{ - */ - -/** - * \brief Get the value of an integer feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] value Value to get - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name or \p value are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Integer - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntGet ( const VmbHandle_t handle, - const char* name, - VmbInt64_t* value ); - -/** - * \brief Set the value of an integer feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[in] value Value to set - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorInvalidCall If called from feature callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter If \p name is null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Integer - * - * \retval ::VmbErrorInvalidAccess The feature is unavailable or not writable - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - * - * \retval ::VmbErrorInvalidValue If value is either out of bounds or not an increment of the minimum - * - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntSet ( const VmbHandle_t handle, - const char* name, - VmbInt64_t value ); - -/** - * \brief Query the range of an integer feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] min Minimum value to be returned. May be null. - * \param[out] max Maximum value to be returned. May be null. - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter If \p name is null or both \p min and \p max are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature name is not Integer - * - * \retval ::VmbErrorInvalidAccess The range information is unavailable or not writable - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntRangeQuery ( const VmbHandle_t handle, - const char* name, - VmbInt64_t* min, - VmbInt64_t* max ); - -/** - * \brief Query the increment of an integer feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] value Value of the increment to get. - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter If \p name or \p value are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Integer - * - * \retval ::VmbErrorInvalidAccess The information is unavailable or cannot be read - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntIncrementQuery ( const VmbHandle_t handle, - const char* name, - VmbInt64_t* value ); - -/** - * \brief Retrieves info about the valid value set of an integer feature. - * - * Retrieves information about the set of valid values of an integer feature. If null is passed as buffer, - * only the size of the set is determined and written to bufferFilledCount; Otherwise the largest possible - * number of elements of the valid value set is copied to buffer. - * - * \param[in] handle The handle for the entity the feature information is retrieved from - * \param[in] name The name of the feature to retrieve the info for; if null is passed ::VmbErrorBadParameter is returned - * \param[in] buffer The array to copy the valid values to or null if only the size of the set is requested - * \param[in] bufferSize The size of buffer; if buffer is null, the value is ignored - * \param[out] setSize The total number of elements in the set; the value is set, if ::VmbErrorMoreData is returned - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name is null or both \p buffer and \p bufferFilledCount are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of the feature is not Integer - * - * \retval ::VmbErrorValidValueSetNotPresent The feature does not provide a valid value set - * - * \retval ::VmbErrorMoreData Some of data was retrieved successfully, but the size of buffer is insufficient to store all elements - * - * \retval ::VmbErrorIncomplete The module the handle refers to is in a state where it cannot complete the request - * - * \retval ::VmbErrorOther Some other issue occurred - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureIntValidValueSetQuery(const VmbHandle_t handle, - const char* name, - VmbInt64_t* buffer, - VmbUint32_t bufferSize, - VmbUint32_t* setSize); - -/** - * \} \} - */ - -/** - * \name Float Feature Access - * \{ - * \defgroup FloatAccess Float Feature Access - * \{ - */ - -/** - * \brief Get the value of a float feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] value Value to get - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name or \p value are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Float - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureFloatGet ( const VmbHandle_t handle, - const char* name, - double* value ); - -/** - * \brief Set the value of a float feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[in] value Value to set - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from feature callback - * - * \retval ::VmbErrorBadParameter \p name is null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Float - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - * - * \retval ::VmbErrorInvalidValue If value is not within valid bounds - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureFloatSet ( const VmbHandle_t handle, - const char* name, - double value ); - -/** - * \brief Query the range of a float feature. - * - * Only one of the values may be queried if the other parameter is set to null, - * but if both parameters are null, an error is returned. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] min Minimum value to be returned. May be null. - * \param[out] max Maximum value to be returned. May be null. - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorBadParameter \p name is null or both \p min and \p max are null - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Float - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureFloatRangeQuery ( const VmbHandle_t handle, - const char* name, - double* min, - double* max ); - -/** - * \brief Query the increment of a float feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] hasIncrement `true` if this float feature has an increment. - * \param[out] value Value of the increment to get. - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorBadParameter \p name is null or both \p value and \p hasIncrement are null - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Float - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureFloatIncrementQuery ( const VmbHandle_t handle, - const char* name, - VmbBool_t* hasIncrement, - double* value ); - -/** - * \} \} -*/ - -/** - * \name Enum Feature Access - * \{ - * \defgroup EnumAccess Enum Feature Access - * \{ - */ - -/** - * \brief Get the value of an enumeration feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] value The current enumeration value. The returned value is a - * reference to the API value - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorBadParameter \p name or \p value are null - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature featureName is not Enumeration - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature is not available - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumGet ( const VmbHandle_t handle, - const char* name, - const char** value ); - -/** - * \brief Set the value of an enumeration feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[in] value Value to set - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from feature callback - * - * \retval ::VmbErrorBadParameter If \p name or \p value are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration - * - * \retval ::VmbErrorNotAvailable The feature is not available - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorInvalidValue \p value is not a enum entry for the feature or the existing enum entry is currently not available - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumSet ( const VmbHandle_t handle, - const char* name, - const char* value ); - -/** - * \brief Query the value range of an enumeration feature. - * - * All elements not filled with the names of enum entries by the function are set to null. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[out] nameArray An array of enumeration value names; may be null if \p numFound is used for size query - * \param[in] arrayLength Number of elements in the array - * \param[out] numFound Number of elements found; may be null if \p nameArray is not null - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name is null or both \p nameArray and \p numFound are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorNotImplemented The feature \p name is not implemented - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration - * - * \retval ::VmbErrorMoreData The given array length was insufficient to hold all available entries - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumRangeQuery ( const VmbHandle_t handle, - const char* name, - const char** nameArray, - VmbUint32_t arrayLength, - VmbUint32_t* numFound ); - -/** - * \brief Check if a certain value of an enumeration is available. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[in] value Value to check - * \param[out] isAvailable Indicates if the given enumeration value is available - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name, \p value or \p isAvailable are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration - * - * \retval ::VmbErrorNotImplemented The feature \p name is not implemented - * - * \retval ::VmbErrorInvalidValue There is no enum entry with string representation of \p value for the given enum feature - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumIsAvailable ( const VmbHandle_t handle, - const char* name, - const char* value, - VmbBool_t * isAvailable ); - -/** - * \brief Get the integer value for a given enumeration string value. - * - * Converts a name of an enum member into an int value ("Mono12Packed" to 0x10C0006) - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[in] value The enumeration value to get the integer value for - * \param[out] intVal The integer value for this enumeration entry - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter If \p name, \p value or \p intVal are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound No feature with the given name was found - * - * \retval ::VmbErrorNotImplemented The feature \p name is not implemented - * - * \retval ::VmbErrorInvalidValue \p value is not the name of a enum entry for the feature - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumAsInt ( const VmbHandle_t handle, - const char* name, - const char* value, - VmbInt64_t* intVal ); - -/** - * \brief Get the enumeration string value for a given integer value. - * - * Converts an int value to a name of an enum member (e.g. 0x10C0006 to "Mono12Packed") - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[in] intValue The numeric value - * \param[out] stringValue The string value for the numeric value - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name or \p stringValue are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound No feature with the given name was found - * - * \retval ::VmbErrorNotImplemented No feature \p name is not implemented - * - * \retval ::VmbErrorInvalidValue \p intValue is not the int value of an enum entry - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Enumeration - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumAsString ( VmbHandle_t handle, - const char* name, - VmbInt64_t intValue, - const char** stringValue ); - -/** - * \brief Get infos about an entry of an enumeration feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] featureName Name of the feature - * \param[in] entryName Name of the enum entry of that feature - * \param[out] featureEnumEntry Infos about that entry returned by the API - * \param[in] sizeofFeatureEnumEntry Size of the structure - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorStructSize Size of ::VmbFeatureEnumEntry_t is not compatible with the API version - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p featureName, \p entryName or \p featureEnumEntry are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorNotImplemented The feature \p name is not implemented - * - * \retval ::VmbErrorInvalidValue There is no enum entry with a string representation of \p entryName - * - * \retval ::VmbErrorWrongType The type of feature featureName is not Enumeration - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureEnumEntryGet ( const VmbHandle_t handle, - const char* featureName, - const char* entryName, - VmbFeatureEnumEntry_t* featureEnumEntry, - VmbUint32_t sizeofFeatureEnumEntry ); - -/** - * \} \} - */ - -/** - * \name String Feature Access - * \{ - * \defgroup StringAccess String Feature Access - * \{ - */ - -/** - * \brief Get the value of a string feature. - * - * This function is usually called twice: once with an empty buffer to query the length - * of the string, and then again with a buffer of the correct length. - * - * The value written to \p sizeFilled includes the terminating 0 character of the string. - * - * If a \p buffer is provided and there its insufficient to hold all the data, the longest - * possible prefix fitting the buffer is copied to \p buffer; the last element of \p buffer is - * set to 0 case. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the string feature - * \param[out] buffer String buffer to fill. May be null if \p sizeFilled is used for size query. - * \param[in] bufferSize Size of the input buffer - * \param[out] sizeFilled Size actually filled. May be null if \p buffer is not null. - * - * - * \return An error code indicating the type of error, if any. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name is null, both \p buffer and \p sizeFilled are null or \p buffer is non-null and bufferSize is 0 - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not String - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - * - * \retval ::VmbErrorMoreData The given buffer size was too small - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureStringGet ( const VmbHandle_t handle, - const char* name, - char* buffer, - VmbUint32_t bufferSize, - VmbUint32_t* sizeFilled ); - -/** - * \brief Set the value of a string feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the string feature - * \param[in] value Value to set - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from feature callback - * - * \retval ::VmbErrorBadParameter \p name or \p value are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not String - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorInvalidValue If length of value exceeded the maximum length - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureStringSet ( const VmbHandle_t handle, - const char* name, - const char* value ); - -/** - * \brief Get the maximum length of a string feature. - * - * The length reported does not include the terminating 0 char. - * - * Note: For some features the maximum size is not fixed and may change. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the string feature - * \param[out] maxLength Maximum length of this string feature - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name or \p maxLength are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorWrongType The type of feature \p name is not String - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureStringMaxlengthQuery ( const VmbHandle_t handle, - const char* name, - VmbUint32_t* maxLength ); - -/** - * \} \} - */ - -/** - * \name Boolean Feature Access - * \{ - * \defgroup BoolAccess Boolean Feature Access - * \{ - */ - -/** - * \brief Get the value of a boolean feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the boolean feature - * \param[out] value Value to be read - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name or \p value are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound If feature is not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Boolean - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureBoolGet ( const VmbHandle_t handle, - const char* name, - VmbBool_t * value ); - -/** - * \brief Set the value of a boolean feature. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the boolean feature - * \param[in] value Value to write - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name is null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound If the feature is not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Boolean - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - * - * \retval ::VmbErrorInvalidValue If value is not within valid bounds - * - * \retval ::VmbErrorInvalidCall If called from feature callback - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureBoolSet ( const VmbHandle_t handle, - const char* name, - VmbBool_t value ); - -/** - * \} \} - */ - -/** - * \name Command Feature Access - * \{ - * \defgroup CmdAccess Command Feature Access - * \{ - */ - -/** - * \brief Run a feature command. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the command feature - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorInvalidCall If called from a feature callback or chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name is null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound Feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Command - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureCommandRun ( const VmbHandle_t handle, - const char* name ); - -/** - * \brief Check if a feature command is done. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the command feature - * \param[out] isDone State of the command. - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorBadParameter If \p name or \p isDone are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound Feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Command - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureCommandIsDone ( const VmbHandle_t handle, - const char* name, - VmbBool_t * isDone ); - -/** - * \} \} - */ - -/** - * \name Raw Feature Access - * \{ - * \defgroup RawAccess Raw Feature Access - * \{ - */ - -/** - * \brief Read the memory contents of an area given by a feature name. - * - * This feature type corresponds to a top-level "Register" feature in GenICam. - * Data transfer is split up by the transport layer if the feature length is too large. - * You can get the size of the memory area addressed by the feature name by ::VmbFeatureRawLengthQuery(). - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the raw feature - * \param[out] buffer Buffer to fill - * \param[in] bufferSize Size of the buffer to be filled - * \param[out] sizeFilled Number of bytes actually filled - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p name, \p buffer or \p sizeFilled are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound Feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Register - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureRawGet ( const VmbHandle_t handle, - const char* name, - char* buffer, - VmbUint32_t bufferSize, - VmbUint32_t* sizeFilled ); - -/** - * \brief Write to a memory area given by a feature name. - * - * This feature type corresponds to a first-level "Register" node in the XML file. - * Data transfer is split up by the transport layer if the feature length is too large. - * You can get the size of the memory area addressed by the feature name by ::VmbFeatureRawLengthQuery(). - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the raw feature - * \param[in] buffer Data buffer to use - * \param[in] bufferSize Size of the buffer - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from feature callback or a chunk access callback - * - * \retval ::VmbErrorBadParameter \p name or \p buffer are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound Feature was not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Register - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureRawSet ( const VmbHandle_t handle, - const char* name, - const char* buffer, - VmbUint32_t bufferSize ); - -/** - * \brief Get the length of a raw feature for memory transfers. - * - * This feature type corresponds to a first-level "Register" node in the XML file. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the raw feature - * \param[out] length Length of the raw feature area (in bytes) - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter If \p name or \p length are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound Feature not found - * - * \retval ::VmbErrorWrongType The type of feature \p name is not Register - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorNotImplemented The feature isn't implemented - * - * \retval ::VmbErrorNotAvailable The feature isn't available currently - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureRawLengthQuery ( const VmbHandle_t handle, - const char* name, - VmbUint32_t* length ); - -/** - * \} \} - */ - -/** - * \name Feature Invalidation - * \{ - * \defgroup FeatureInvalidation Feature Invalidation - * \{ - */ - -/** - * \brief Register a VmbInvalidationCallback callback for feature invalidation signaling. - * - * Any feature change, either of its value or of its access state, may be tracked - * by registering an invalidation callback. - * Registering multiple callbacks for one feature invalidation event is possible because - * only the combination of handle, name, and callback is used as key. If the same - * combination of handle, name, and callback is registered a second time, the callback remains - * registered and the context is overwritten with \p userContext. - * - * \param[in] handle Handle for an entity that emits events - * \param[in] name Name of the event - * \param[in] callback Callback to be run when invalidation occurs - * \param[in] userContext User context passed to function - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorBadParameter If \p name or \p callback are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound No feature with \p name was found for the module associated with \p handle - * - * \retval ::VmbErrorNotImplemented The feature \p name is not implemented - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureInvalidationRegister ( VmbHandle_t handle, - const char* name, - VmbInvalidationCallback callback, - void* userContext ); - -/** - * \brief Unregister a previously registered feature invalidation callback. - * - * Since multiple callbacks may be registered for a feature invalidation event, - * a combination of handle, name, and callback is needed for unregistering, too. - * - * \param[in] handle Handle for an entity that emits events - * \param[in] name Name of the event - * \param[in] callback Callback to be removed - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorBadParameter If \p name or \p callback are null - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound No feature with \p name was found for the module associated with \p handle or there was no listener to unregister - * - * \retval ::VmbErrorNotImplemented The feature \p name is not implemented - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - */ -IMEXPORTC VmbError_t VMB_CALL VmbFeatureInvalidationUnregister ( VmbHandle_t handle, - const char* name, - VmbInvalidationCallback callback ); - -/** - * \} \} - */ - -/** - * \name Image preparation and acquisition - * \{ - * \defgroup Capture Image preparation and acquisition - * \{ - */ - -/** -* \brief Get the necessary payload size for buffer allocation. -* -* Returns the payload size necessary for buffer allocation as queried from the Camera. -* If the stream module provides a PayloadSize feature, this value will be returned instead. -* If a camera handle is passed, the payload size refers to the stream with index 0. -* -* \param[in] handle Camera or stream handle -* \param[out] payloadSize Payload Size -* -* -* \return An error code indicating success or the type of error that occurred. -* -* \retval ::VmbErrorSuccess If no error -* -* \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command -* -* \retval ::VmbErrorBadHandle The given handle is not valid -* -* \retval ::VmbErrorBadParameter \p payloadSize is null -*/ -IMEXPORTC VmbError_t VMB_CALL VmbPayloadSizeGet(VmbHandle_t handle, - VmbUint32_t* payloadSize); - -/** - * \brief Announce frames to the API that may be queued for frame capturing later. - * - * Allows some preparation for frames like DMA preparation depending on the transport layer. - * The order in which the frames are announced is not taken into consideration by the API. - * If frame.buffer is null, the allocation is done by the transport layer. - * - * \param[in] handle Camera or stream handle - * \param[in] frame Frame buffer to announce - * \param[in] sizeofFrame Size of the frame structure - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorStructSize The given struct size is not valid for this version of the API - * - * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given camera handle is not valid - * - * \retval ::VmbErrorBadParameter \p frame is null - * - * \retval ::VmbErrorAlready The frame has already been announced - * - * \retval ::VmbErrorBusy The underlying transport layer does not support announcing frames during acquisition - * - * \retval ::VmbErrorMoreData The given buffer size is invalid (usually 0) - */ -IMEXPORTC VmbError_t VMB_CALL VmbFrameAnnounce ( VmbHandle_t handle, - const VmbFrame_t* frame, - VmbUint32_t sizeofFrame ); - - -/** - * \brief Revoke a frame from the API. - * - * The referenced frame is removed from the pool of frames for capturing images. - * - * \param[in] handle Handle for a camera or stream - * \param[in] frame Frame buffer to be removed from the list of announced frames - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorBadParameter The given frame pointer is not valid - * - * \retval ::VmbErrorBusy The underlying transport layer does not support revoking frames during acquisition - * - * \retval ::VmbErrorNotFound The given frame could not be found for the stream - * - * \retval ::VmbErrorInUse The frame is currently still in use (e.g. in a running frame callback) - */ -IMEXPORTC VmbError_t VMB_CALL VmbFrameRevoke ( VmbHandle_t handle, - const VmbFrame_t* frame ); - - -/** - * \brief Revoke all frames assigned to a certain stream or camera. - * - * In case of an failure some of the frames may have been revoked. To prevent this it is recommended to call - * ::VmbCaptureQueueFlush for the same handle before invoking this function. - * - * \param[in] handle Handle for a stream or camera - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle \p handle is not valid - * - * \retval ::VmbErrorInUse One of the frames of the stream is still in use - */ -IMEXPORTC VmbError_t VMB_CALL VmbFrameRevokeAll ( VmbHandle_t handle ); - - -/** - * \brief Prepare the API for incoming frames. - * - * \param[in] handle Handle for a camera or a stream - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid; this includes the camera no longer being open - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorMoreData The buffer size of the announced frames is insufficient - * - * \retval ::VmbErrorInsufficientBufferCount The operation requires more buffers to be announced; see the StreamAnnounceBufferMinimum stream feature - * - * \retval ::VmbErrorAlready Capturing was already started - */ -IMEXPORTC VmbError_t VMB_CALL VmbCaptureStart ( VmbHandle_t handle ); - - -/** - * \brief Stop the API from being able to receive frames. - * - * Consequences of VmbCaptureEnd(): - * The frame callback will not be called anymore - * - * \note This function waits for the completion of the last callback for the current capture. - * If the callback does not return in finite time, this function may not return in finite time either. - * - * \param[in] handle Handle for a stream or camera - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorInvalidCall If called from a frame callback or a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle \p handle is not valid - */ -IMEXPORTC VmbError_t VMB_CALL VmbCaptureEnd ( VmbHandle_t handle ); - - -/** - * \brief Queue frames that may be filled during frame capturing. - * - * The given frame is put into a queue that will be filled sequentially. - * The order in which the frames are filled is determined by the order in which they are queued. - * If the frame was announced with ::VmbFrameAnnounce() before, the application - * has to ensure that the frame is also revoked by calling ::VmbFrameRevoke() or - * ::VmbFrameRevokeAll() when cleaning up. - * - * \warning \p callback should to return in finite time. Otherwise ::VmbCaptureEnd and - * operations resulting in the stream being closed may not return. - * - * \param[in] handle Handle of a camera or stream - * \param[in] frame Pointer to an already announced frame - * \param[in] callback Callback to be run when the frame is complete. Null is OK. - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorBadParameter If \p frame is null - * - * \retval ::VmbErrorBadHandle No stream related to \p handle could be found - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInternalFault The buffer or bufferSize members of \p frame have been set to null or zero respectively - * - * \retval ::VmbErrorNotFound The frame is not a frame announced for the given stream - * - * \retval ::VmbErrorAlready The frame is currently queued - */ -IMEXPORTC VmbError_t VMB_CALL VmbCaptureFrameQueue ( VmbHandle_t handle, - const VmbFrame_t* frame, - VmbFrameCallback callback ); - -/** - * \brief Wait for a queued frame to be filled (or dequeued). - * - * The frame needs to be queued and not filled for the function to complete successfully. - * - * If a camera handle is passed, the first stream of the camera is used. - * - * \param[in] handle Handle of a camera or stream - * \param[in] frame Pointer to an already announced and queued frame - * \param[in] timeout Timeout (in milliseconds) - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorBadParameter If \p frame or the buffer of \p frame are null or the the buffer size of \p frame is 0 - * - * \retval ::VmbErrorBadHandle No stream related to \p handle could be found - * - * \retval ::VmbErrorNotFound The frame is not one currently queued for the stream - * - * \retval ::VmbErrorAlready The frame has already been dequeued or VmbCaptureFrameWait has been called already for this frame - * - * \retval ::VmbErrorInUse If the frame was queued with a frame callback - * - * \retval ::VmbErrorTimeout Call timed out - * - * \retval ::VmbErrorIncomplete Capture is not active when the function is called - */ -IMEXPORTC VmbError_t VMB_CALL VmbCaptureFrameWait ( const VmbHandle_t handle, - const VmbFrame_t* frame, - VmbUint32_t timeout); - - -/** - * \brief Flush the capture queue. - * - * Control of all the currently queued frames will be returned to the user, - * leaving no frames in the capture queue. - * After this call, no frame notification will occur until frames are queued again - * - * Frames need to be revoked separately, if desired. - * - * This function can only succeeds, if no capture is currently active. - * If ::VmbCaptureStart has been called for the stream, but no successful call to ::VmbCaptureEnd - * happened, the function fails with error code ::VmbErrorInUse. - * - * \param[in] handle The handle of the camera or stream to flush. - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorBadHandle No stream related to \p handle could be found. - * - * \retval ::VmbErrorInUse There is currently an active capture - */ -IMEXPORTC VmbError_t VMB_CALL VmbCaptureQueueFlush(VmbHandle_t handle); - -/** - * \} \} - */ - -/** - * \name Transport Layer Enumeration & Information - * \{ - * \defgroup TransportLayer Transport Layer Enumeration & Information - * \{ - */ - -/** - * \brief List all the transport layers that are used by the API. - * - * Note: This function is usually called twice: once with an empty array to query the length - * of the list, and then again with an array of the correct length. - * - * \param[in,out] transportLayerInfo Array of VmbTransportLayerInfo_t, allocated by the caller. - * The transport layer list is copied here. May be null. - * \param[in] listLength Number of entries in the caller's transportLayerInfo array. - * \param[in,out] numFound Number of transport layers found. May be more than listLength. - * \param[in] sizeofTransportLayerInfo Size of one ::VmbTransportLayerInfo_t entry (ignored if \p transportLayerInfo is null). - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInternalFault An internal fault occurred - * - * \retval ::VmbErrorNotImplemented One of the transport layers does not provide the required information - * - * \retval ::VmbErrorBadParameter \p numFound is null - * - * \retval ::VmbErrorStructSize The given struct size is not valid for this API version - * - * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries - */ -IMEXPORTC VmbError_t VMB_CALL VmbTransportLayersList ( VmbTransportLayerInfo_t* transportLayerInfo, - VmbUint32_t listLength, - VmbUint32_t* numFound, - VmbUint32_t sizeofTransportLayerInfo); - -/** - * \} \} -*/ - -/** - * \name Interface Enumeration & Information - * \{ - * \defgroup Interface Interface Enumeration & Information - * \{ - */ - -/** - * \brief List all the interfaces that are currently visible to the API. - * - * Note: All the interfaces known via GenICam transport layers are listed by this - * command and filled into the provided array. Interfaces may correspond to - * adapter cards or frame grabber cards. - * This function is usually called twice: once with an empty array to query the length - * of the list, and then again with an array of the correct length. - * - * \param[in,out] interfaceInfo Array of ::VmbInterfaceInfo_t, allocated by the caller. - * The interface list is copied here. May be null. - * - * \param[in] listLength Number of entries in the callers interfaceInfo array - * - * \param[in,out] numFound Number of interfaces found. Can be more than listLength - * - * \param[in] sizeofInterfaceInfo Size of one ::VmbInterfaceInfo_t entry - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p numFound is null - * - * \retval ::VmbErrorStructSize The given struct size is not valid for this API version - * - * \retval ::VmbErrorMoreData The given list length was insufficient to hold all available entries - */ -IMEXPORTC VmbError_t VMB_CALL VmbInterfacesList ( VmbInterfaceInfo_t* interfaceInfo, - VmbUint32_t listLength, - VmbUint32_t* numFound, - VmbUint32_t sizeofInterfaceInfo ); - -/** - * \} \} - */ - -/** - * \name Direct Access - * \{ - * \defgroup DirectAccess Direct Access - * \{ - */ - -//----- Memory/Register access -------------------------------------------- - -/** - * \brief Read an array of bytes. - * - * \param[in] handle Handle for an entity that allows memory access - * \param[in] address Address to be used for this read operation - * \param[in] bufferSize Size of the data buffer to read - * \param[out] dataBuffer Buffer to be filled - * \param[out] sizeComplete Size of the data actually read - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - */ -IMEXPORTC VmbError_t VMB_CALL VmbMemoryRead ( const VmbHandle_t handle, - VmbUint64_t address, - VmbUint32_t bufferSize, - char* dataBuffer, - VmbUint32_t* sizeComplete ); - -/** - * \brief Write an array of bytes. - * - * \param[in] handle Handle for an entity that allows memory access - * \param[in] address Address to be used for this read operation - * \param[in] bufferSize Size of the data buffer to write - * \param[in] dataBuffer Data to write - * \param[out] sizeComplete Number of bytes successfully written; if an - * error occurs this is less than bufferSize - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorMoreData Not all data were written; see sizeComplete value for the number of bytes written - */ -IMEXPORTC VmbError_t VMB_CALL VmbMemoryWrite ( const VmbHandle_t handle, - VmbUint64_t address, - VmbUint32_t bufferSize, - const char* dataBuffer, - VmbUint32_t* sizeComplete ); - -/** - * \} \} - */ - -/** - * \name Load & Save Settings - * \{ - * \defgroup LoadSaveSettings Load & Save Settings - * \{ - */ - -/** - * \brief Write the current features related to a module to a xml file - * - * Camera must be opened beforehand and function needs corresponding handle. - * With given filename parameter path and name of XML file can be determined. - * Additionally behaviour of function can be set with providing 'persistent struct'. - * - * \param[in] handle Handle for an entity that allows register access - * \param[in] filePath The path to the file to save the settings to; relative paths are relative to the current working directory - * \param[in] settings Settings struct; if null the default settings are used - * (persist features except LUT for the remote device, maximum 5 iterations, logging only errors) - * \param[in] sizeofSettings Size of settings struct - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorBadParameter If \p filePath is or the settings struct is invalid - * - * \retval ::VmbErrorStructSize If sizeofSettings the struct size does not match the size of the struct expected by the API - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorNotFound The provided handle is insufficient to identify all the modules that should be saved - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorIO There was an issue writing the file. - */ -IMEXPORTC VmbError_t VMB_CALL VmbSettingsSave(VmbHandle_t handle, - const VmbFilePathChar_t* filePath, - const VmbFeaturePersistSettings_t* settings, - VmbUint32_t sizeofSettings); - -/** - * \brief Load all feature values from xml file to device-related modules. - * - * The modules must be opened beforehand. If the handle is non-null it must be a valid handle other than the Vmb API handle. - * Additionally behaviour of function can be set with providing \p settings . Note that even in case of an failure some or all of the features - * may have been set for some of the modules. - * - * The error code ::VmbErrorRetriesExceeded only indicates that the number of retries was insufficient - * to restore the features. Even if the features could not be restored for one of the modules, restoring the features is not aborted but the process - * continues for other modules, if present. - * - * \param[in] handle Handle related to the modules to write the values to; - * may be null to indicate that modules should be identified based on the information provided in the input file - * - * \param[in] filePath The path to the file to load the settings from; relative paths are relative to the current working directory - * \param[in] settings Settings struct; pass null to use the default settings. If the \p maxIterations field is 0, the number of - * iterations is determined by the value loaded from the xml file - * \param[in] sizeofSettings Size of the settings struct - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess If no error - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback - * - * \retval ::VmbErrorStructSize If sizeofSettings the struct size does not match the size of the struct expected by the API - * - * \retval ::VmbErrorWrongType \p handle is neither null nor a transport layer, interface, local device, remote device or stream handle - * - * \retval ::VmbErrorBadHandle The given handle is not valid - * - * \retval ::VmbErrorAmbiguous The modules to restore the settings for cannot be uniquely identified based on the information available - * - * \retval ::VmbErrorNotFound The provided handle is insufficient to identify all the modules that should be restored - * - * \retval ::VmbErrorRetriesExceeded Some or all of the features could not be restored with the max iterations specified - * - * \retval ::VmbErrorInvalidAccess Operation is invalid with the current access mode - * - * \retval ::VmbErrorBadParameter If \p filePath is null or the settings struct is invalid - * - * \retval ::VmbErrorIO There was an issue with reading the file. - */ -IMEXPORTC VmbError_t VMB_CALL VmbSettingsLoad(VmbHandle_t handle, - const VmbFilePathChar_t* filePath, - const VmbFeaturePersistSettings_t* settings, - VmbUint32_t sizeofSettings); - -/** - * \} \} - */ - -/** - * \name Chunk Data - * \{ - * \defgroup ChunkData Chunk Data - * \{ - */ - -/** - * \brief Access chunk data for a frame. - * - * This function can only succeed if the given frame has been filled by the API. - * - * \param[in] frame A pointer to a filled frame that is announced - * \param[in] chunkAccessCallback A callback to access the chunk data from - * \param[in] userContext A pointer to pass to the callback - * - * - * \return An error code indicating success or the type of error that occurred. - * - * \retval ::VmbErrorSuccess The call was successful - * - * \retval ::VmbErrorInvalidCall If called from a chunk access callback or a feature callback - * - * \retval ::VmbErrorApiNotStarted ::VmbStartup() was not called before the current command - * - * \retval ::VmbErrorBadParameter \p frame or \p chunkAccessCallback are null - * - * \retval ::VmbErrorInUse The frame state does not allow for retrieval of chunk data - * (e.g. the frame could have been reenqueued before the chunk access could happen). - * - * \retval ::VmbErrorNotFound The frame is currently not announced for a stream - * - * \retval ::VmbErrorDeviceNotOpen If the device the frame was received from is no longer open - * - * \retval ::VmbErrorNoChunkData \p frame does not contain chunk data - * - * \retval ::VmbErrorParsingChunkData The chunk data does not adhere to the expected format - * - * \retval ::VmbErrorUserCallbackException The callback threw an exception - * - * \retval ::VmbErrorFeaturesUnavailable The feature description for the remote device is unavailable - * - * \retval ::VmbErrorCustom The minimum a user defined error code returned by the callback - */ -IMEXPORTC VmbError_t VMB_CALL VmbChunkDataAccess(const VmbFrame_t* frame, - VmbChunkAccessCallback chunkAccessCallback, - void* userContext); - -/** - * \} \} \} - */ -#ifdef __cplusplus -} -#endif - -#endif // VMBC_H_INCLUDE_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCTypeDefinitions.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCTypeDefinitions.h deleted file mode 100644 index b010d5be6..000000000 --- a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCTypeDefinitions.h +++ /dev/null @@ -1,610 +0,0 @@ -/*============================================================================= - Copyright (C) 2012 - 2021 Allied Vision Technologies. All Rights Reserved. - - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. - -------------------------------------------------------------------------------- - - File: VmbCTypeDefinitions.h - -------------------------------------------------------------------------------- - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, - NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -=============================================================================*/ - -/** - * \file - * \brief Struct definitions for the VmbC API. - */ - -#ifndef VMBC_TYPE_DEFINITIONS_H_INCLUDE_ -#define VMBC_TYPE_DEFINITIONS_H_INCLUDE_ - -#include -#include - -#include - -#if defined (_WIN32) -#if defined AVT_VMBAPI_C_EXPORTS // DLL exports -#define IMEXPORTC // We export via the .def file -#elif defined AVT_VMBAPI_C_LIB // static LIB -#define IMEXPORTC -#else // import -#define IMEXPORTC __declspec(dllimport) -#endif - -#ifndef _WIN64 - // Calling convention -#define VMB_CALL __stdcall -#else - // Calling convention -#define VMB_CALL -#endif -#elif defined (__GNUC__) && (__GNUC__ >= 4) && defined (__ELF__) - // SO exports (requires compiler option -fvisibility=hidden) -#ifdef AVT_VMBAPI_C_EXPORTS -#define IMEXPORTC __attribute__((visibility("default"))) -#else -#define IMEXPORTC -#endif - -#ifdef __i386__ - // Calling convention -#define VMB_CALL __attribute__((stdcall)) -#else - // Calling convention -#define VMB_CALL -#endif -#elif defined (__APPLE__) -#define IMEXPORTC __attribute__((visibility("default"))) - // Calling convention -#define VMB_CALL -#else -#error Unknown platform, file needs adaption -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \name Transport layer - * \{ - */ - - /** -* \brief Camera or transport layer type (for instance U3V or GEV). -*/ -typedef enum VmbTransportLayerType -{ - VmbTransportLayerTypeUnknown = 0, //!< Interface is not known to this version of the API - VmbTransportLayerTypeGEV = 1, //!< GigE Vision - VmbTransportLayerTypeCL = 2, //!< Camera Link - VmbTransportLayerTypeIIDC = 3, //!< IIDC 1394 - VmbTransportLayerTypeUVC = 4, //!< USB video class - VmbTransportLayerTypeCXP = 5, //!< CoaXPress - VmbTransportLayerTypeCLHS = 6, //!< Camera Link HS - VmbTransportLayerTypeU3V = 7, //!< USB3 Vision Standard - VmbTransportLayerTypeEthernet = 8, //!< Generic Ethernet - VmbTransportLayerTypePCI = 9, //!< PCI / PCIe - VmbTransportLayerTypeCustom = 10, //!< Non standard - VmbTransportLayerTypeMixed = 11, //!< Mixed (transport layer only) -} VmbTransportLayerType; - -/** - * \brief Type for an Interface; for values see ::VmbTransportLayerType. - */ -typedef VmbUint32_t VmbTransportLayerType_t; - -/** - * \brief Transport layer information. - * - * Holds read-only information about a transport layer. - */ -typedef struct VmbTransportLayerInfo -{ - /** - * \name Out - * \{ - */ - - const char* transportLayerIdString; //!< Unique id of the transport layer - const char* transportLayerName; //!< Name of the transport layer - const char* transportLayerModelName; //!< Model name of the transport layer - const char* transportLayerVendor; //!< Vendor of the transport layer - const char* transportLayerVersion; //!< Version of the transport layer - const char* transportLayerPath; //!< Full path of the transport layer - VmbHandle_t transportLayerHandle; //!< Handle of the transport layer for feature access - VmbTransportLayerType_t transportLayerType; //!< The type of the transport layer - - /** - * \} - */ -} VmbTransportLayerInfo_t; - -/** - * \} - */ - -/** - * \name Interface - * \{ - */ - -/** - * \brief Interface information. - * - * Holds read-only information about an interface. - */ -typedef struct VmbInterfaceInfo -{ - /** - * \name Out - * \{ - */ - - const char* interfaceIdString; //!< Identifier of the interface - const char* interfaceName; //!< Interface name, given by the transport layer - VmbHandle_t interfaceHandle; //!< Handle of the interface for feature access - VmbHandle_t transportLayerHandle; //!< Handle of the related transport layer for feature access - VmbTransportLayerType_t interfaceType; //!< The technology of the interface - - /** - * \} - */ -} VmbInterfaceInfo_t; - -/** - * \} - */ - -/** - * \name Camera - * \{ - */ - - /** - * \brief Access mode for cameras. - * - * Used in ::VmbCameraInfo_t as flags, so multiple modes can be - * announced, while in ::VmbCameraOpen(), no combination must be used. - */ -typedef enum VmbAccessModeType -{ - VmbAccessModeNone = 0, //!< No access - VmbAccessModeFull = 1, //!< Read and write access - VmbAccessModeRead = 2, //!< Read-only access - VmbAccessModeUnknown = 4, //!< Access type unknown - VmbAccessModeExclusive = 8, //!< Read and write access without permitting access for other consumers -} VmbAccessModeType; - -/** - * \brief Type for an AccessMode; for values see ::VmbAccessModeType. - */ -typedef VmbUint32_t VmbAccessMode_t; - -/** - * \brief Camera information. - * - * Holds read-only information about a camera. - */ -typedef struct VmbCameraInfo -{ - /** - * \name Out - * \{ - */ - - const char* cameraIdString; //!< Identifier of the camera - const char* cameraIdExtended; //!< globally unique identifier for the camera - const char* cameraName; //!< The display name of the camera - const char* modelName; //!< Model name - const char* serialString; //!< Serial number - VmbHandle_t transportLayerHandle; //!< Handle of the related transport layer for feature access - VmbHandle_t interfaceHandle; //!< Handle of the related interface for feature access - VmbHandle_t localDeviceHandle; //!< Handle of the related GenTL local device. NULL if the camera is not opened - VmbHandle_t const* streamHandles; //!< Handles of the streams provided by the camera. NULL if the camera is not opened - VmbUint32_t streamCount; //!< Number of stream handles in the streamHandles array - VmbAccessMode_t permittedAccess; //!< Permitted access modes, see ::VmbAccessModeType - - /** - * \} - */ -} VmbCameraInfo_t; - -/** - * \} - */ - -/** - * \name Feature - * \{ - */ - -/** - * \brief Supported feature data types. - */ -typedef enum VmbFeatureDataType -{ - VmbFeatureDataUnknown = 0, //!< Unknown feature type - VmbFeatureDataInt = 1, //!< 64-bit integer feature - VmbFeatureDataFloat = 2, //!< 64-bit floating point feature - VmbFeatureDataEnum = 3, //!< Enumeration feature - VmbFeatureDataString = 4, //!< String feature - VmbFeatureDataBool = 5, //!< Boolean feature - VmbFeatureDataCommand = 6, //!< Command feature - VmbFeatureDataRaw = 7, //!< Raw (direct register access) feature - VmbFeatureDataNone = 8, //!< Feature with no data -} VmbFeatureDataType; - -/** - * \brief Data type for a Feature; for values see ::VmbFeatureDataType. - */ -typedef VmbUint32_t VmbFeatureData_t; - -/** - * \brief Feature visibility. - */ -typedef enum VmbFeatureVisibilityType -{ - VmbFeatureVisibilityUnknown = 0, //!< Feature visibility is not known - VmbFeatureVisibilityBeginner = 1, //!< Feature is visible in feature list (beginner level) - VmbFeatureVisibilityExpert = 2, //!< Feature is visible in feature list (expert level) - VmbFeatureVisibilityGuru = 3, //!< Feature is visible in feature list (guru level) - VmbFeatureVisibilityInvisible = 4, //!< Feature is visible in the feature list, but should be hidden in GUI applications -} VmbFeatureVisibilityType; - -/** - * \brief Type for Feature visibility; for values see ::VmbFeatureVisibilityType. - */ -typedef VmbUint32_t VmbFeatureVisibility_t; - -/** - * \brief Feature flags. - */ -typedef enum VmbFeatureFlagsType -{ - VmbFeatureFlagsNone = 0, //!< No additional information is provided - VmbFeatureFlagsRead = 1, //!< Static info about read access. Current status depends on access mode, check with ::VmbFeatureAccessQuery() - VmbFeatureFlagsWrite = 2, //!< Static info about write access. Current status depends on access mode, check with ::VmbFeatureAccessQuery() - VmbFeatureFlagsVolatile = 8, //!< Value may change at any time - VmbFeatureFlagsModifyWrite = 16, //!< Value may change after a write -} VmbFeatureFlagsType; - -/** - * \brief Type for Feature flags; for values see ::VmbFeatureFlagsType. - */ -typedef VmbUint32_t VmbFeatureFlags_t; - -/** - * \brief Feature information. - * - * Holds read-only information about a feature. - */ -typedef struct VmbFeatureInfo -{ - /** - * \name Out - * \{ - */ - - const char* name; //!< Name used in the API - const char* category; //!< Category this feature can be found in - const char* displayName; //!< Feature name to be used in GUIs - const char* tooltip; //!< Short description, e.g. for a tooltip - const char* description; //!< Longer description - const char* sfncNamespace; //!< Namespace this feature resides in - const char* unit; //!< Measuring unit as given in the XML file - const char* representation; //!< Representation of a numeric feature - VmbFeatureData_t featureDataType; //!< Data type of this feature - VmbFeatureFlags_t featureFlags; //!< Access flags for this feature - VmbUint32_t pollingTime; //!< Predefined polling time for volatile features - VmbFeatureVisibility_t visibility; //!< GUI visibility - VmbBool_t isStreamable; //!< Indicates if a feature can be stored to / loaded from a file - VmbBool_t hasSelectedFeatures; //!< Indicates if the feature selects other features - - /** - * \} - */ -} VmbFeatureInfo_t; - -/** - * \brief Info about possible entries of an enumeration feature. - */ -typedef struct VmbFeatureEnumEntry -{ - /** - * \name Out - * \{ - */ - - const char* name; //!< Name used in the API - const char* displayName; //!< Enumeration entry name to be used in GUIs - const char* tooltip; //!< Short description, e.g. for a tooltip - const char* description; //!< Longer description - VmbInt64_t intValue; //!< Integer value of this enumeration entry - const char* sfncNamespace; //!< Namespace this feature resides in - VmbFeatureVisibility_t visibility; //!< GUI visibility - - /** - * \} - */ -} VmbFeatureEnumEntry_t; - -/** - * \} - */ - -/** - * \name Frame - * \{ - */ - -/** - * \brief Status of a frame transfer. - */ -typedef enum VmbFrameStatusType -{ - VmbFrameStatusComplete = 0, //!< Frame has been completed without errors - VmbFrameStatusIncomplete = -1, //!< Frame could not be filled to the end - VmbFrameStatusTooSmall = -2, //!< Frame buffer was too small - VmbFrameStatusInvalid = -3, //!< Frame buffer was invalid -} VmbFrameStatusType; - -/** - * \brief Type for the frame status; for values see ::VmbFrameStatusType. - */ -typedef VmbInt32_t VmbFrameStatus_t; - -/** - * \brief Frame flags. - */ -typedef enum VmbFrameFlagsType -{ - VmbFrameFlagsNone = 0, //!< No additional information is provided - VmbFrameFlagsDimension = 1, //!< VmbFrame_t::width and VmbFrame_t::height are provided - VmbFrameFlagsOffset = 2, //!< VmbFrame_t::offsetX and VmbFrame_t::offsetY are provided (ROI) - VmbFrameFlagsFrameID = 4, //!< VmbFrame_t::frameID is provided - VmbFrameFlagsTimestamp = 8, //!< VmbFrame_t::timestamp is provided - VmbFrameFlagsImageData = 16, //!< VmbFrame_t::imageData is provided - VmbFrameFlagsPayloadType = 32, //!< VmbFrame_t::payloadType is provided - VmbFrameFlagsChunkDataPresent = 64, //!< VmbFrame_t::chunkDataPresent is set based on info provided by the transport layer -} VmbFrameFlagsType; - -/** - * \brief Type for Frame flags; for values see ::VmbFrameFlagsType. - */ -typedef VmbUint32_t VmbFrameFlags_t; - -/** - * \brief Frame payload type. - */ -typedef enum VmbPayloadType -{ - VmbPayloadTypeUnknown = 0, //!< Unknown payload type - VmbPayloadTypeImage = 1, //!< image data - VmbPayloadTypeRaw = 2, //!< raw data - VmbPayloadTypeFile = 3, //!< file data - VmbPayloadTypeJPEG = 5, //!< JPEG data as described in the GigEVision 2.0 specification - VmbPayloadTypJPEG2000 = 6, //!< JPEG 2000 data as described in the GigEVision 2.0 specification - VmbPayloadTypeH264 = 7, //!< H.264 data as described in the GigEVision 2.0 specification - VmbPayloadTypeChunkOnly = 8, //!< Chunk data exclusively - VmbPayloadTypeDeviceSpecific = 9, //!< Device specific data format - VmbPayloadTypeGenDC = 11, //!< GenDC data -} VmbPayloadType; - -/** - * \brief Type representing the payload type of a frame. For values see ::VmbPayloadType. - */ -typedef VmbUint32_t VmbPayloadType_t; - -/** - * \brief Type used to represent a dimension value, e.g. the image height. - */ -typedef VmbUint32_t VmbImageDimension_t; - -/** - * \brief Frame delivered by the camera. - */ -typedef struct VmbFrame -{ - /** - * \name In - * \{ - */ - - void* buffer; //!< Comprises image and potentially chunk data - VmbUint32_t bufferSize; //!< The size of the data buffer - void* context[4]; //!< 4 void pointers that can be employed by the user (e.g. for storing handles) - - /** - * \} - */ - - /** - * \name Out - * \{ - */ - - VmbFrameStatus_t receiveStatus; //!< The resulting status of the receive operation - VmbUint64_t frameID; //!< Unique ID of this frame in this stream - VmbUint64_t timestamp; //!< The timestamp set by the camera - VmbUint8_t* imageData; //!< The start of the image data, if present, or null - VmbFrameFlags_t receiveFlags; //!< Flags indicating which additional frame information is available - VmbPixelFormat_t pixelFormat; //!< Pixel format of the image - VmbImageDimension_t width; //!< Width of an image - VmbImageDimension_t height; //!< Height of an image - VmbImageDimension_t offsetX; //!< Horizontal offset of an image - VmbImageDimension_t offsetY; //!< Vertical offset of an image - VmbPayloadType_t payloadType; //!< The type of payload - VmbBool_t chunkDataPresent; //!< True if the transport layer reported chunk data to be present in the buffer - - /** - * \} - */ -} VmbFrame_t; - -/** - * \} - */ - -/** - * \name Save/LoadSettings - * \{ - */ - -/** - * \brief Type of features that are to be saved (persisted) to the XML file when using ::VmbSettingsSave - */ -typedef enum VmbFeaturePersistType -{ - VmbFeaturePersistAll = 0, //!< Save all features to XML, including look-up tables (if possible) - VmbFeaturePersistStreamable = 1, //!< Save only features marked as streamable, excluding look-up tables - VmbFeaturePersistNoLUT = 2 //!< Save all features except look-up tables (default) -} VmbFeaturePersistType; - -/** - * \brief Type for feature persistence; for values see ::VmbFeaturePersistType. - */ -typedef VmbUint32_t VmbFeaturePersist_t; - -/** - * \brief Parameters determining the operation mode of ::VmbSettingsSave and ::VmbSettingsLoad. - */ -typedef enum VmbModulePersistFlagsType -{ - VmbModulePersistFlagsNone = 0x00, //!< Persist/Load features for no module. - VmbModulePersistFlagsTransportLayer = 0x01, //!< Persist/Load the transport layer features. - VmbModulePersistFlagsInterface = 0x02, //!< Persist/Load the interface features. - VmbModulePersistFlagsRemoteDevice = 0x04, //!< Persist/Load the remote device features. - VmbModulePersistFlagsLocalDevice = 0x08, //!< Persist/Load the local device features. - VmbModulePersistFlagsStreams = 0x10, //!< Persist/Load the features of stream modules. - VmbModulePersistFlagsAll = 0xff //!< Persist/Load features for all modules. -} VmbModulePersistFlagsType; - -/** - * \brief Type for module persist flags; for values see VmbModulePersistFlagsType - * - * Use a combination of ::VmbModulePersistFlagsType constants - */ -typedef VmbUint32_t VmbModulePersistFlags_t; - -/** - * \brief A level to use for logging - */ -typedef enum VmbLogLevel -{ - VmbLogLevelNone = 0, //!< Nothing is logged regardless of the severity of the issue - VmbLogLevelError, //!< Only errors are logged - VmbLogLevelDebug, //!< Only error and debug messages are logged - VmbLogLevelWarn, //!< Only error, debug and warn messages are logged - VmbLogLevelTrace, //!< all messages are logged - VmbLogLevelAll = VmbLogLevelTrace, //!< all messages are logged -} VmbLogLevel; - -/** - * \brief The type used for storing the log level - * - * Use a constant from ::VmbLogLevel - */ -typedef VmbUint32_t VmbLogLevel_t; - -/** - * \brief Parameters determining the operation mode of ::VmbSettingsSave and ::VmbSettingsLoad - */ -typedef struct VmbFeaturePersistSettings -{ - /** - * \name In - * \{ - */ - - VmbFeaturePersist_t persistType; //!< Type of features that are to be saved - VmbModulePersistFlags_t modulePersistFlags; //!< Flags specifying the modules to persist/load - VmbUint32_t maxIterations; //!< Number of iterations when loading settings - VmbLogLevel_t loggingLevel; //!< Determines level of detail for load/save settings logging - - /** - * \} - */ -} VmbFeaturePersistSettings_t; - -/** - * \} - */ - -/** - * \name Callbacks - * \{ - */ - -/** - * \brief Invalidation callback type for a function that gets called in a separate thread - * and has been registered with ::VmbFeatureInvalidationRegister(). - * - * While the callback is run, all feature data is atomic. After the callback finishes, - * the feature data may be updated with new values. - * - * Do not spend too much time in this thread; it prevents the feature values - * from being updated from any other thread or the lower-level drivers. - * - * \param[in] handle Handle for an entity that exposes features - * \param[in] name Name of the feature - * \param[in] userContext Pointer to the user context, see ::VmbFeatureInvalidationRegister - */ -typedef void (VMB_CALL* VmbInvalidationCallback)(const VmbHandle_t handle, const char* name, void* userContext); - -/** - * \brief Frame Callback type for a function that gets called in a separate thread - * if a frame has been queued with ::VmbCaptureFrameQueue. - * - * \warning Any operations closing the stream including ::VmbShutdown and ::VmbCameraClose in addition to - * ::VmbCaptureEnd block until any currently active callbacks return. If the callback does not - * return in finite time, the program may not return. - * - * \param[in] cameraHandle Handle of the camera the frame belongs to - * \param[in] streamHandle Handle of the stream the frame belongs to - * \param[in] frame The received frame - */ -typedef void (VMB_CALL* VmbFrameCallback)(const VmbHandle_t cameraHandle, const VmbHandle_t streamHandle, VmbFrame_t* frame); - -/** - * \brief Function pointer type to access chunk data - * - * This function should complete as quickly as possible, since it blocks other updates on the - * remote device. - * - * This function should not throw exceptions, even if VmbC is used from C++. Any exception - * thrown will only result in an error code indicating that an exception was thrown. - * - * \param[in] featureAccessHandle A special handle that can be used for accessing features; - * the handle is only valid during the call of the function. - * \param[in] userContext The value the user passed to ::VmbChunkDataAccess. - * - * \return An error to be returned from ::VmbChunkDataAccess in the absence of other errors; - * A custom exit code >= ::VmbErrorCustom can be returned to indicate a failure via - * ::VmbChunkDataAccess return code - */ -typedef VmbError_t(VMB_CALL* VmbChunkAccessCallback)(VmbHandle_t featureAccessHandle, void* userContext); - -/** - * \} - */ - -#ifdef __cplusplus -} -#endif - -#endif // VMBC_TYPE_DEFINITIONS_H_INCLUDE_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCommonTypes.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCommonTypes.h deleted file mode 100644 index 7e3615472..000000000 --- a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbCommonTypes.h +++ /dev/null @@ -1,444 +0,0 @@ -/*============================================================================= - Copyright (C) 2012 - 2021 Allied Vision Technologies. All Rights Reserved. - - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. - -------------------------------------------------------------------------------- - - File: VmbCommonTypes.h - -------------------------------------------------------------------------------- - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, - NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -=============================================================================*/ - -/** - * \file - * \brief Main header file for the common types of the APIs. - * - * This file describes all necessary definitions for types used within - * the Vmb APIs. These type definitions are designed to be - * portable from other languages and other operating systems. - */ - -#ifndef VMBCOMMONTYPES_H_INCLUDE_ -#define VMBCOMMONTYPES_H_INCLUDE_ - -#ifdef _WIN32 -# include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \name Basic Types - * \{ - */ - -#if defined (_MSC_VER) - - /** - * \brief 8-bit signed integer. - */ - typedef __int8 VmbInt8_t; - - /** - * \brief 8-bit unsigned integer. - */ - typedef unsigned __int8 VmbUint8_t; - - /** - * \brief 16-bit signed integer. - */ - typedef __int16 VmbInt16_t; - - /** - * \brief 16-bit unsigned integer. - */ - typedef unsigned __int16 VmbUint16_t; - - /** - * \brief 32-bit signed integer. - */ - typedef __int32 VmbInt32_t; - - /** - * \brief 32-bit unsigned integer. - */ - typedef unsigned __int32 VmbUint32_t; - - /** - * \brief 64-bit signed integer. - */ - typedef __int64 VmbInt64_t; - - /** - * \brief 64-bit unsigned integer. - */ - typedef unsigned __int64 VmbUint64_t; - -#else - - /** - * \brief 8-bit signed integer. - */ - typedef signed char VmbInt8_t; - - /** - * \brief 8-bit unsigned integer. - */ - typedef unsigned char VmbUint8_t; - - /** - * \brief 16-bit signed integer. - */ - typedef short VmbInt16_t; - - /** - * \brief 16-bit unsigned integer. - */ - typedef unsigned short VmbUint16_t; - - /** - * \brief 32-bit signed integer. - */ - typedef int VmbInt32_t; - - /** - * \brief 32-bit unsigned integer. - */ - typedef unsigned int VmbUint32_t; - - /** - * \brief 64-bit signed integer. - */ - typedef long long VmbInt64_t; - - /** - * \brief 64-bit unsigned integer. - */ - typedef unsigned long long VmbUint64_t; - -#endif - - /** - * \brief Handle, e.g. for a camera. - */ - typedef void* VmbHandle_t; - -#if defined(__cplusplus) || defined(__bool_true_false_are_defined) - - /** - * \brief Standard type for boolean values. - */ - typedef bool VmbBool_t; - -#else - - /** - * \brief Boolean type (equivalent to char). - * - * For values see ::VmbBoolVal - */ - typedef char VmbBool_t; - -#endif - - /** - * \brief enum for bool values. - */ - typedef enum VmbBoolVal - { - VmbBoolTrue = 1, - VmbBoolFalse = 0, - } VmbBoolVal; - - /** - * \brief char type. - */ - typedef unsigned char VmbUchar_t; - -#ifdef _WIN32 - - /** - * \brief Character type used for file paths (Windows uses wchar_t not char). - */ - typedef wchar_t VmbFilePathChar_t; - - /** - * \brief macro for converting a c string literal into a system dependent string literal - * - * Adds L as prefix on Windows and is replaced by the unmodified value on other operating systems. - * - * \code{.c} - * const VmbFilePathChar_t* path = VMB_FILE_PATH_LITERAL("./some/path/tl.cti"); - * \endcode - */ -# define VMB_FILE_PATH_LITERAL(value) L##value - -#else - - /** - * Character type used for file paths - */ - typedef char VmbFilePathChar_t; - - /** - * \brief macro for converting a c string literal into a system dependent string literal - * - * Adds L as prefix on Windows and is replaced by the unmodified value on other operating systems. - * - * \code{.c} - * const VmbFilePathChar_t* path = VMB_FILE_PATH_LITERAL("./some/path/tl.cti"); - * \endcode - */ -# define VMB_FILE_PATH_LITERAL(value) value -#endif - -/** - * \} - */ - -/** - * \name Error Codes - * \{ - */ - - /** - * \brief Error codes, returned by most functions. - */ - typedef enum VmbErrorType - { - VmbErrorSuccess = 0, //!< No error - VmbErrorInternalFault = -1, //!< Unexpected fault in VmbC or driver - VmbErrorApiNotStarted = -2, //!< ::VmbStartup() was not called before the current command - VmbErrorNotFound = -3, //!< The designated instance (camera, feature etc.) cannot be found - VmbErrorBadHandle = -4, //!< The given handle is not valid - VmbErrorDeviceNotOpen = -5, //!< Device was not opened for usage - VmbErrorInvalidAccess = -6, //!< Operation is invalid with the current access mode - VmbErrorBadParameter = -7, //!< One of the parameters is invalid (usually an illegal pointer) - VmbErrorStructSize = -8, //!< The given struct size is not valid for this version of the API - VmbErrorMoreData = -9, //!< More data available in a string/list than space is provided - VmbErrorWrongType = -10, //!< Wrong feature type for this access function - VmbErrorInvalidValue = -11, //!< The value is not valid; either out of bounds or not an increment of the minimum - VmbErrorTimeout = -12, //!< Timeout during wait - VmbErrorOther = -13, //!< Other error - VmbErrorResources = -14, //!< Resources not available (e.g. memory) - VmbErrorInvalidCall = -15, //!< Call is invalid in the current context (e.g. callback) - VmbErrorNoTL = -16, //!< No transport layers are found - VmbErrorNotImplemented = -17, //!< API feature is not implemented - VmbErrorNotSupported = -18, //!< API feature is not supported - VmbErrorIncomplete = -19, //!< The current operation was not completed (e.g. a multiple registers read or write) - VmbErrorIO = -20, //!< Low level IO error in transport layer - VmbErrorValidValueSetNotPresent = -21, //!< The valid value set could not be retrieved, since the feature does not provide this property - VmbErrorGenTLUnspecified = -22, //!< Unspecified GenTL runtime error - VmbErrorUnspecified = -23, //!< Unspecified runtime error - VmbErrorBusy = -24, //!< The responsible module/entity is busy executing actions - VmbErrorNoData = -25, //!< The function has no data to work on - VmbErrorParsingChunkData = -26, //!< An error occurred parsing a buffer containing chunk data - VmbErrorInUse = -27, //!< Something is already in use - VmbErrorUnknown = -28, //!< Error condition unknown - VmbErrorXml = -29, //!< Error parsing XML - VmbErrorNotAvailable = -30, //!< Something is not available - VmbErrorNotInitialized = -31, //!< Something is not initialized - VmbErrorInvalidAddress = -32, //!< The given address is out of range or invalid for internal reasons - VmbErrorAlready = -33, //!< Something has already been done - VmbErrorNoChunkData = -34, //!< A frame expected to contain chunk data does not contain chunk data - VmbErrorUserCallbackException = -35, //!< A callback provided by the user threw an exception - VmbErrorFeaturesUnavailable = -36, //!< The XML for the module is currently not loaded; the module could be in the wrong state or the XML could not be retrieved or could not be parsed properly - VmbErrorTLNotFound = -37, //!< A required transport layer could not be found or loaded - VmbErrorAmbiguous = -39, //!< An entity cannot be uniquely identified based on the information provided - VmbErrorRetriesExceeded = -40, //!< Something could not be accomplished with a given number of retries - VmbErrorInsufficientBufferCount = -41, //!< The operation requires more buffers - VmbErrorCustom = 1, //!< The minimum error code to use for user defined error codes to avoid conflict with existing error codes - } VmbErrorType; - - /** - * \brief Type for an error returned by API methods; for values see ::VmbErrorType. - */ - typedef VmbInt32_t VmbError_t; - -/** - * \} - */ - -/** - * \name Version - * \{ - */ - - /** - * \brief Version information. - */ - typedef struct VmbVersionInfo - { - /** - * \name Out - * \{ - */ - - VmbUint32_t major; //!< Major version number - VmbUint32_t minor; //!< Minor version number - VmbUint32_t patch; //!< Patch version number - - /** - * \} - */ - } VmbVersionInfo_t; - -/** - * \} - */ - - /** - * \name Pixel information - * \{ - */ - - /** - * \brief Indicates if pixel is monochrome or RGB. - */ - typedef enum VmbPixelType - { - VmbPixelMono = 0x01000000, //!< Monochrome pixel - VmbPixelColor = 0x02000000 //!< Pixel bearing color information - } VmbPixelType; - - /** - * \brief Indicates number of bits for a pixel. Needed for building values of ::VmbPixelFormatType. - */ - typedef enum VmbPixelOccupyType - { - VmbPixelOccupy8Bit = 0x00080000, //!< Pixel effectively occupies 8 bits - VmbPixelOccupy10Bit = 0x000A0000, //!< Pixel effectively occupies 10 bits - VmbPixelOccupy12Bit = 0x000C0000, //!< Pixel effectively occupies 12 bits - VmbPixelOccupy14Bit = 0x000E0000, //!< Pixel effectively occupies 14 bits - VmbPixelOccupy16Bit = 0x00100000, //!< Pixel effectively occupies 16 bits - VmbPixelOccupy24Bit = 0x00180000, //!< Pixel effectively occupies 24 bits - VmbPixelOccupy32Bit = 0x00200000, //!< Pixel effectively occupies 32 bits - VmbPixelOccupy48Bit = 0x00300000, //!< Pixel effectively occupies 48 bits - VmbPixelOccupy64Bit = 0x00400000, //!< Pixel effectively occupies 64 bits - } VmbPixelOccupyType; - - /** - * \brief Pixel format types. - * As far as possible, the Pixel Format Naming Convention (PFNC) has been followed, allowing a few deviations. - * If data spans more than one byte, it is always LSB aligned, except if stated differently. - */ - typedef enum VmbPixelFormatType - { - // mono formats - VmbPixelFormatMono8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0001, //!< Monochrome, 8 bits (PFNC: Mono8) - VmbPixelFormatMono10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0003, //!< Monochrome, 10 bits in 16 bits (PFNC: Mono10) - VmbPixelFormatMono10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0046, //!< Monochrome, 10 bits in 16 bits (PFNC: Mono10p) - VmbPixelFormatMono12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0005, //!< Monochrome, 12 bits in 16 bits (PFNC: Mono12) - VmbPixelFormatMono12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x0006, //!< Monochrome, 2x12 bits in 24 bits (GEV:Mono12Packed) - VmbPixelFormatMono12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0047, //!< Monochrome, 2x12 bits in 24 bits (PFNC: MonoPacked) - VmbPixelFormatMono14 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0025, //!< Monochrome, 14 bits in 16 bits (PFNC: Mono14) - VmbPixelFormatMono16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0007, //!< Monochrome, 16 bits (PFNC: Mono16) - - // bayer formats - VmbPixelFormatBayerGR8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0008, //!< Bayer-color, 8 bits, starting with GR line (PFNC: BayerGR8) - VmbPixelFormatBayerRG8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0009, //!< Bayer-color, 8 bits, starting with RG line (PFNC: BayerRG8) - VmbPixelFormatBayerGB8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x000A, //!< Bayer-color, 8 bits, starting with GB line (PFNC: BayerGB8) - VmbPixelFormatBayerBG8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x000B, //!< Bayer-color, 8 bits, starting with BG line (PFNC: BayerBG8) - VmbPixelFormatBayerGR10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000C, //!< Bayer-color, 10 bits in 16 bits, starting with GR line (PFNC: BayerGR10) - VmbPixelFormatBayerRG10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000D, //!< Bayer-color, 10 bits in 16 bits, starting with RG line (PFNC: BayerRG10) - VmbPixelFormatBayerGB10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000E, //!< Bayer-color, 10 bits in 16 bits, starting with GB line (PFNC: BayerGB10) - VmbPixelFormatBayerBG10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000F, //!< Bayer-color, 10 bits in 16 bits, starting with BG line (PFNC: BayerBG10) - VmbPixelFormatBayerGR12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0010, //!< Bayer-color, 12 bits in 16 bits, starting with GR line (PFNC: BayerGR12) - VmbPixelFormatBayerRG12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0011, //!< Bayer-color, 12 bits in 16 bits, starting with RG line (PFNC: BayerRG12) - VmbPixelFormatBayerGB12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0012, //!< Bayer-color, 12 bits in 16 bits, starting with GB line (PFNC: BayerGB12) - VmbPixelFormatBayerBG12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0013, //!< Bayer-color, 12 bits in 16 bits, starting with BG line (PFNC: BayerBG12) - VmbPixelFormatBayerGR12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002A, //!< Bayer-color, 2x12 bits in 24 bits, starting with GR line (GEV:BayerGR12Packed) - VmbPixelFormatBayerRG12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002B, //!< Bayer-color, 2x12 bits in 24 bits, starting with RG line (GEV:BayerRG12Packed) - VmbPixelFormatBayerGB12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002C, //!< Bayer-color, 2x12 bits in 24 bits, starting with GB line (GEV:BayerGB12Packed) - VmbPixelFormatBayerBG12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002D, //!< Bayer-color, 2x12 bits in 24 bits, starting with BG line (GEV:BayerBG12Packed) - VmbPixelFormatBayerGR10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0056, //!< Bayer-color, 10 bits continuous packed, starting with GR line (PFNC: BayerGR10p) - VmbPixelFormatBayerRG10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0058, //!< Bayer-color, 10 bits continuous packed, starting with RG line (PFNC: BayerRG10p) - VmbPixelFormatBayerGB10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0054, //!< Bayer-color, 10 bits continuous packed, starting with GB line (PFNC: BayerGB10p) - VmbPixelFormatBayerBG10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0052, //!< Bayer-color, 10 bits continuous packed, starting with BG line (PFNC: BayerBG10p) - VmbPixelFormatBayerGR12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0057, //!< Bayer-color, 12 bits continuous packed, starting with GR line (PFNC: BayerGR12p) - VmbPixelFormatBayerRG12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0059, //!< Bayer-color, 12 bits continuous packed, starting with RG line (PFNC: BayerRG12p) - VmbPixelFormatBayerGB12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0055, //!< Bayer-color, 12 bits continuous packed, starting with GB line (PFNC: BayerGB12p) - VmbPixelFormatBayerBG12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0053, //!< Bayer-color, 12 bits continuous packed, starting with BG line (PFNC: BayerBG12p) - VmbPixelFormatBayerGR16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x002E, //!< Bayer-color, 16 bits, starting with GR line (PFNC: BayerGR16) - VmbPixelFormatBayerRG16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x002F, //!< Bayer-color, 16 bits, starting with RG line (PFNC: BayerRG16) - VmbPixelFormatBayerGB16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0030, //!< Bayer-color, 16 bits, starting with GB line (PFNC: BayerGB16) - VmbPixelFormatBayerBG16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0031, //!< Bayer-color, 16 bits, starting with BG line (PFNC: BayerBG16) - - // rgb formats - VmbPixelFormatRgb8 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0014, //!< RGB, 8 bits x 3 (PFNC: RGB8) - VmbPixelFormatBgr8 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0015, //!< BGR, 8 bits x 3 (PFNC: BGR8) - VmbPixelFormatRgb10 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0018, //!< RGB, 12 bits in 16 bits x 3 (PFNC: RGB12) - VmbPixelFormatBgr10 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0019, //!< RGB, 12 bits in 16 bits x 3 (PFNC: RGB12) - VmbPixelFormatRgb12 = VmbPixelColor | VmbPixelOccupy48Bit | 0x001A, //!< RGB, 12 bits in 16 bits x 3 (PFNC: RGB12) - VmbPixelFormatBgr12 = VmbPixelColor | VmbPixelOccupy48Bit | 0x001B, //!< RGB, 12 bits in 16 bits x 3 (PFNC: RGB12) - VmbPixelFormatRgb14 = VmbPixelColor | VmbPixelOccupy48Bit | 0x005E, //!< RGB, 14 bits in 16 bits x 3 (PFNC: RGB12) - VmbPixelFormatBgr14 = VmbPixelColor | VmbPixelOccupy48Bit | 0x004A, //!< RGB, 14 bits in 16 bits x 3 (PFNC: RGB12) - VmbPixelFormatRgb16 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0033, //!< RGB, 16 bits x 3 (PFNC: RGB16) - VmbPixelFormatBgr16 = VmbPixelColor | VmbPixelOccupy48Bit | 0x004B, //!< RGB, 16 bits x 3 (PFNC: RGB16) - - // rgba formats - VmbPixelFormatArgb8 = VmbPixelColor | VmbPixelOccupy32Bit | 0x0016, //!< ARGB, 8 bits x 4 (PFNC: RGBa8) - VmbPixelFormatRgba8 = VmbPixelFormatArgb8, //!< RGBA, 8 bits x 4, legacy name - VmbPixelFormatBgra8 = VmbPixelColor | VmbPixelOccupy32Bit | 0x0017, //!< BGRA, 8 bits x 4 (PFNC: BGRa8) - VmbPixelFormatRgba10 = VmbPixelColor | VmbPixelOccupy64Bit | 0x005F, //!< RGBA, 8 bits x 4, legacy name - VmbPixelFormatBgra10 = VmbPixelColor | VmbPixelOccupy64Bit | 0x004C, //!< RGBA, 8 bits x 4, legacy name - VmbPixelFormatRgba12 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0061, //!< RGBA, 8 bits x 4, legacy name - VmbPixelFormatBgra12 = VmbPixelColor | VmbPixelOccupy64Bit | 0x004E, //!< RGBA, 8 bits x 4, legacy name - VmbPixelFormatRgba14 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0063, //!< RGBA, 8 bits x 4, legacy name - VmbPixelFormatBgra14 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0050, //!< RGBA, 8 bits x 4, legacy name - VmbPixelFormatRgba16 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0064, //!< RGBA, 8 bits x 4, legacy name - VmbPixelFormatBgra16 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0051, //!< RGBA, 8 bits x 4, legacy name - - // yuv/ycbcr formats - VmbPixelFormatYuv411 = VmbPixelColor | VmbPixelOccupy12Bit | 0x001E, //!< YUV 4:1:1 with 8 bits (PFNC: YUV411_8_UYYVYY, GEV:YUV411Packed) - VmbPixelFormatYuv422 = VmbPixelColor | VmbPixelOccupy16Bit | 0x001F, //!< YUV 4:2:2 with 8 bits (PFNC: YUV422_8_UYVY, GEV:YUV422Packed) - VmbPixelFormatYuv444 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0020, //!< YUV 4:4:4 with 8 bits (PFNC: YUV8_UYV, GEV:YUV444Packed) - VmbPixelFormatYuv422_8 = VmbPixelColor | VmbPixelOccupy16Bit | 0x0032, //!< YUV 4:2:2 with 8 bits Channel order YUYV (PFNC: YUV422_8) - VmbPixelFormatYCbCr8_CbYCr = VmbPixelColor | VmbPixelOccupy24Bit | 0x003A, //!< YCbCr 4:4:4 with 8 bits (PFNC: YCbCr8_CbYCr) - identical to VmbPixelFormatYuv444 - VmbPixelFormatYCbCr422_8 = VmbPixelColor | VmbPixelOccupy16Bit | 0x003B, //!< YCbCr 4:2:2 8-bit YCbYCr (PFNC: YCbCr422_8) - VmbPixelFormatYCbCr411_8_CbYYCrYY = VmbPixelColor | VmbPixelOccupy12Bit | 0x003C, //!< YCbCr 4:1:1 with 8 bits (PFNC: YCbCr411_8_CbYYCrYY) - identical to VmbPixelFormatYuv411 - VmbPixelFormatYCbCr601_8_CbYCr = VmbPixelColor | VmbPixelOccupy24Bit | 0x003D, //!< YCbCr601 4:4:4 8-bit CbYCrt (PFNC: YCbCr601_8_CbYCr) - VmbPixelFormatYCbCr601_422_8 = VmbPixelColor | VmbPixelOccupy16Bit | 0x003E, //!< YCbCr601 4:2:2 8-bit YCbYCr (PFNC: YCbCr601_422_8) - VmbPixelFormatYCbCr601_411_8_CbYYCrYY = VmbPixelColor | VmbPixelOccupy12Bit | 0x003F, //!< YCbCr601 4:1:1 8-bit CbYYCrYY (PFNC: YCbCr601_411_8_CbYYCrYY) - VmbPixelFormatYCbCr709_8_CbYCr = VmbPixelColor | VmbPixelOccupy24Bit | 0x0040, //!< YCbCr709 4:4:4 8-bit CbYCr (PFNC: YCbCr709_8_CbYCr) - VmbPixelFormatYCbCr709_422_8 = VmbPixelColor | VmbPixelOccupy16Bit | 0x0041, //!< YCbCr709 4:2:2 8-bit YCbYCr (PFNC: YCbCr709_422_8) - VmbPixelFormatYCbCr709_411_8_CbYYCrYY = VmbPixelColor | VmbPixelOccupy12Bit | 0x0042, //!< YCbCr709 4:1:1 8-bit CbYYCrYY (PFNC: YCbCr709_411_8_CbYYCrYY) - VmbPixelFormatYCbCr422_8_CbYCrY = VmbPixelColor | VmbPixelOccupy16Bit | 0x0043, //!< YCbCr 4:2:2 with 8 bits (PFNC: YCbCr422_8_CbYCrY) - identical to VmbPixelFormatYuv422 - VmbPixelFormatYCbCr601_422_8_CbYCrY = VmbPixelColor | VmbPixelOccupy16Bit | 0x0044, //!< YCbCr601 4:2:2 8-bit CbYCrY (PFNC: YCbCr601_422_8_CbYCrY) - VmbPixelFormatYCbCr709_422_8_CbYCrY = VmbPixelColor | VmbPixelOccupy16Bit | 0x0045, //!< YCbCr709 4:2:2 8-bit CbYCrY (PFNC: YCbCr709_422_8_CbYCrY) - VmbPixelFormatYCbCr411_8 = VmbPixelColor | VmbPixelOccupy12Bit | 0x005A, //!< YCbCr 4:1:1 8-bit YYCbYYCr (PFNC: YCbCr411_8) - VmbPixelFormatYCbCr8 = VmbPixelColor | VmbPixelOccupy24Bit | 0x005B, //!< YCbCr 4:4:4 8-bit YCbCr (PFNC: YCbCr8) - - VmbPixelFormatLast, - } VmbPixelFormatType; - - /** - * \brief Type for the pixel format; for values see ::VmbPixelFormatType. - */ - typedef VmbUint32_t VmbPixelFormat_t; - -/** - * \} - */ - -#ifdef __cplusplus -} -#endif - -#endif // VMBCOMMONTYPES_H_INCLUDE_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbConstants.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbConstants.h deleted file mode 100644 index 95ebeb690..000000000 --- a/DeviceAdapters/AlliedVisionCamera/SDK/VmbC/VmbConstants.h +++ /dev/null @@ -1,85 +0,0 @@ -/*============================================================================= - Copyright (C) 2021 Allied Vision Technologies. All Rights Reserved. - - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. - -------------------------------------------------------------------------------- - - File: VmbConstants.h - -------------------------------------------------------------------------------- - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, - NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -=============================================================================*/ - -/** - * \file - * \brief File containing constants used in the Vmb C API. - */ - -#ifndef VMBCONSTANTS_H_INCLUDE_ -#define VMBCONSTANTS_H_INCLUDE_ - -#ifdef _WIN32 -/** - * \brief the character used to separate file paths in the parameter of ::VmbStartup - */ -#define VMB_PATH_SEPARATOR_CHAR L';' - -/** - * \brief the string used to separate file paths in the parameter of ::VmbStartup - */ -#define VMB_PATH_SEPARATOR_STRING L";" -#else -/** - * \brief the character used to separate file paths in the parameter of ::VmbStartup - */ -#define VMB_PATH_SEPARATOR_CHAR ':' - -/** - * \brief the string used to separate file paths in the parameter of ::VmbStartup - */ -#define VMB_PATH_SEPARATOR_STRING ":" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \defgroup SfncNamespaces Sfnc Namespace Constants - * \{ - */ - -/** - * \brief The C string identifying the namespace of features not defined in the SFNC - * standard. - */ -#define VMB_SFNC_NAMESPACE_CUSTOM "Custom" - -/** - * \brief The C string identifying the namespace of features defined in the SFNC - * standard. - */ -#define VMB_SFNC_NAMESPACE_STANDARD "Standard" - -/** - * \} - */ - -#ifdef __cplusplus -} -#endif - -#endif // VMBCONSTANTS_H_INCLUDE_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransform.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransform.h deleted file mode 100644 index 77d497eca..000000000 --- a/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransform.h +++ /dev/null @@ -1,336 +0,0 @@ -/*============================================================================= - Copyright (C) 2012 - 2021 Allied Vision Technologies. All Rights Reserved. - - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. - -------------------------------------------------------------------------------- - - File: VmbTransform.h - - Description: Definition of image transform functions for the Vmb APIs. - -------------------------------------------------------------------------------- - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, - NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -=============================================================================*/ - -/** - * \file - */ -#ifndef VMB_TRANSFORM_H_ -#define VMB_TRANSFORM_H_ -#ifndef VMB_TRANSFORM -#define VMB_TRANSFORM -#endif - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef VMBIMAGETRANSFORM_API -# ifndef VMB_NO_EXPORT -# ifdef VMB_EXPORTS -# if defined(__ELF__) && (defined(__clang__) || defined(__GNUC__)) -# define VMBIMAGETRANSFORM_API __attribute__((visibility("default"))) -# elif defined( __APPLE__ ) || defined(__MACH__) -# define VMBIMAGETRANSFORM_API __attribute__((visibility("default"))) -# else -# ifndef _WIN64 -# define VMBIMAGETRANSFORM_API __declspec(dllexport) __stdcall -# else -# define VMBIMAGETRANSFORM_API __stdcall -# endif -# endif -# else -# if defined (__ELF__) && (defined(__clang__) || defined(__GNUC__)) -# define VMBIMAGETRANSFORM_API -# elif defined( __APPLE__ ) || defined(__MACH__) -# define VMBIMAGETRANSFORM_API -# else -# define VMBIMAGETRANSFORM_API __declspec(dllimport) __stdcall -# endif -# endif -# else -# define VMBIMAGETRANSFORM_API -# endif -#endif - -/** - * \brief Inquire the library version. - * - * \param[out] value Contains the library version (Major,Minor,Sub,Build). - * - * This function can be called at anytime, even before the library is initialized. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter \p value is null. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbGetImageTransformVersion ( VmbUint32_t* value ); - -/** - * \brief Get information about processor supported features. - * - * This should be called before using any SIMD (MMX,SSE) optimized functions. - * - * \param[out] technoInfo Returns the supported SIMD technologies. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter If \p technoInfo is null. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbGetTechnoInfo( VmbTechInfo_t* technoInfo ); - -/** - * \brief Translate an Vmb error code to a human-readable string. - * - * \param[in] errorCode The error code to get a readable string for. - * \param[out] info Pointer to a zero terminated string the error description is written to. - * \param[in] maxInfoLength The size of the \p info buffer. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter \p info is null, or if maxInfoLength is 0. - * - * \retval ::VmbErrorMoreData If \p maxInfoLength is too small to hold the complete information. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbGetErrorInfo(VmbError_t errorCode, - VmbANSIChar_t* info, - VmbUint32_t maxInfoLength ); - -/** - * \brief Get information about the currently loaded Vmb ImageTransform API. - * - * - * \p infoType may be one of the following values: - * - ::VmbAPIInfoAll: Returns all information about the API - * - ::VmbAPIInfoPlatform: Returns information about the platform the API was built for (x86 or x64) - * - ::VmbAPIInfoBuild: Returns info about the API built (debug or release) - * - ::VmbAPIInfoTechnology: Returns info about the supported technologies the API was built for (OpenMP or OpenCL) - * - * \param[in] infoType Type of information to return - * \param[out] info Pointer to a zero terminated string that - * \param[in] maxInfoLength The length of the \p info buffer - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter \p info is null. - * - * \retval ::VmbErrorMoreData If chars are insufficient \p maxInfoLength to hold the complete information. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbGetApiInfoString(VmbAPIInfo_t infoType, - VmbANSIChar_t* info, - VmbUint32_t maxInfoLength ); - -/** - * \brief Set transformation options to a predefined debayering mode. - * - * The default mode is 2x2 debayering. Debayering modes only work for image widths and heights - * divisible by two. - * - * \param[in] debayerMode The mode used for debayering the raw source image. - * - * \param[in,out] transformInfo Parameter that contains information about special - * transform functionality - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter \p transformInfo is null. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbSetDebayerMode(VmbDebayerMode_t debayerMode, - VmbTransformInfo* transformInfo ); - -/** - * \brief Set transformation options to a 3x3 color matrix transformation. - * - * \param[in] matrix Color correction matrix. - * - * \param[in,out] transformInfo Parameter that is filled with information - * about special transform functionality. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter If \p matrix or \p transformInfo are null. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbSetColorCorrectionMatrix3x3(const VmbFloat_t* matrix, - VmbTransformInfo* transformInfo ); - -/** - * \brief Initialize the give VmbTransformInfo with gamma correction information. - * - * \param[in] gamma Float gamma correction to set - * \param[in,out] transformInfo Transform info to set gamma correction to - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter \p transformInfo is null. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbSetGammaCorrection(VmbFloat_t gamma, - VmbTransformInfo* transformInfo ); - -/** - * \brief Set the pixel related info of a VmbImage to the values appropriate for the given pixel format. - * - * A VmbPixelFormat_t can be obtained from Vmb C/C++ APIs frame. - * For displaying images, it is suggested to use ::VmbSetImageInfoFromString() or to look up - * a matching VmbPixelFormat_t. - * - * \param[in] pixelFormat The pixel format describes the pixel format to be used. - * \param[in] width The width of the image in pixels. - * \param[in] height The height of the image in pixels. - * \param[in,out] image A pointer to the image struct to write the info to. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter If \p image is null or one of the members of \p image is invalid. - * - * \retval ::VmbErrorStructSize If the Size member of the image is incorrect. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbSetImageInfoFromPixelFormat(VmbPixelFormat_t pixelFormat, - VmbUint32_t width, - VmbUint32_t height, - VmbImage* image); - -/** - * \brief Set image info member values in VmbImage from string. - * - * This function does not read or write to VmbImage::Data member. - * - * \param[in] imageFormat The string containing the image format. This parameter is case insensitive. - * \param[in] width The width of the image in pixels. - * \param[in] height The height of the image in pixels. - * \param[in,out] image A pointer to the image struct to write the info to. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter \p imageFormat or \p image are null. - * - * \retval ::VmbErrorStructSize The Size member of \p image contains an invalid value. - * - * \retval ::VmbErrorResources The function ran out of memory while processing. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbSetImageInfoFromString(const VmbANSIChar_t* imageFormat, - VmbUint32_t width, - VmbUint32_t height, - VmbImage* image); - -/** - * \brief Set output image dependent on the input image, user specifies pixel layout and bit depth of the out format. - * - * \param[in] inputPixelFormat Input Vmb pixel format - * \param[in] width width of the output image - * \param[in] height height of the output image - * \param[in] outputPixelLayout pixel component layout for output image - * \param[in] bitsPerPixel bit depth of output 8 and 16 supported - * \param[out] outputImage The output image to write the compatible format to. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter \p outputImage is null. - * - * \retval ::VmbErrorStructSize The Size member of \p outputImage contains an invalid size. - * - * \retval ::VmbErrorNotImplemented No suitable transformation is implemented. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbSetImageInfoFromInputParameters(VmbPixelFormat_t inputPixelFormat, - VmbUint32_t width, - VmbUint32_t height, - VmbPixelLayout_t outputPixelLayout, - VmbUint32_t bitsPerPixel, - VmbImage* outputImage); - -/** - * \brief Set output image compatible to input image with given layout and bit depth. - * The output image will have same dimensions as the input image. - * - * \param[in] inputImage The input image with fully initialized image info elements. - * \param[in] outputPixelLayout The desired layout for the output image. - * \param[in] bitsPerPixel The desided bit depth for output image. 8 bit and 16 bit are supported. - * \param[out] outputImage The output image to write the compatible format to. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter \p inputImage or \p outputImage are null, - * or the PixelInfo member of the ImageInfo member of the \p inputImage does not correspond to a supported pixel format. - * - * \retval ::VmbErrorStructSize The Size member of \p outputImage contains an invalid size. - * - * \retval ::VmbErrorNotImplemented No suitable transformation is implemented. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbSetImageInfoFromInputImage(const VmbImage* inputImage, - VmbPixelLayout_t outputPixelLayout, - VmbUint32_t bitsPerPixel, - VmbImage* outputImage); - -/** - * \brief Transform an image from one pixel format to another providing additional transformation options, if necessary. - * - * The transformation is defined by the provided images and the \p parameter. - * - * Create the source and destination image info structure with VmbSetImageInfoFromPixelFormat - * or VmbSetimageInfoFromString and keep those structures as template. - * For calls to transform, simply attach the image to the Data member. - * The optional parameters, when set, are constraints on the transform. - * - * \param[in] source The pointer to source image. - * \param[in,out] destination The pointer to destination image. - * \param[in] parameter An array of transform parameters; may be null. - * \param[in] parameterCount The number of transform parameters. - * - * \return An error code indicating success or the type of error. - * - * \retval ::VmbErrorSuccess The call was successful. - * - * \retval ::VmbErrorBadParameter if any image pointer or their "Data" members is NULL, or - * if "Width" or "Height" don't match between source and destination, or - * if one of the parameters for the conversion does not fit - * - * \retval ::VmbErrorStructSize The Size member of \p source or \p destination contain an invalid value. - * - * \retval ::VmbErrorNotImplemented The transformation from the format of \p source to the format of \p destination is not implemented. - */ -VmbError_t VMBIMAGETRANSFORM_API VmbImageTransform(const VmbImage* source, - VmbImage* destination, - const VmbTransformInfo* parameter, - VmbUint32_t parameterCount); - -#ifdef __cplusplus -} -#endif - -#endif // VMB_TRANSFORM_H_ diff --git a/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransformTypes.h b/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransformTypes.h deleted file mode 100644 index c2438470c..000000000 --- a/DeviceAdapters/AlliedVisionCamera/SDK/VmbImageTransform/VmbTransformTypes.h +++ /dev/null @@ -1,1018 +0,0 @@ -/*============================================================================= - Copyright (C) 2012 - 2021 Allied Vision Technologies. All Rights Reserved. - - Redistribution of this header file, in original or modified form, without - prior written consent of Allied Vision Technologies is prohibited. - -------------------------------------------------------------------------------- - - File: VmbTransformTypes.h - - Description: Definition of types used in the Vmb Image Transform library. - -------------------------------------------------------------------------------- - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, - NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -=============================================================================*/ - -/** - * \file - */ -#ifndef VMB_TRANSFORM_TYPES_H_ -#define VMB_TRANSFORM_TYPES_H_ - -#include - -/** - * \brief the type of character to use for strings. - */ -typedef char VmbANSIChar_t; - -/** - * \brief The floating point type to use for matrices. - */ -typedef float VmbFloat_t; - -/** - * \brief Enumeration for the Bayer pattern. - */ -typedef enum VmbBayerPattern -{ - VmbBayerPatternRGGB=0, //!< RGGB pattern, red pixel comes first - VmbBayerPatternGBRG, //!< RGGB pattern, green pixel of blue row comes first - VmbBayerPatternGRBG, //!< RGGB pattern, green pixel of red row comes first - VmbBayerPatternBGGR, //!< RGGB pattern, blue pixel comes first - VmbBayerPatternCYGM=128, //!< CYGM pattern, cyan pixel comes first in the first row, green in the second row (of the sensor) - VmbBayerPatternGMCY, //!< CYGM pattern, green pixel comes first in the first row, cyan in the second row (of the sensor) - VmbBayerPatternCYMG, //!< CYGM pattern, cyan pixel comes first in the first row, magenta in the second row (of the sensor) - VmbBayerPatternMGCY, //!< CYGM pattern, magenta pixel comes first in the first row, cyan in the second row (of the sensor) - VmbBayerPatternLAST=255 -} VmbBayerPattern; - -/** - * \brief Type for an error returned by API methods; for values see ::VmbBayerPattern. - */ -typedef VmbUint32_t VmbBayerPattern_t; - -/** - * \brief Enumeration for the endianness. - */ -typedef enum VmbEndianness -{ - VmbEndiannessLittle=0, //!< Little endian data format - VmbEndiannessBig, //!< Big endian data format - VmbEndiannessLast=255 -} VmbEndianness; - -/** - * \brief Type for the endianness; for values see ::VmbEndianness. - */ -typedef VmbUint32_t VmbEndianness_t; - -/** - * \brief Enumeration for the image alignment. - */ -typedef enum VmbAlignment -{ - VmbAlignmentMSB=0, //!< Data is MSB aligned (pppp pppp pppp ....) - VmbAlignmentLSB, //!< Data is LSB aligned (.... pppp pppp pppp) - VmbAlignmentLAST=255 -} VmbAlignment; - -/** - * \brief Enumeration for the image alignment; for values see ::VmbAlignment - */ -typedef VmbUint32_t VmbAlignment_t; - -/** - * \name Library Info - * \defgroup Library Info - * \{ - */ - -/** - * \brief States of the multi media technology support for operating system and processor. - */ -typedef struct VmbSupportState_t -{ - VmbBool_t Processor; //!< technology supported by the processor - VmbBool_t OperatingSystem; //!< technology supported by the OS -} VmbSupportState_t; - -/** - * \brief States of the support for different multimedia technologies - */ -typedef struct VmbTechInfo_t -{ - VmbSupportState_t IntelMMX; //!< INTEL first gen MultiMedia eXtension - VmbSupportState_t IntelSSE; //!< INTEL Streaming SIMD Extension - VmbSupportState_t IntelSSE2; //!< INTEL Streaming SIMD Extension 2 - VmbSupportState_t IntelSSE3; //!< INTEL Streaming SIMD Extension 3 - VmbSupportState_t IntelSSSE3; //!< INTEL Supplemental Streaming SIMD Extension 3 - VmbSupportState_t AMD3DNow; //!< AMD 3DNow -} VmbTechInfo_t; - -/** - * \brief API info types - */ -typedef enum VmbAPIInfo -{ - VmbAPIInfoAll, //!< All the info (platform, build type and technologies) - VmbAPIInfoPlatform, //!< Platform the api was build for - VmbAPIInfoBuild, //!< build type (debug or release) - VmbAPIInfoTechnology, //!< info about special technologies uses in building the API - VmbAPIInfoLast -} VmbAPIInfo; - -/** - * \brief API info type; for values see ::VmbAPIInfo - */ -typedef VmbUint32_t VmbAPIInfo_t; - -/** - * \} - */ - -/** - * \name Pixel Access Structs - * \defgroup Pixel Access Structs - * \{ - */ - -/** - * \brief Structure for accessing data in 12-bit transfer mode. - * - * Two pixel are coded into 3 bytes. - */ -typedef struct Vmb12BitPackedPair_t -{ - VmbUint8_t m_nVal8_1 ; //!< High byte of the first Pixel - VmbUint8_t m_nVal8_1Low : 4; //!< Low nibble of the first pixel - VmbUint8_t m_nVal8_2Low : 4; //!< Low nibble of the second pixel - VmbUint8_t m_nVal8_2 ; //!< High byte of the second pixel -} Vmb12BitPackedPair_t; - -/** - * \brief Struct for accessing data of a 8 bit grayscale image stored as unsigned integer. - * - * This corresponds to ::VmbPixelFormatMono8. - */ -typedef struct VmbMono8_t -{ -#ifdef __cplusplus - typedef VmbUint8_t value_type; -#endif - VmbUint8_t Y; //!< gray part -} VmbMono8_t; - -/** - * \brief Struct for accessing data of a 8 bit grayscale image stored as signed integer. - */ -typedef struct VmbMono8s_t -{ -#ifdef __cplusplus - typedef VmbInt8_t value_type; -#endif - VmbInt8_t Y; //!< gray part -} VmbMono8s_t; - -/** - * \brief Struct for accessing pixel data of a 10 bit mono padded buffer. - * - * The pixel data is LSB aligned and little endianness encoded on little endian systems. - * - * The pixel data is MSB aligned and big endianness encoded on big endian systems. - * - * On little endian systems this corresponds to ::VmbPixelFormatMono10. - */ -typedef struct VmbMono10_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t Y; //!< gray part -} VmbMono10_t; - -/** - * \brief Struct for accessing pixel data of a 12 bit mono padded buffer. - * - * The pixel data is LSB aligned and little endianness encoded on little endian systems. - * - * The pixel data is MSB aligned and big endianness encoded on big endian systems. - * - * On little endian systems this corresponds to ::VmbPixelFormatMono12. - */ -typedef struct VmbMono12_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t Y; //!< gray part -} VmbMono12_t; - -/** - * \brief Struct for accessing pixel data of a 14 bit mono padded buffer. - * - * The pixel data is LSB aligned and little endianness encoded on little endian systems. - * - * The pixel data is MSB aligned and big endianness encoded on big endian systems. - * - * On little endian systems this corresponds to ::VmbPixelFormatMono14. - */ -typedef struct VmbMono14_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t Y; //!< gray part -} VmbMono14_t; - -/** - * \brief Struct for accessing 16 bit grayscale image stored as unsigned integer. - * - * The pixel data is LSB aligned and little endianness encoded on little endian systems. - * - * The pixel data is MSB aligned and big endianness encoded on big endian systems. - * - * On little endian systems this corresponds to ::VmbPixelFormatMono16. - */ -typedef struct VmbMono16_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t Y; //!< gray part -} VmbMono16_t; - -/** - * \brief Struct for accessing 16 bit grayscale image stored as signed integer. - */ -typedef struct VmbMono16s_t -{ -#ifdef __cplusplus - typedef VmbInt16_t value_type; -#endif - VmbInt16_t Y; //!< gray part -} VmbMono16s_t; - -/** - * \brief Structure for accessing RGB data using 8 bit per channel. - * - * This corresponds to ::VmbPixelFormatRgb8 - */ -typedef struct VmbRGB8_t -{ -#ifdef __cplusplus - typedef VmbUint8_t value_type; -#endif - VmbUint8_t R; //!< red part - VmbUint8_t G; //!< green part - VmbUint8_t B; //!< blue part -} VmbRGB8_t; - -/** - * \brief Structure for accessing RGB data using 10 bit per channel padded to 16 bit; 48 bits per pixel are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatRgb10 on little endian systems. - */ -typedef struct VmbRGB10_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t R; //!< red part - VmbUint16_t G; //!< green part - VmbUint16_t B; //!< blue part -} VmbRGB10_t; - -/** - * \brief Structure for accessing RGB data using 12 bit per channel padded to 16 bit; 48 bits per pixel are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatRgb12 on little endian systems. - */ -typedef struct VmbRGB12_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t R; //!< red part - VmbUint16_t G; //!< green part - VmbUint16_t B; //!< blue part -} VmbRGB12_t; - -/** - * \brief Structure for accessing RGB data using 14 bit per channel padded to 16 bit; 48 bits per pixel are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatRgb14 on little endian systems. - */ -typedef struct VmbRGB14_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t R; //!< red part - VmbUint16_t G; //!< green part - VmbUint16_t B; //!< blue part -} VmbRGB14_t; - -/** - * \brief Struct for accessing RGB pixels stored as 16 bit unsigend integer per channel. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatRgb16 on little endian systems. - */ -typedef struct VmbRGB16_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t R; //!< red part - VmbUint16_t G; //!< green part - VmbUint16_t B; //!< blue part -} VmbRGB16_t; - -/** - * \brief Structure for accessing BGR data using 8 bit per channel. - * - * Corresponds to ::VmbPixelFormatBgr8 - */ -typedef struct VmbBGR8_t -{ -#ifdef __cplusplus - typedef VmbUint8_t value_type; -#endif - VmbUint8_t B; //!< blue part - VmbUint8_t G; //!< green part - VmbUint8_t R; //!< red part -} VmbBGR8_t; - -/** - * \brief Structure for accessing BGR data using 10 bit per channel padded to 16 bit; 48 bits per pixel are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatBgr10 on little endian systems. - */ -typedef struct VmbBGR10_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t B; //!< blue part - VmbUint16_t G; //!< green part - VmbUint16_t R; //!< red part -} VmbBGR10_t; - -/** - * \brief Structure for accessing BGR data using 12 bit per channel padded to 16 bit; 48 bits per pixel are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatBgr12 on little endian systems. - */ -typedef struct VmbBGR12_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t B; //!< blue part - VmbUint16_t G; //!< green part - VmbUint16_t R; //!< red part -} VmbBGR12_t; - -/** - * \brief Structure for accessing BGR data using 14 bit per channel padded to 16 bit; 48 bits per pixel are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatBgr14 on little endian systems. - */ -typedef struct VmbBGR14_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t B; //!< blue part - VmbUint16_t G; //!< green part - VmbUint16_t R; //!< red part -} VmbBGR14_t; - -/** - * \brief Structure for accessing BGR data using 16 bit per channel; 48 bits per pixel are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatBgr16 on little endian systems. - */ -typedef struct VmbBGR16_t -{ -#ifdef __cplusplus - typedef VmbUint16_t value_type; -#endif - VmbUint16_t B; //!< blue part - VmbUint16_t G; //!< green part - VmbUint16_t R; //!< red part -} VmbBGR16_t; - -/** - * \brief Structure for accessing RGBA data using 8 bit per channel. - */ -typedef struct VmbRGBA8_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint8_t value_type; -#endif - VmbUint8_t R; //!< red part - VmbUint8_t G; //!< green part - VmbUint8_t B; //!< blue part - VmbUint8_t A; //!< unused -} VmbRGBA8_t; - -/** - * \brief Alias for ::VmbRGBA8_t - */ -typedef VmbRGBA8_t VmbRGBA32_t; - -/** - * \brief Structure for accessing BGRA data using 8 bit per channel. - * - * This corresponds to ::VmbPixelFormatBgra8 - */ -typedef struct VmbBGRA8_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint8_t value_type; -#endif - VmbUint8_t B; //!< blue part - VmbUint8_t G; //!< green part - VmbUint8_t R; //!< red part - VmbUint8_t A; //!< unused -} VmbBGRA8_t; - -/** - * \brief Alias for ::VmbBGRA8_t - */ -typedef VmbBGRA8_t VmbBGRA32_t; - -/** - * \brief Struct for accessing ARGB values stored using a 8 bit unsigned integer per channel. - * - * Corresponds to ::VmbPixelFormatArgb8 - */ -typedef struct VmbARGB8_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint8_t value_type; -#endif - VmbUint8_t A; //!< unused - VmbUint8_t R; //!< red part - VmbUint8_t G; //!< green part - VmbUint8_t B; //!< blue part -} VmbARGB8_t; - -/** - * \brief Alias for ::VmbARGB8_t - */ -typedef VmbARGB8_t VmbARGB32_t; - -/** - * \brief Structure for accessing BGRA data using a 8 bit unsigned integer per channel. - */ -typedef struct VmbABGR8_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint8_t value_type; -#endif - VmbUint8_t A; //!< unused - VmbUint8_t B; //!< blue part - VmbUint8_t G; //!< green part - VmbUint8_t R; //!< red part -} VmbABGR8_t; - -/** - * \brief Alias for ::VmbABGR8_t - */ -typedef VmbABGR8_t VmbABGR32_t; - -/** - * \brief Structure for accessing RGBA data using 10 bit per channel padded to 16 bit; 64 bit are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatRgba10 on little endian systems. - */ -typedef struct VmbRGBA10_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint16_t value_type; -#endif - VmbUint16_t R; //!< red part - VmbUint16_t G; //!< green part - VmbUint16_t B; //!< blue part - VmbUint16_t A; //!< unused -} VmbRGBA10_t; - -/** - * \brief Structure for accessing BGRA data using 10 bit per channel padded to 16 bit; 64 bit are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatBgra10 on little endian systems. - */ -typedef struct VmbBGRA10_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint16_t value_type; -#endif - VmbUint16_t B; //!< blue part - VmbUint16_t G; //!< green part - VmbUint16_t R; //!< red part - VmbUint16_t A; //!< unused -} VmbBGRA10_t; - -/** - * \brief Structure for accessing RGBA data using 12 bit per channel padded to 16 bit; 64 bit are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatRgba12 on little endian systems. - */ -typedef struct VmbRGBA12_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint16_t value_type; -#endif - VmbUint16_t R; //!< red part - VmbUint16_t G; //!< green part - VmbUint16_t B; //!< blue part - VmbUint16_t A; //!< unused -} VmbRGBA12_t; - -/** - * \brief Structure for accessing RGBA data using 14 bit per channel padded to 16 bit; 64 bit are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatRgba14 on little endian systems. - */ -typedef struct VmbRGBA14_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint16_t value_type; -#endif - VmbUint16_t R; //!< red part - VmbUint16_t G; //!< green part - VmbUint16_t B; //!< blue part - VmbUint16_t A; //!< unused -} VmbRGBA14_t; - -/** - * \brief Structure for accessing BGRA data using 12 bit per channel padded to 16 bit; 64 bit are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatBgra12 on little endian systems. - */ -typedef struct VmbBGRA12_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint16_t value_type; -#endif - VmbUint16_t B; //!< blue part - VmbUint16_t G; //!< green part - VmbUint16_t R; //!< red part - VmbUint16_t A; //!< unused -} VmbBGRA12_t; - -/** - * \brief Structure for accessing BGRA data using 14 bit per channel padded to 16 bit; 64 bit are used in total. - * - * Each channel is LSB aligned and little endianness encoded on little endian systems. - * - * Each channel is MSB aligned and big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatBgra14 on little endian systems. - */ -typedef struct VmbBGRA14_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint16_t value_type; -#endif - VmbUint16_t B; //!< blue part - VmbUint16_t G; //!< green part - VmbUint16_t R; //!< red part - VmbUint16_t A; //!< unused -} VmbBGRA14_t; - -/** - * \brief Structure for accessing RGBA data using 16 bit per channel. - * - * Each channel is little endianness encoded on little endian systems. - * - * Each channel is big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatRgba16 on little endian systems. - */ -typedef struct VmbRGBA16_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint16_t value_type; -#endif - VmbUint16_t R; //!< red part - VmbUint16_t G; //!< green part - VmbUint16_t B; //!< blue part - VmbUint16_t A; //!< unused -} VmbRGBA16_t; - -/** - * \brief Alias for ::VmbRGBA16_t - */ -typedef VmbRGBA16_t VmbRGBA64_t; - -/** - * \brief Structure for accessing BGRA data using 16 bit per channel. - * - * Each channel is little endianness encoded on little endian systems. - * - * Each channel is big endianness encoded on big endian systems. - * - * Corresponds to ::VmbPixelFormatBgra16 on little endian systems. - */ -typedef struct VmbBGRA16_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint16_t value_type; -#endif - VmbUint16_t B; //!< blue part - VmbUint16_t G; //!< green part - VmbUint16_t R; //!< red part - VmbUint16_t A; //!< unused -} VmbBGRA16_t; - -/** - * \brief Alias for ::VmbBGRA64_t - */ -typedef VmbBGRA16_t VmbBGRA64_t; - -/** - * \brief Structure for accessing data in the YUV 4:4:4 format (YUV) prosilica component order. - * - * Corresponds to ::VmbPixelFormatYuv444 - */ -typedef struct VmbYUV444_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint8_t value_type; -#endif - VmbUint8_t U; //!< U - VmbUint8_t Y; //!< Luma - VmbUint8_t V; //!< V -} VmbYUV444_t; - -/** - * \brief Structure for accessing data in the YUV 4:2:2 format (UYVY) - * - * This struct provides data for 2 pixels (Y0, U, V) and (Y1, U, V) - * - * Corresponds to ::VmbPixelFormatYuv422 - */ -typedef struct VmbYUV422_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint8_t value_type; -#endif - VmbUint8_t U; //!< the U part for both pixels - VmbUint8_t Y0; //!< the intensity of the first pixel - VmbUint8_t V; //!< the V part for both pixels - VmbUint8_t Y1; //!< the intensity of the second pixel -} VmbYUV422_t; - -/** - * \brief Structure for accessing data in the YUV 4:1:1 format (UYYVYY) - * - * This struct provides data for 2 pixels (Y0, U, V), (Y1, U, V), (Y2, U, V) and (Y3, U, V) - * - * Corresponds to ::VmbPixelFormatYuv411 - */ -typedef struct VmbYUV411_t -{ -#ifdef __cplusplus - /** - * \brief The data type used to store one channel. - */ - typedef VmbUint8_t value_type; -#endif - VmbUint8_t U; //!< the U part for all four pixels - VmbUint8_t Y0; //!< the intensity of the first pixel - VmbUint8_t Y1; //!< the intensity of the second pixel - VmbUint8_t V; //!< the V part for all four pixels - VmbUint8_t Y2; //!< the intensity of the third pixel - VmbUint8_t Y3; //!< the intensity of the fourth pixel -} VmbYUV411_t; - -/** - * \} - */ - -/** - * \brief Image pixel layout information. - */ -typedef enum VmbPixelLayout -{ - VmbPixelLayoutMono, //!< Monochrome pixel data; pixels are padded, if necessary. - VmbPixelLayoutMonoPacked, //!< Monochrome pixel data; pixels some bytes contain data for more than one pixel. - VmbPixelLayoutRaw, //!< Some Bayer pixel format where pixels each byte contains only data for a single pixel. - VmbPixelLayoutRawPacked, //!< Some Bayer pixel format where some bytes contain data for more than one pixel. - VmbPixelLayoutRGB, //!< Non-packed RGB data in channel order R, G, B - VmbPixelLayoutBGR, //!< Non-packed RGB data in channel order B, G, R - VmbPixelLayoutRGBA, //!< Non-packed RGBA data in channel order R, G, B, A - VmbPixelLayoutBGRA, //!< Non-packed RGBA data in channel order B, G, R, A - VmbPixelLayoutYUV411_UYYVYY, //!< YUV data; pixel order for 4 pixels is U, Y0, Y1, V, Y2, Y3 - VmbPixelLayoutYUV411_YYUYYV, //!< YUV data; pixel order for 4 pixels is Y0, Y1, U, Y2, Y3, V - VmbPixelLayoutYUV422_UYVY, //!< YUV data; pixel order for 2 pixels is U, Y0, V, Y1 - VmbPixelLayoutYUV422_YUYV, //!< YUV data; pixel order for 2 pixels is Y0, U, Y1, V - VmbPixelLayoutYUV444_UYV, //!< YUV data; pixel order is U, Y, V - VmbPixelLayoutYUV444_YUV, //!< YUV data; pixel order is Y, U, V - VmbPixelLayoutMonoP, //!< Monochrome pixel data; pixels are padded, if necessary. \todo What is the difference to VmbPixelLayoutMono? - VmbPixelLayoutMonoPl, //!< \todo unused, remove? - VmbPixelLayoutRawP, //!< Some Bayer pixel format where pixels each byte contains only data for a single pixel. \todo What's the difference to VmbPixelLayoutRawPacked? - VmbPixelLayoutRawPl, //!< \todo unused, remove? - VmbPixelLayoutYYCbYYCr411 = VmbPixelLayoutYUV411_YYUYYV, //!< Alias for ::VmbPixelLayoutYUV411_YYUYYV - VmbPixelLayoutCbYYCrYY411 = VmbPixelLayoutYUV411_UYYVYY, //!< Alias for ::VmbPixelLayoutYUV411_UYYVYY - VmbPixelLayoutYCbYCr422 = VmbPixelLayoutYUV422_YUYV, //!< Alias for ::VmbPixelLayoutYUV422_YUYV - VmbPixelLayoutCbYCrY422 = VmbPixelLayoutYUV422_UYVY, //!< Alias for ::VmbPixelLayoutYUV422_UYVY - VmbPixelLayoutYCbCr444 = VmbPixelLayoutYUV444_YUV, //!< Alias for ::VmbPixelLayoutYUV444_YUV - VmbPixelLayoutCbYCr444 = VmbPixelLayoutYUV444_UYV, //!< Alias for ::VmbPixelLayoutYUV444_UYV - - VmbPixelLayoutLAST, -} VmbPixelLayout; - -/** - * \brief Image pixel layout information; for values see ::VmbPixelLayout - */ -typedef VmbUint32_t VmbPixelLayout_t; - -/** - * \brief Image color space information. - */ -typedef enum VmbColorSpace -{ - VmbColorSpaceUndefined, - VmbColorSpaceITU_BT709, //!< \todo color space description - VmbColorSpaceITU_BT601, //!< \todo color space description - -} VmbColorSpace; - -/** - * \brief Image color space information; for values see ::VmbColorSpace - */ -typedef VmbUint32_t VmbColorSpace_t; - -/** - * \brief Image pixel information - */ -typedef struct VmbPixelInfo -{ - VmbUint32_t BitsPerPixel; //!< The number of bits used to store the data for one pixel - VmbUint32_t BitsUsed; //!< The number of bits that actually contain data. - VmbAlignment_t Alignment; //!< Indicates, if the most significant or the least significant bit is filled for pixel formats not using all bits of the buffer to store data. - VmbEndianness_t Endianness; //!< Endianness of the pixel data - VmbPixelLayout_t PixelLayout; //!< Channel order, and in case of YUV formats relative order. - VmbBayerPattern_t BayerPattern; //!< The bayer pattern - VmbColorSpace_t Reserved; //!< Unused member reserved for future use. -} VmbPixelInfo; - -/** - * \brief Struct containing information about the image data in the Data member of a ::VmbImage. - */ -typedef struct VmbImageInfo -{ - VmbUint32_t Width; //!< The width of the image in pixels - VmbUint32_t Height; //!< The height of the image in pixels - VmbInt32_t Stride; //!< \todo description; do we actually use this - VmbPixelInfo PixelInfo; //!< Information about the pixel format -} VmbImageInfo; - -/** - * \brief vmb image type - */ -typedef struct VmbImage -{ - VmbUint32_t Size; //!< The size of this struct; If set incorrectly, API functions will return ::VmbErrorStructSize - void* Data; //!< The image data - VmbImageInfo ImageInfo; //!< Information about pixel format, size, and stride of the image. - -} VmbImage; - -/** - * \brief Transform info for special debayering modes. - */ -typedef enum VmbDebayerMode -{ - VmbDebayerMode2x2, //!< \todo description - VmbDebayerMode3x3, //!< \todo description - VmbDebayerModeLCAA, //!< \todo description - VmbDebayerModeLCAAV, //!< \todo description - VmbDebayerModeYUV422, //!< \todo description -} VmbDebayerMode; - -/** - * \brief Transform info for special debayering mode; for values see ::VmbDebayerMode - */ -typedef VmbUint32_t VmbDebayerMode_t; - -/** - * \name Transformation Parameters - * \defgroup Transformation Parameters - * \{ - */ - -/** - * \brief Transform parameter types. - */ -typedef enum VmbTransformType -{ - VmbTransformTypeNone, //!< Invalid type - VmbTransformTypeDebayerMode, //!< Debayering mode - VmbTransformTypeColorCorrectionMatrix, //!< Color correction matrix - VmbTransformTypeGammaCorrection, //!< Gamma correction - VmbTransformTypeOffset, //!< Offset - VmbTransformTypeGain, //!< Gain -} VmbTransformType; - -/** - * \brief Transform parameter type; for avalues see ::VmbTransformType - */ -typedef VmbUint32_t VmbTransformType_t; - -/** - * \brief Struct definition for holding the debayering mode. - * - * The struct is used to pass the data to ::VmbImageTransform via transform parameter. - * It corresponds to the ::VmbTransformTypeDebayerMode parameter type. - */ -typedef struct VmbTransformParameteDebayer -{ - VmbDebayerMode_t Method; //!< The DeBayering method to use. -} VmbTransformParameterDebayer; - - -/** - * \brief Transform info for color correction using a 3x3 matrix multiplication. - * - * The struct is used to pass the data to ::VmbImageTransform via transform parameter. - * It corresponds to the ::VmbTransformTypeColorCorrectionMatrix parameter type. - * - * \todo what does each index represent; how to get from 2d to 1d? - */ -typedef struct VmbTransformParameterMatrix3x3 -{ - VmbFloat_t Matrix[9]; //!< The color correction matrix to use for the transformation. -} VmbTransformParameterMatrix3x3; - -/** - * \brief Struct definition for a gamma value. - * - * This is currently not supported by ::VmbImageTransform. - * It corresponds to the ::VmbTransformTypeGammaCorrection parameter type. - */ -typedef struct VmbTransformParameterGamma -{ - VmbFloat_t Gamma; //!< The gamma value to use for the transformation -} VmbTransformParameterGamma; - -/** - * \brief Struct definition for holding the offset to pass via transform parameter. - * - * The struct is used to pass the data to ::VmbImageTransform via transform parameter. - * It corresponds to the ::VmbTransformTypeOffset parameter type. - */ -typedef struct VmbTransformParameterOffset -{ - VmbInt32_t Offset; //!< The offset to use for the transformation. -} VmbTransformParameterOffset; - -/** - * \brief Struct definition for holding the gain value. - * - * The struct is used to pass the data to ::VmbImageTransform via transform parameter. - * It corresponds to the ::VmbTransformTypeGain parameter type. - */ -typedef struct VmbTransformParameterGain -{ - VmbUint32_t Gain; //!< The gain to use for the transformation -} VmbTransformParameterGain; - -/** - * \brief Union for possible transformation parameter types. - * - * Each possible data type corresponds to a constant of ::VmbTransformType. - */ -typedef union VmbTransformParameter -{ - VmbTransformParameterMatrix3x3 Matrix3x3; //!< A matrix with 3 rows and 3 columns. - VmbTransformParameterDebayer Debayer; //!< A debayering mode - VmbTransformParameterGamma Gamma; //!< A gamma value - VmbTransformParameterOffset Offset; //!< \todo offset (is this even used?) - VmbTransformParameterGain Gain; //!< A gain value -} VmbTransformParameter; - -/** - * \} - */ - -/** - * \brief Transform info interface structure. - */ -typedef struct VmbTransformInfo -{ - VmbTransformType_t TransformType; //!< The type of the information stored in the Parameter member. - VmbTransformParameter Parameter; //!< The parameter data. -} VmbTransformInfo; - -#endif // VMB_TRANSFORM_TYPES_H_ diff --git a/DeviceAdapters/AlliedVisionCamera/license.txt b/DeviceAdapters/AlliedVisionCamera/license.txt new file mode 100644 index 000000000..0032977fd --- /dev/null +++ b/DeviceAdapters/AlliedVisionCamera/license.txt @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2023, Allied Vision Technologies GmbH +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From b6848b71b463f3af9b5622ee6ff4e320b8854827 Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Thu, 26 Oct 2023 15:43:20 -0500 Subject: [PATCH 42/43] AlliedVisionCamera: Use headers in 3rdparty Also remove 32-bit from project file. --- .../AlliedVisionCamera.vcxproj | 77 +------------------ 1 file changed, 2 insertions(+), 75 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj index 96b6f5ded..1aa16787b 100644 --- a/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj +++ b/DeviceAdapters/AlliedVisionCamera/AlliedVisionCamera.vcxproj @@ -1,14 +1,6 @@ - - Debug - Win32 - - - Release - Win32 - Debug x64 @@ -44,19 +36,6 @@ 10.0 - - DynamicLibrary - true - v142 - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - DynamicLibrary true @@ -75,16 +54,6 @@ - - - - - - - - - - @@ -96,12 +65,6 @@ - - true - - - false - true C:\Program Files\Micro-Manager-2.0\ @@ -109,49 +72,13 @@ false - - - Level3 - true - WIN32;_DEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - $(VIMBA_X_HOME)/api/include;%(AdditionalIncludeDirectories) - - - Windows - true - false - - - - - Level3 - true - true - true - WIN32;NDEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - $(VIMBA_X_HOME)/api/include;%(AdditionalIncludeDirectories) - - - Windows - true - true - true - false - - true _DEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - $(VIMBA_X_HOME)/api/include;%(AdditionalIncludeDirectories) + $(MM_3RDPARTYPRIVATE)\AVT\VimbaX-2023-1-Win64\api\include;%(AdditionalIncludeDirectories) Windows @@ -167,7 +94,7 @@ NDEBUG;ALLIEDVISIONCAMERA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - $(VIMBA_X_HOME)/api/include;%(AdditionalIncludeDirectories) + $(MM_3RDPARTYPRIVATE)\AVT\VimbaX-2023-1-Win64\api\include;%(AdditionalIncludeDirectories) Windows From 8eb1882c5da7c88c74e165655dfce706e94ccf39 Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Thu, 26 Oct 2023 18:50:15 -0500 Subject: [PATCH 43/43] AlliedVisionCamera: Set up with ./configure Also fix a bug in Autoconf function MM_LIB_IFELSE() (allow MM_LIB_SIMPLE() to work even if no function to test is given). --- DeviceAdapters/AlliedVisionCamera/Makefile.am | 18 +++++++++++++----- DeviceAdapters/Makefile.am | 5 ++++- DeviceAdapters/configure.ac | 19 +++++++++++++++++++ m4/mm_lib_ifelse.m4 | 2 +- m4/mm_libs.m4 | 11 +++++++++++ 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/DeviceAdapters/AlliedVisionCamera/Makefile.am b/DeviceAdapters/AlliedVisionCamera/Makefile.am index 1f4fa159a..7719d678e 100644 --- a/DeviceAdapters/AlliedVisionCamera/Makefile.am +++ b/DeviceAdapters/AlliedVisionCamera/Makefile.am @@ -1,9 +1,17 @@ - AUTOMAKE_OPTIONS = subdir-objects -AM_CXXFLAGS = $(MMDEVAPI_CXXFLAGS) -I$(VIMBA_X_HOME)/api/include +AM_CXXFLAGS = $(MMDEVAPI_CXXFLAGS) $(VIMBA_X_CPPFLAGS) deviceadapter_LTLIBRARIES = libmmgr_dal_AlliedVisionCamera.la -libmmgr_dal_AlliedVisionCamera_la_SOURCES = AlliedVisionHub.h AlliedVisionHub.cpp AlliedVisionDeviceBase.h AlliedVisionDeviceBase.cpp AlliedVisionCamera.h AlliedVisionCamera.cpp Loader/Constants.h Loader/LibLoader.h Loader/LibLoader.cpp $(VIMBA_X_HOME)/api/include/VmbC/VmbC.h $(VIMBA_X_HOME)/api/include/VmbC/VmbCommonTypes.h $(VIMBA_X_HOME)/api/include/VmbC/VmbConstants.h $(VIMBA_X_HOME)/api/include/VmbC/VmbCTypeDefinitions.h $(VIMBA_X_HOME)/api/include/VmbImageTransform/VmbTransform.h $(VIMBA_X_HOME)/api/include/VmbImageTransform/VmbTransformTypes.h + +libmmgr_dal_AlliedVisionCamera_la_SOURCES = \ + AlliedVisionCamera.cpp \ + AlliedVisionCamera.h \ + AlliedVisionDeviceBase.cpp \ + AlliedVisionDeviceBase.h \ + AlliedVisionHub.cpp \ + AlliedVisionHub.h \ + Loader/Constants.h \ + Loader/LibLoader.cpp \ + Loader/LibLoader.h + libmmgr_dal_AlliedVisionCamera_la_LIBADD = $(MMDEVAPI_LIBADD) libmmgr_dal_AlliedVisionCamera_la_LDFLAGS = $(MMDEVAPI_LDFLAGS) - -EXTRA_DIST = AlliedVisionCamera.vcproj AlliedVisionCamera.vcproj.filters AlliedVisionCamera.vcproj.user diff --git a/DeviceAdapters/Makefile.am b/DeviceAdapters/Makefile.am index 454243648..ec6b8891a 100644 --- a/DeviceAdapters/Makefile.am +++ b/DeviceAdapters/Makefile.am @@ -1,6 +1,9 @@ AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I ../m4 +if BUILD_ALLIED_VISION_CAMERA + ALLIED_VISION_CAMERA = AlliedVisionCamera +endif if BUILD_ANDOR ANDOR = Andor endif @@ -71,6 +74,7 @@ endif # Please keep these ASCII-lexically sorted (pass through sort(1)). SUBDIRS = \ + $(ALLIED_VISION_CAMERA) \ $(ANDOR) \ $(ANDORLASERCOMBINER) \ $(ANDORSDK3) \ @@ -95,7 +99,6 @@ SUBDIRS = \ $(V4L) \ $(ZABER) \ AAAOTF \ - AlliedVisionCamera \ AOTF \ ASIFW1000 \ ASIStage \ diff --git a/DeviceAdapters/configure.ac b/DeviceAdapters/configure.ac index b68f9d88c..7424deba3 100644 --- a/DeviceAdapters/configure.ac +++ b/DeviceAdapters/configure.ac @@ -394,6 +394,22 @@ AS_IF([test "x$want_opencv" != xno], AM_CONDITIONAL([BUILD_OPENCV], [test "x$use_opencv" = xyes]) +# Vimba X (Allied Vision) SDK +MM_ARG_WITH_OPTIONAL_LIB([Vimba X], [vimba-x], [VIMBA_X]) +AS_IF([test "x$want_vimba_x" != xno], +[ + MM_LIB_VIMBA_X([$VIMBA_X_PREFIX], + [use_vimba_x=yes], + [ + use_vimba_x=no + AS_IF([test "x$want_vimba_x" = xyes], + [MM_MSG_OPTIONAL_LIB_FAILURE([Vimba X], [vimba-x])]) + ]) +], +[use_vimba_x=no]) + +AM_CONDITIONAL([BUILD_ALLIED_VISION_CAMERA], [test "x$use_vimba_x" = xyes]) + # Zaber Motion Library (hack: only support 3rdpartypublic copy currently) AC_MSG_CHECKING([for Zaber Motion Library in 3rdpartypublic]) zml_header_to_check="${thirdpartypublic}/Zaber/zaber-motion/include/zaber/motion/library.h" @@ -677,4 +693,7 @@ echo "m4_text_wrap([$use_libusb_0_1], echo "m4_text_wrap([$use_opencv], [ ], [ Build with OpenCV: ])" +echo "m4_text_wrap([$use_vimba_x], + [ ], + [ Build with Vimba X: ])" echo "" diff --git a/m4/mm_lib_ifelse.m4 b/m4/mm_lib_ifelse.m4 index 171f2db00..74b8ec6a3 100644 --- a/m4/mm_lib_ifelse.m4 +++ b/m4/mm_lib_ifelse.m4 @@ -64,7 +64,7 @@ AC_DEFUN([MM_LIB_IFELSE], [ ]) ], [ - mm_lib_ifelse_have_$1=no + mm_lib_ifelse_have_$1=yes ]) ]) diff --git a/m4/mm_libs.m4 b/m4/mm_libs.m4 index 4f6296471..603a2aa14 100644 --- a/m4/mm_libs.m4 +++ b/m4/mm_libs.m4 @@ -105,3 +105,14 @@ AC_DEFUN([MM_LIB_USB_0_1], [ [$1], [-lusb], [usb.h], [usb_init], [$2], [$3]) ]) + + +# Check for Allied Vision Vimba X SDK +# +# MM_LIB_VIMBA_X([Vimba X api prefix], [action-if-found], [action-if-not-found]) +# +# Defines variable VIMBA_X_CPPFLAGS. +# +AC_DEFUN([MM_LIB_VIMBA_X], [ + MM_LIB_SIMPLE([VIMBA_X], [Vimba X], [$1], [], [VmbC/VmbC.h], [], [$2], [$3]) +])