@@ -34,10 +34,19 @@ Abstract: This is a stub class definition of CPylonDeviceInstance
3434#include " libmcdriver_pylon_pylondeviceinstance.hpp"
3535#include " libmcdriver_pylon_interfaceexception.hpp"
3636
37+ // #include <iostream>
38+
3739// Include custom headers here.
3840#define PYLONFEATURENAME_AUTOEXPOSURE " ExposureAuto"
3941#define PYLONFEATURENAME_EXPOSURETIME " ExposureTime"
4042
43+ /* pylon device access modes */
44+ #define PYLONACCESS_MODE_MONITOR 0
45+ #define PYLONACCESS_MODE_CONTROL 1
46+ #define PYLONACCESS_MODE_STREAM 2
47+ #define PYLONACCESS_MODE_EVENT 4
48+ #define PYLONACCESS_MODE_EXCLUSIVE 8
49+
4150using namespace LibMCDriver_Pylon ::Impl;
4251
4352/* ************************************************************************************************************************
@@ -52,11 +61,25 @@ CPylonDeviceInstance::CPylonDeviceInstance(const std::string & sIdentifier, PLib
5261 if (pDeviceHandle == nullptr )
5362 throw ELibMCDriver_PylonInterfaceException (LIBMCDRIVER_PYLON_ERROR_INVALIDPARAM);
5463
64+ m_pPylonSDK->checkError (m_pPylonSDK->PylonDeviceOpen (m_pDeviceHandle, PYLONACCESS_MODE_CONTROL | PYLONACCESS_MODE_STREAM));
65+
5566}
5667
5768CPylonDeviceInstance::~CPylonDeviceInstance ()
5869{
5970 if (m_pPylonSDK.get () != nullptr ) {
71+
72+ if (m_pDeviceHandle != nullptr ) {
73+ pylonBool bIsOpen = 0 ;
74+ pylonResult nResult = m_pPylonSDK->PylonDeviceIsOpen (m_pDeviceHandle, &bIsOpen);
75+
76+ if (nResult == 0 ) {
77+ if (bIsOpen != 0 ) {
78+ m_pPylonSDK->PylonDeviceClose (m_pDeviceHandle);
79+ }
80+ }
81+ }
82+
6083 m_pPylonSDK->PylonDestroyDevice (m_pDeviceHandle);
6184 }
6285 m_pDeviceHandle = nullptr ;
@@ -211,8 +234,11 @@ void CPylonDeviceInstance::grabSingleGreyscaleImage(const LibMCDriver_Pylon_uint
211234 if (grabResult.m_Status != ePylonGrabStatus::pgsGrabbed)
212235 throw ELibMCDriver_PylonInterfaceException (LIBMCDRIVER_PYLON_ERROR_COULDNOTGRABIMAGE, " Could not grab image (#" + std::to_string (grabResult.m_nErrorCode ) + " )" );
213236
214- if ((grabResult.m_OffsetX != 0 ) || (grabResult.m_OffsetY != 0 ))
215- throw ELibMCDriver_PylonInterfaceException (LIBMCDRIVER_PYLON_ERROR_UNSUPPORTEDGRABOFFSET, " Unsupported Grab Offset (" + std::to_string (grabResult.m_OffsetX ) + " /" + std::to_string (grabResult.m_OffsetY ) + " )" );
237+ // if ((grabResult.m_OffsetX != 0) || (grabResult.m_OffsetY != 0))
238+ // throw ELibMCDriver_PylonInterfaceException(LIBMCDRIVER_PYLON_ERROR_UNSUPPORTEDGRABOFFSET, "Unsupported Grab Offset (" + std::to_string(grabResult.m_OffsetX) + "/" + std::to_string(grabResult.m_OffsetY) + ")");
239+
240+ // std::cout << "Grab offset: " << std::to_string(grabResult.m_OffsetX) + "/" + std::to_string(grabResult.m_OffsetY) << std::endl;
241+ // std::cout << "Padding: " << std::to_string(grabResult.m_PaddingX) + "/" + std::to_string(grabResult.m_PaddingY) << std::endl;
216242
217243 if ((grabResult.m_SizeX <= 0 ) || (grabResult.m_SizeY <= 0 ))
218244 throw ELibMCDriver_PylonInterfaceException (LIBMCDRIVER_PYLON_ERROR_INVALIDGRABIMAGESIZE, " Invalid Grab Image Size (" + std::to_string (grabResult.m_SizeX ) + " /" + std::to_string (grabResult.m_SizeY ) + " )" );
@@ -226,8 +252,8 @@ void CPylonDeviceInstance::grabSingleGreyscaleImage(const LibMCDriver_Pylon_uint
226252 std::to_string (nImageSizeX) + " x" + std::to_string (nImageSizeY) + " != " +
227253 std::to_string (grabResult.m_SizeX ) + " x" + std::to_string (grabResult.m_SizeY ));
228254
229- if ((grabResult.m_PaddingX != 0 ) || (grabResult.m_PaddingY != 0 ))
230- throw ELibMCDriver_PylonInterfaceException (LIBMCDRIVER_PYLON_ERROR_UNSUPPORTEDGRABPADDING, " Unsupported Grab Padding (" + std::to_string (grabResult.m_PaddingX ) + " /" + std::to_string (grabResult.m_PaddingY ) + " )" );
255+ // if ((grabResult.m_PaddingX != 0) || (grabResult.m_PaddingY != 0))
256+ // throw ELibMCDriver_PylonInterfaceException(LIBMCDRIVER_PYLON_ERROR_UNSUPPORTEDGRABPADDING, "Unsupported Grab Padding (" + std::to_string(grabResult.m_PaddingX) + "/" + std::to_string(grabResult.m_PaddingY) + ")");
231257
232258 pImageInstance->SetPixels (0 , 0 , nImageSizeX, nImageSizeY, LibMCEnv::eImagePixelFormat::GreyScale8bit, payloadBuffer);
233259
0 commit comments