Skip to content

Commit fade2de

Browse files
Updated Pylon Driver
1 parent 8945597 commit fade2de

10 files changed

Lines changed: 121 additions & 1 deletion

Drivers/Pylon/ACT/LibMCDriver_Pylon.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<error name="COULDNOTCREATEGIGEDEVICE" code="1008" description="Could not create GigE Device" />
6161
<error name="INVALIDIDENTIFIER" code="1009" description="Invalid device identifier" />
6262
<error name="CONNECTIONIDENTIFIERALREADYINUSE" code="1010" description="Connection identifier already in use" />
63+
<error name="CONNECTIONIDENTIFIERNOTFOUND" code="1011" description="Connection identifier not found" />
6364

6465

6566

@@ -279,6 +280,11 @@ Custom implementation
279280
<param name="Exists" type="bool" pass="return" description="Returns true, if the connection exists, false otherwise." />
280281
</method>
281282

283+
<method name="FindDeviceConnection" description= "Returns a connection by an identifier. Fails if connection does not exist.">
284+
<param name="Identifier" type="string" pass="in" description="Identifier for the connection." />
285+
<param name="Device" type="class" class="PylonDevice" pass="return" description="Device Instance" />
286+
</method>
287+
282288
<method name="CloseAllConnections" description= "Closes all connections.">
283289
</method>
284290

Drivers/Pylon/Headers/CppDynamic/libmcdriver_pylon_dynamic.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,16 @@ typedef LibMCDriver_PylonResult (*PLibMCDriver_PylonDriver_Pylon_ConnectToUnique
440440
*/
441441
typedef LibMCDriver_PylonResult (*PLibMCDriver_PylonDriver_Pylon_ConnectionExistsPtr) (LibMCDriver_Pylon_Driver_Pylon pDriver_Pylon, const char * pIdentifier, bool * pExists);
442442

443+
/**
444+
* Returns a connection by an identifier. Fails if connection does not exist.
445+
*
446+
* @param[in] pDriver_Pylon - Driver_Pylon instance.
447+
* @param[in] pIdentifier - Identifier for the connection.
448+
* @param[out] pDevice - Device Instance
449+
* @return error code or 0 (success)
450+
*/
451+
typedef LibMCDriver_PylonResult (*PLibMCDriver_PylonDriver_Pylon_FindDeviceConnectionPtr) (LibMCDriver_Pylon_Driver_Pylon pDriver_Pylon, const char * pIdentifier, LibMCDriver_Pylon_PylonDevice * pDevice);
452+
443453
/**
444454
* Closes all connections.
445455
*
@@ -561,6 +571,7 @@ typedef struct {
561571
PLibMCDriver_PylonDriver_Pylon_ConnectToUniqueGenericDevicePtr m_Driver_Pylon_ConnectToUniqueGenericDevice;
562572
PLibMCDriver_PylonDriver_Pylon_ConnectToUniqueGigEDevicePtr m_Driver_Pylon_ConnectToUniqueGigEDevice;
563573
PLibMCDriver_PylonDriver_Pylon_ConnectionExistsPtr m_Driver_Pylon_ConnectionExists;
574+
PLibMCDriver_PylonDriver_Pylon_FindDeviceConnectionPtr m_Driver_Pylon_FindDeviceConnection;
564575
PLibMCDriver_PylonDriver_Pylon_CloseAllConnectionsPtr m_Driver_Pylon_CloseAllConnections;
565576
PLibMCDriver_PylonGetVersionPtr m_GetVersion;
566577
PLibMCDriver_PylonGetLastErrorPtr m_GetLastError;

Drivers/Pylon/Headers/CppDynamic/libmcdriver_pylon_dynamic.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class ELibMCDriver_PylonException : public std::exception {
193193
case LIBMCDRIVER_PYLON_ERROR_COULDNOTCREATEGIGEDEVICE: return "COULDNOTCREATEGIGEDEVICE";
194194
case LIBMCDRIVER_PYLON_ERROR_INVALIDIDENTIFIER: return "INVALIDIDENTIFIER";
195195
case LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERALREADYINUSE: return "CONNECTIONIDENTIFIERALREADYINUSE";
196+
case LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERNOTFOUND: return "CONNECTIONIDENTIFIERNOTFOUND";
196197
}
197198
return "UNKNOWN";
198199
}
@@ -220,6 +221,7 @@ class ELibMCDriver_PylonException : public std::exception {
220221
case LIBMCDRIVER_PYLON_ERROR_COULDNOTCREATEGIGEDEVICE: return "Could not create GigE Device";
221222
case LIBMCDRIVER_PYLON_ERROR_INVALIDIDENTIFIER: return "Invalid device identifier";
222223
case LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERALREADYINUSE: return "Connection identifier already in use";
224+
case LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERNOTFOUND: return "Connection identifier not found";
223225
}
224226
return "unknown error";
225227
}
@@ -505,6 +507,7 @@ class CDriver_Pylon : public CDriver {
505507
inline PPylonDevice ConnectToUniqueGenericDevice(const std::string & sIdentifier);
506508
inline PPylonDevice ConnectToUniqueGigEDevice(const std::string & sIdentifier);
507509
inline bool ConnectionExists(const std::string & sIdentifier);
510+
inline PPylonDevice FindDeviceConnection(const std::string & sIdentifier);
508511
inline void CloseAllConnections();
509512
};
510513

@@ -667,6 +670,7 @@ class CDriver_Pylon : public CDriver {
667670
pWrapperTable->m_Driver_Pylon_ConnectToUniqueGenericDevice = nullptr;
668671
pWrapperTable->m_Driver_Pylon_ConnectToUniqueGigEDevice = nullptr;
669672
pWrapperTable->m_Driver_Pylon_ConnectionExists = nullptr;
673+
pWrapperTable->m_Driver_Pylon_FindDeviceConnection = nullptr;
670674
pWrapperTable->m_Driver_Pylon_CloseAllConnections = nullptr;
671675
pWrapperTable->m_GetVersion = nullptr;
672676
pWrapperTable->m_GetLastError = nullptr;
@@ -1058,6 +1062,15 @@ class CDriver_Pylon : public CDriver {
10581062
if (pWrapperTable->m_Driver_Pylon_ConnectionExists == nullptr)
10591063
return LIBMCDRIVER_PYLON_ERROR_COULDNOTFINDLIBRARYEXPORT;
10601064

1065+
#ifdef _WIN32
1066+
pWrapperTable->m_Driver_Pylon_FindDeviceConnection = (PLibMCDriver_PylonDriver_Pylon_FindDeviceConnectionPtr) GetProcAddress(hLibrary, "libmcdriver_pylon_driver_pylon_finddeviceconnection");
1067+
#else // _WIN32
1068+
pWrapperTable->m_Driver_Pylon_FindDeviceConnection = (PLibMCDriver_PylonDriver_Pylon_FindDeviceConnectionPtr) dlsym(hLibrary, "libmcdriver_pylon_driver_pylon_finddeviceconnection");
1069+
dlerror();
1070+
#endif // _WIN32
1071+
if (pWrapperTable->m_Driver_Pylon_FindDeviceConnection == nullptr)
1072+
return LIBMCDRIVER_PYLON_ERROR_COULDNOTFINDLIBRARYEXPORT;
1073+
10611074
#ifdef _WIN32
10621075
pWrapperTable->m_Driver_Pylon_CloseAllConnections = (PLibMCDriver_PylonDriver_Pylon_CloseAllConnectionsPtr) GetProcAddress(hLibrary, "libmcdriver_pylon_driver_pylon_closeallconnections");
10631076
#else // _WIN32
@@ -1294,6 +1307,10 @@ class CDriver_Pylon : public CDriver {
12941307
if ( (eLookupError != 0) || (pWrapperTable->m_Driver_Pylon_ConnectionExists == nullptr) )
12951308
return LIBMCDRIVER_PYLON_ERROR_COULDNOTFINDLIBRARYEXPORT;
12961309

1310+
eLookupError = (*pLookup)("libmcdriver_pylon_driver_pylon_finddeviceconnection", (void**)&(pWrapperTable->m_Driver_Pylon_FindDeviceConnection));
1311+
if ( (eLookupError != 0) || (pWrapperTable->m_Driver_Pylon_FindDeviceConnection == nullptr) )
1312+
return LIBMCDRIVER_PYLON_ERROR_COULDNOTFINDLIBRARYEXPORT;
1313+
12971314
eLookupError = (*pLookup)("libmcdriver_pylon_driver_pylon_closeallconnections", (void**)&(pWrapperTable->m_Driver_Pylon_CloseAllConnections));
12981315
if ( (eLookupError != 0) || (pWrapperTable->m_Driver_Pylon_CloseAllConnections == nullptr) )
12991316
return LIBMCDRIVER_PYLON_ERROR_COULDNOTFINDLIBRARYEXPORT;
@@ -1811,6 +1828,22 @@ class CDriver_Pylon : public CDriver {
18111828
return resultExists;
18121829
}
18131830

1831+
/**
1832+
* CDriver_Pylon::FindDeviceConnection - Returns a connection by an identifier. Fails if connection does not exist.
1833+
* @param[in] sIdentifier - Identifier for the connection.
1834+
* @return Device Instance
1835+
*/
1836+
PPylonDevice CDriver_Pylon::FindDeviceConnection(const std::string & sIdentifier)
1837+
{
1838+
LibMCDriver_PylonHandle hDevice = nullptr;
1839+
CheckError(m_pWrapper->m_WrapperTable.m_Driver_Pylon_FindDeviceConnection(m_pHandle, sIdentifier.c_str(), &hDevice));
1840+
1841+
if (!hDevice) {
1842+
CheckError(LIBMCDRIVER_PYLON_ERROR_INVALIDPARAM);
1843+
}
1844+
return std::make_shared<CPylonDevice>(m_pWrapper, hDevice);
1845+
}
1846+
18141847
/**
18151848
* CDriver_Pylon::CloseAllConnections - Closes all connections.
18161849
*/

Drivers/Pylon/Headers/CppDynamic/libmcdriver_pylon_types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ typedef void * LibMCDriver_Pylon_pvoid;
115115
#define LIBMCDRIVER_PYLON_ERROR_COULDNOTCREATEGIGEDEVICE 1008 /** Could not create GigE Device */
116116
#define LIBMCDRIVER_PYLON_ERROR_INVALIDIDENTIFIER 1009 /** Invalid device identifier */
117117
#define LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERALREADYINUSE 1010 /** Connection identifier already in use */
118+
#define LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERNOTFOUND 1011 /** Connection identifier not found */
118119

119120
/*************************************************************************************************************************
120121
Error strings for LibMCDriver_Pylon
@@ -142,6 +143,7 @@ inline const char * LIBMCDRIVER_PYLON_GETERRORSTRING (LibMCDriver_PylonResult nE
142143
case LIBMCDRIVER_PYLON_ERROR_COULDNOTCREATEGIGEDEVICE: return "Could not create GigE Device";
143144
case LIBMCDRIVER_PYLON_ERROR_INVALIDIDENTIFIER: return "Invalid device identifier";
144145
case LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERALREADYINUSE: return "Connection identifier already in use";
146+
case LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERNOTFOUND: return "Connection identifier not found";
145147
default: return "unknown error";
146148
}
147149
}

Drivers/Pylon/Implementation/libmcdriver_pylon_driver_pylon.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ CDriver_Pylon::CDriver_Pylon(const std::string& sName, LibMCEnv::PDriverEnvironm
5555

5656
CDriver_Pylon::~CDriver_Pylon()
5757
{
58-
58+
unloadPylonSDK();
5959
}
6060

6161

@@ -145,6 +145,8 @@ IPylonDevice * CDriver_Pylon::ConnectToUniqueGenericDevice(const std::string & s
145145

146146
checkIdentifier(sIdentifier);
147147

148+
loadPylonSDK();
149+
148150
size_t numDevices = 0;
149151
m_pPylonSDK->checkError(m_pPylonSDK->PylonEnumerateDevices(&numDevices));
150152

@@ -170,6 +172,8 @@ IPylonDevice * CDriver_Pylon::ConnectToUniqueGigEDevice(const std::string & sIde
170172
if (iIter != m_ConnectedDevices.end())
171173
throw ELibMCDriver_PylonInterfaceException(LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERALREADYINUSE, "connection identifier already in use: " + sIdentifier);
172174

175+
loadPylonSDK();
176+
173177
size_t numDevices = 0;
174178
m_pPylonSDK->checkError(m_pPylonSDK->PylonGigEEnumerateAllDevices(&numDevices));
175179

@@ -202,3 +206,13 @@ void CDriver_Pylon::CloseAllConnections()
202206
m_ConnectedDevices.clear();
203207
}
204208

209+
IPylonDevice* CDriver_Pylon::FindDeviceConnection(const std::string& sIdentifier)
210+
{
211+
auto iIter = m_ConnectedDevices.find(sIdentifier);
212+
if (iIter == m_ConnectedDevices.end())
213+
throw ELibMCDriver_PylonInterfaceException(LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERNOTFOUND, "connection identifier not found: " + sIdentifier);
214+
215+
return new CPylonDevice(iIter->second);
216+
}
217+
218+

Drivers/Pylon/Implementation/libmcdriver_pylon_driver_pylon.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class CDriver_Pylon : public virtual IDriver_Pylon, public virtual CDriver {
102102

103103
bool ConnectionExists(const std::string & sIdentifier) override;
104104

105+
IPylonDevice* FindDeviceConnection(const std::string& sIdentifier) override;
106+
105107
void CloseAllConnections() override;
106108

107109
};

Drivers/Pylon/Interfaces/libmcdriver_pylon_abi.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,16 @@ LIBMCDRIVER_PYLON_DECLSPEC LibMCDriver_PylonResult libmcdriver_pylon_driver_pylo
453453
*/
454454
LIBMCDRIVER_PYLON_DECLSPEC LibMCDriver_PylonResult libmcdriver_pylon_driver_pylon_connectionexists(LibMCDriver_Pylon_Driver_Pylon pDriver_Pylon, const char * pIdentifier, bool * pExists);
455455

456+
/**
457+
* Returns a connection by an identifier. Fails if connection does not exist.
458+
*
459+
* @param[in] pDriver_Pylon - Driver_Pylon instance.
460+
* @param[in] pIdentifier - Identifier for the connection.
461+
* @param[out] pDevice - Device Instance
462+
* @return error code or 0 (success)
463+
*/
464+
LIBMCDRIVER_PYLON_DECLSPEC LibMCDriver_PylonResult libmcdriver_pylon_driver_pylon_finddeviceconnection(LibMCDriver_Pylon_Driver_Pylon pDriver_Pylon, const char * pIdentifier, LibMCDriver_Pylon_PylonDevice * pDevice);
465+
456466
/**
457467
* Closes all connections.
458468
*

Drivers/Pylon/Interfaces/libmcdriver_pylon_interfaces.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ class IDriver_Pylon : public virtual IDriver {
547547
*/
548548
virtual bool ConnectionExists(const std::string & sIdentifier) = 0;
549549

550+
/**
551+
* IDriver_Pylon::FindDeviceConnection - Returns a connection by an identifier. Fails if connection does not exist.
552+
* @param[in] sIdentifier - Identifier for the connection.
553+
* @return Device Instance
554+
*/
555+
virtual IPylonDevice * FindDeviceConnection(const std::string & sIdentifier) = 0;
556+
550557
/**
551558
* IDriver_Pylon::CloseAllConnections - Closes all connections.
552559
*/

Drivers/Pylon/Interfaces/libmcdriver_pylon_interfacewrapper.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,37 @@ LibMCDriver_PylonResult libmcdriver_pylon_driver_pylon_connectionexists(LibMCDri
13021302
}
13031303
}
13041304

1305+
LibMCDriver_PylonResult libmcdriver_pylon_driver_pylon_finddeviceconnection(LibMCDriver_Pylon_Driver_Pylon pDriver_Pylon, const char * pIdentifier, LibMCDriver_Pylon_PylonDevice * pDevice)
1306+
{
1307+
IBase* pIBaseClass = (IBase *)pDriver_Pylon;
1308+
1309+
try {
1310+
if (pIdentifier == nullptr)
1311+
throw ELibMCDriver_PylonInterfaceException (LIBMCDRIVER_PYLON_ERROR_INVALIDPARAM);
1312+
if (pDevice == nullptr)
1313+
throw ELibMCDriver_PylonInterfaceException (LIBMCDRIVER_PYLON_ERROR_INVALIDPARAM);
1314+
std::string sIdentifier(pIdentifier);
1315+
IBase* pBaseDevice(nullptr);
1316+
IDriver_Pylon* pIDriver_Pylon = dynamic_cast<IDriver_Pylon*>(pIBaseClass);
1317+
if (!pIDriver_Pylon)
1318+
throw ELibMCDriver_PylonInterfaceException(LIBMCDRIVER_PYLON_ERROR_INVALIDCAST);
1319+
1320+
pBaseDevice = pIDriver_Pylon->FindDeviceConnection(sIdentifier);
1321+
1322+
*pDevice = (IBase*)(pBaseDevice);
1323+
return LIBMCDRIVER_PYLON_SUCCESS;
1324+
}
1325+
catch (ELibMCDriver_PylonInterfaceException & Exception) {
1326+
return handleLibMCDriver_PylonException(pIBaseClass, Exception);
1327+
}
1328+
catch (std::exception & StdException) {
1329+
return handleStdException(pIBaseClass, StdException);
1330+
}
1331+
catch (...) {
1332+
return handleUnhandledException(pIBaseClass);
1333+
}
1334+
}
1335+
13051336
LibMCDriver_PylonResult libmcdriver_pylon_driver_pylon_closeallconnections(LibMCDriver_Pylon_Driver_Pylon pDriver_Pylon)
13061337
{
13071338
IBase* pIBaseClass = (IBase *)pDriver_Pylon;
@@ -1415,6 +1446,8 @@ LibMCDriver_PylonResult LibMCDriver_Pylon::Impl::LibMCDriver_Pylon_GetProcAddres
14151446
*ppProcAddress = (void*) &libmcdriver_pylon_driver_pylon_connecttouniquegigedevice;
14161447
if (sProcName == "libmcdriver_pylon_driver_pylon_connectionexists")
14171448
*ppProcAddress = (void*) &libmcdriver_pylon_driver_pylon_connectionexists;
1449+
if (sProcName == "libmcdriver_pylon_driver_pylon_finddeviceconnection")
1450+
*ppProcAddress = (void*) &libmcdriver_pylon_driver_pylon_finddeviceconnection;
14181451
if (sProcName == "libmcdriver_pylon_driver_pylon_closeallconnections")
14191452
*ppProcAddress = (void*) &libmcdriver_pylon_driver_pylon_closeallconnections;
14201453
if (sProcName == "libmcdriver_pylon_getversion")

Drivers/Pylon/Interfaces/libmcdriver_pylon_types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ typedef void * LibMCDriver_Pylon_pvoid;
115115
#define LIBMCDRIVER_PYLON_ERROR_COULDNOTCREATEGIGEDEVICE 1008 /** Could not create GigE Device */
116116
#define LIBMCDRIVER_PYLON_ERROR_INVALIDIDENTIFIER 1009 /** Invalid device identifier */
117117
#define LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERALREADYINUSE 1010 /** Connection identifier already in use */
118+
#define LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERNOTFOUND 1011 /** Connection identifier not found */
118119

119120
/*************************************************************************************************************************
120121
Error strings for LibMCDriver_Pylon
@@ -142,6 +143,7 @@ inline const char * LIBMCDRIVER_PYLON_GETERRORSTRING (LibMCDriver_PylonResult nE
142143
case LIBMCDRIVER_PYLON_ERROR_COULDNOTCREATEGIGEDEVICE: return "Could not create GigE Device";
143144
case LIBMCDRIVER_PYLON_ERROR_INVALIDIDENTIFIER: return "Invalid device identifier";
144145
case LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERALREADYINUSE: return "Connection identifier already in use";
146+
case LIBMCDRIVER_PYLON_ERROR_CONNECTIONIDENTIFIERNOTFOUND: return "Connection identifier not found";
145147
default: return "unknown error";
146148
}
147149
}

0 commit comments

Comments
 (0)