@@ -571,6 +571,9 @@ class CDriver_OPCUA : public CDriver {
571571 inline void WriteInteger (const LibMCDriver_OPCUA_uint32 nNameSpace, const std::string & sNodeName , const eUAIntegerType eNodeType, const LibMCDriver_OPCUA_int64 nValue);
572572 inline void WriteDouble (const LibMCDriver_OPCUA_uint32 nNameSpace, const std::string & sNodeName , const eUADoubleType eNodeType, const LibMCDriver_OPCUA_double dValue);
573573 inline void WriteString (const LibMCDriver_OPCUA_uint32 nNameSpace, const std::string & sNodeName , const std::string & sValue );
574+ inline void CreateEventSubscription (const LibMCDriver_OPCUA_uint32 nNameSpace, const std::string & sNodeName , const std::string & sSelectFields , const LibMCDriver_OPCUA_double dPublishingInterval, const LibMCDriver_OPCUA_uint32 nQueueSize, const bool bDiscardOldest, LibMCDriver_OPCUA_uint32 & nSubscriptionID, LibMCDriver_OPCUA_uint32 & nMonitoredItemID);
575+ inline void DeleteEventSubscription (const LibMCDriver_OPCUA_uint32 nSubscriptionID, const LibMCDriver_OPCUA_uint32 nMonitoredItemID);
576+ inline void PollEvent (const LibMCDriver_OPCUA_uint32 nTimeoutMS, bool & bHasEvent, LibMCDriver_OPCUA_uint32 & nSubscriptionID, LibMCDriver_OPCUA_uint32 & nMonitoredItemID, std::string & sEventJSON );
574577};
575578
576579 /* *
@@ -714,6 +717,9 @@ class CDriver_OPCUA : public CDriver {
714717 pWrapperTable->m_Driver_OPCUA_WriteInteger = nullptr ;
715718 pWrapperTable->m_Driver_OPCUA_WriteDouble = nullptr ;
716719 pWrapperTable->m_Driver_OPCUA_WriteString = nullptr ;
720+ pWrapperTable->m_Driver_OPCUA_CreateEventSubscription = nullptr ;
721+ pWrapperTable->m_Driver_OPCUA_DeleteEventSubscription = nullptr ;
722+ pWrapperTable->m_Driver_OPCUA_PollEvent = nullptr ;
717723 pWrapperTable->m_GetVersion = nullptr ;
718724 pWrapperTable->m_GetLastError = nullptr ;
719725 pWrapperTable->m_ReleaseInstance = nullptr ;
@@ -942,6 +948,33 @@ class CDriver_OPCUA : public CDriver {
942948 if (pWrapperTable->m_Driver_OPCUA_WriteString == nullptr )
943949 return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
944950
951+ #ifdef _WIN32
952+ pWrapperTable->m_Driver_OPCUA_CreateEventSubscription = (PLibMCDriver_OPCUADriver_OPCUA_CreateEventSubscriptionPtr) GetProcAddress (hLibrary, " libmcdriver_opcua_driver_opcua_createeventsubscription" );
953+ #else // _WIN32
954+ pWrapperTable->m_Driver_OPCUA_CreateEventSubscription = (PLibMCDriver_OPCUADriver_OPCUA_CreateEventSubscriptionPtr) dlsym (hLibrary, " libmcdriver_opcua_driver_opcua_createeventsubscription" );
955+ dlerror ();
956+ #endif // _WIN32
957+ if (pWrapperTable->m_Driver_OPCUA_CreateEventSubscription == nullptr )
958+ return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
959+
960+ #ifdef _WIN32
961+ pWrapperTable->m_Driver_OPCUA_DeleteEventSubscription = (PLibMCDriver_OPCUADriver_OPCUA_DeleteEventSubscriptionPtr) GetProcAddress (hLibrary, " libmcdriver_opcua_driver_opcua_deleteeventsubscription" );
962+ #else // _WIN32
963+ pWrapperTable->m_Driver_OPCUA_DeleteEventSubscription = (PLibMCDriver_OPCUADriver_OPCUA_DeleteEventSubscriptionPtr) dlsym (hLibrary, " libmcdriver_opcua_driver_opcua_deleteeventsubscription" );
964+ dlerror ();
965+ #endif // _WIN32
966+ if (pWrapperTable->m_Driver_OPCUA_DeleteEventSubscription == nullptr )
967+ return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
968+
969+ #ifdef _WIN32
970+ pWrapperTable->m_Driver_OPCUA_PollEvent = (PLibMCDriver_OPCUADriver_OPCUA_PollEventPtr) GetProcAddress (hLibrary, " libmcdriver_opcua_driver_opcua_pollevent" );
971+ #else // _WIN32
972+ pWrapperTable->m_Driver_OPCUA_PollEvent = (PLibMCDriver_OPCUADriver_OPCUA_PollEventPtr) dlsym (hLibrary, " libmcdriver_opcua_driver_opcua_pollevent" );
973+ dlerror ();
974+ #endif // _WIN32
975+ if (pWrapperTable->m_Driver_OPCUA_PollEvent == nullptr )
976+ return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
977+
945978 #ifdef _WIN32
946979 pWrapperTable->m_GetVersion = (PLibMCDriver_OPCUAGetVersionPtr) GetProcAddress (hLibrary, " libmcdriver_opcua_getversion" );
947980 #else // _WIN32
@@ -1097,6 +1130,18 @@ class CDriver_OPCUA : public CDriver {
10971130 if ( (eLookupError != 0 ) || (pWrapperTable->m_Driver_OPCUA_WriteString == nullptr ) )
10981131 return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
10991132
1133+ eLookupError = (*pLookup)(" libmcdriver_opcua_driver_opcua_createeventsubscription" , (void **)&(pWrapperTable->m_Driver_OPCUA_CreateEventSubscription ));
1134+ if ( (eLookupError != 0 ) || (pWrapperTable->m_Driver_OPCUA_CreateEventSubscription == nullptr ) )
1135+ return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
1136+
1137+ eLookupError = (*pLookup)(" libmcdriver_opcua_driver_opcua_deleteeventsubscription" , (void **)&(pWrapperTable->m_Driver_OPCUA_DeleteEventSubscription ));
1138+ if ( (eLookupError != 0 ) || (pWrapperTable->m_Driver_OPCUA_DeleteEventSubscription == nullptr ) )
1139+ return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
1140+
1141+ eLookupError = (*pLookup)(" libmcdriver_opcua_driver_opcua_pollevent" , (void **)&(pWrapperTable->m_Driver_OPCUA_PollEvent ));
1142+ if ( (eLookupError != 0 ) || (pWrapperTable->m_Driver_OPCUA_PollEvent == nullptr ) )
1143+ return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
1144+
11001145 eLookupError = (*pLookup)(" libmcdriver_opcua_getversion" , (void **)&(pWrapperTable->m_GetVersion ));
11011146 if ( (eLookupError != 0 ) || (pWrapperTable->m_GetVersion == nullptr ) )
11021147 return LIBMCDRIVER_OPCUA_ERROR_COULDNOTFINDLIBRARYEXPORT ;
@@ -1368,6 +1413,50 @@ class CDriver_OPCUA : public CDriver {
13681413 {
13691414 CheckError (m_pWrapper->m_WrapperTable .m_Driver_OPCUA_WriteString (m_pHandle, nNameSpace, sNodeName .c_str (), sValue .c_str ()));
13701415 }
1416+
1417+ /* *
1418+ * CDriver_OPCUA::CreateEventSubscription - Creates an event subscription for an event notifier node.
1419+ * @param[in] nNameSpace - Namespace ID
1420+ * @param[in] sNodeName - Event notifier node.
1421+ * @param[in] sSelectFields - Comma-separated event field names. Empty uses the default field list.
1422+ * @param[in] dPublishingInterval - Requested publishing interval in milliseconds.
1423+ * @param[in] nQueueSize - Monitored item queue size.
1424+ * @param[in] bDiscardOldest - Discard oldest queued events if full.
1425+ * @param[out] nSubscriptionID - Created subscription id.
1426+ * @param[out] nMonitoredItemID - Created monitored item id.
1427+ */
1428+ void CDriver_OPCUA::CreateEventSubscription (const LibMCDriver_OPCUA_uint32 nNameSpace, const std::string & sNodeName , const std::string & sSelectFields , const LibMCDriver_OPCUA_double dPublishingInterval, const LibMCDriver_OPCUA_uint32 nQueueSize, const bool bDiscardOldest, LibMCDriver_OPCUA_uint32 & nSubscriptionID, LibMCDriver_OPCUA_uint32 & nMonitoredItemID)
1429+ {
1430+ CheckError (m_pWrapper->m_WrapperTable .m_Driver_OPCUA_CreateEventSubscription (m_pHandle, nNameSpace, sNodeName .c_str (), sSelectFields .c_str (), dPublishingInterval, nQueueSize, bDiscardOldest, &nSubscriptionID, &nMonitoredItemID));
1431+ }
1432+
1433+ /* *
1434+ * CDriver_OPCUA::DeleteEventSubscription - Deletes an event subscription and its monitored item.
1435+ * @param[in] nSubscriptionID - Subscription id.
1436+ * @param[in] nMonitoredItemID - Monitored item id.
1437+ */
1438+ void CDriver_OPCUA::DeleteEventSubscription (const LibMCDriver_OPCUA_uint32 nSubscriptionID, const LibMCDriver_OPCUA_uint32 nMonitoredItemID)
1439+ {
1440+ CheckError (m_pWrapper->m_WrapperTable .m_Driver_OPCUA_DeleteEventSubscription (m_pHandle, nSubscriptionID, nMonitoredItemID));
1441+ }
1442+
1443+ /* *
1444+ * CDriver_OPCUA::PollEvent - Processes incoming notifications and returns the next queued event.
1445+ * @param[in] nTimeoutMS - Maximum time to wait for events. 0 for no wait.
1446+ * @param[out] bHasEvent - True if an event was returned.
1447+ * @param[out] nSubscriptionID - Subscription id of the event.
1448+ * @param[out] nMonitoredItemID - Monitored item id of the event.
1449+ * @param[out] sEventJSON - Event fields encoded as JSON object.
1450+ */
1451+ void CDriver_OPCUA::PollEvent (const LibMCDriver_OPCUA_uint32 nTimeoutMS, bool & bHasEvent, LibMCDriver_OPCUA_uint32 & nSubscriptionID, LibMCDriver_OPCUA_uint32 & nMonitoredItemID, std::string & sEventJSON )
1452+ {
1453+ LibMCDriver_OPCUA_uint32 bytesNeededEventJSON = 0 ;
1454+ LibMCDriver_OPCUA_uint32 bytesWrittenEventJSON = 0 ;
1455+ CheckError (m_pWrapper->m_WrapperTable .m_Driver_OPCUA_PollEvent (m_pHandle, nTimeoutMS, &bHasEvent, &nSubscriptionID, &nMonitoredItemID, 0 , &bytesNeededEventJSON, nullptr ));
1456+ std::vector<char > bufferEventJSON (bytesNeededEventJSON);
1457+ CheckError (m_pWrapper->m_WrapperTable .m_Driver_OPCUA_PollEvent (m_pHandle, nTimeoutMS, &bHasEvent, &nSubscriptionID, &nMonitoredItemID, bytesNeededEventJSON, &bytesWrittenEventJSON, &bufferEventJSON[0 ]));
1458+ sEventJSON = std::string (&bufferEventJSON[0 ]);
1459+ }
13711460
13721461} // namespace LibMCDriver_OPCUA
13731462
0 commit comments