Hello.
We are considering purchasing your product and are using your free trial version at the moment.
We would like to see how OPC Alarms & Events operate, but OnNotification doesn't execute with the following code below.
Is there any point we are missing?
Or is this something to do with OPC Kit Server side which needs us to do some extra work to make it work?
Code:
import win32com.client
import win32com.client.connect
import time
# import pythoncom
class EventHandler:
def OnEventingFailure(self, sender0, eventArgs):
print(sender0)
print(eventArgs)
def OnNotification(self, sender0, eventArgs):
print(sender0)
if eventArgs.Succeeded is not None:
print(eventArgs.Message)
daclient = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient')
client = win32com.client.Dispatch('OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient')
serverDescriptor = win32com.client.Dispatch('OpcLabs.EasyOpc.ServerDescriptor')
subscriptionParameters = win32com.client.Dispatch('OpcLabs.EasyOpc.AlarmsAndEvents.AESubscriptionParameters')
serverDescriptor.Host = 'localhost'
serverDescriptor.ServerClass = 'OPCLabs.KitEventServer.2'
subscriptionParameters.notificationRate = 1000
handler = win32com.client.WithEvents(client, EventHandler)
print("Subscribing events...")
handle = client.SubscribeEvents(serverDescriptor, subscriptionParameters, True, None)
time.sleep(10)
daclient.WriteItemValue('localhost', 'OPCLabs.KitServer.2', 'SimulateEvents.ConditionState1.Activate', True)
time.sleep(10)
client.RefreshEventSubscription(handle)
print("Processing event notifications for 1 minute...")
time.sleep(60)
print("Unsubscribing events...")
if handle is not None:
client.UnsubscribeEvents(handle)
print("Finished.")
Environment:
- OPC Server: OPC Kit Server
- QuickOPC: 5.61
- Programming language: Python 3.9.2
- OS: Windows 10 Pro (Ver.2004) 64bit
Please let us know how to make it work.
Kind regards,