Professional OPC
Development Tools

logos

Python examples

More
30 May 2018 06:10 #6381 by support
Replied by support on topic Python examples
Hello,

QuickOPC is exposed to Python via COM, and consuming COM events from Python has turned out to be quite problematic. It might be possible, but you are on your own, currently.

Instead, we suggest to use the "event pull mechanism" - see opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...#Event%20Pull%20Mechanism.html . Semantically, it gets you precisely the same notifications as you would get with events or callbacks, but the coding is different and the activity to obtain the data comes from your side.

There is a Python example right on that documentation page. It looks like this:
# This example shows how to subscribe to item changes and obtain the events by pulling them.
 
import time
import win32com.client
 
# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient') 
# In order to use event pull, you must set a non-zero queue capacity upfront.
client.PullItemChangedQueueCapacity = 1000
 
print('Subscribing item changes...')
client.SubscribeItem('', 'OPCLabs.KitServer.2', 'Simulation.Random', 1000)
 
print('Processing item changes for 1 minute...')
endTime = time.time() + 60
while time.time() < endTime:
    eventArgs = client.PullItemChanged(2*1000)
    if eventArgs is not None:
        # Handle the notification event
        print(eventArgs)
 
print('Unsubscribing item changes...')
client.UnsubscribeAllItems()
 
print('Finished.')
Best regards

Please Log in or Create an account to join the conversation.

More
29 May 2018 13:54 #6370 by filin
Python examples was created by filin
Hello!

I have a small question. How I can register callback for subscribtion (i mean smth like ItemChanged)?
Do you have any examples for it?

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.176 seconds

      

 Recommend this on Google