Professional OPC
Development Tools


Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Using Python with Quick OPC

30 May 2023 20:24 #11778 by jnickles
Thank you very much for the quick response. I would like to apologize as I am not a computer scientist and all that I know about python has been from what I have self-taught 4 years ago(so I am very rusty). I can see that the example python script will not work because I am using XML DA instead of regular DA. I am confused as to how the object created by the VBScript would be accessed by the python code that you provided. In order to have this process loop continuously and constantly pulling values (say every 1 second) would both scripts have to be open and running at the same time? Again, sorry I am not incredibly technically savvy and this is something I am very new to. Once I have the values as variables in python it is easy to manipulate the data as I would like.

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

30 May 2023 15:45 - 30 May 2023 15:46 #11777 by support
Replied by support on topic Using Python with Quick OPC

This is doable, but we do not have ready-made example for that in Python. The number of examples theoretically needed is huge (because there are many tools an languages that can use QuickOPC), so we do not have them all. But the list keeps growing.

OPC XML-DA is handled by the same object as OPC DA "Classic" in QuickOPC; the difference is just in the "server descriptor" which for COM/DCOM normally contains the computer name and ProgID, but for OPC XML-DA it contains the URL of the server endpoint.

So the code needs to be made by combining knowledge from multiple related examples (and not all of them are in Python but they show the idea). I will to to send them to you or point you to them. Hopefully that will help. If not, let me know, and I will put it together myself.

Here is the basic event pull in Python for OPC DA:

# 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('Unsubscribing item changes...')

This may be the starting code snippet. The problem with it is that is for OPC DA and not OPC XML DA. And, the EasyDAClient.SubscribeItem does not support OPC XML-DA; you need to use SubscribeMultipleItems instead. An example for it - in VBScript - is:

Rem This example shows how to subscribe to changes of multiple items and display the value of the item with each change.
Option Explicit
Dim ItemSubscriptionArguments1: Set ItemSubscriptionArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments")
ItemSubscriptionArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemSubscriptionArguments1.ItemDescriptor.ItemID = "Simulation.Random"
ItemSubscriptionArguments1.GroupParameters.RequestedUpdateRate = 1000
Dim ItemSubscriptionArguments2: Set ItemSubscriptionArguments2 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments")
ItemSubscriptionArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemSubscriptionArguments2.ItemDescriptor.ItemID = "Trends.Ramp (1 min)"
ItemSubscriptionArguments2.GroupParameters.RequestedUpdateRate = 1000
Dim ItemSubscriptionArguments3: Set ItemSubscriptionArguments3 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments")
ItemSubscriptionArguments3.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemSubscriptionArguments3.ItemDescriptor.ItemID = "Trends.Sine (1 min)"
ItemSubscriptionArguments3.GroupParameters.RequestedUpdateRate = 1000
Dim ItemSubscriptionArguments4: Set ItemSubscriptionArguments4 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments")
ItemSubscriptionArguments4.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemSubscriptionArguments4.ItemDescriptor.ItemID = "Simulation.Register_I4"
ItemSubscriptionArguments4.GroupParameters.RequestedUpdateRate = 1000
Dim arguments(3)
Set arguments(0) = ItemSubscriptionArguments1
Set arguments(1) = ItemSubscriptionArguments2
Set arguments(2) = ItemSubscriptionArguments3
Set arguments(3) = ItemSubscriptionArguments4
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
WScript.ConnectObject Client, "Client_"
Client.SubscribeMultipleItems arguments
WScript.Echo "Processing item changed events for 1 minute..."
WScript.Sleep 60*1000
Sub Client_ItemChanged(Sender, e)
    If Not (e.Succeeded) Then
WScript.Echo "*** Failure: " & e.ErrorMessageBrief
    Exit Sub
    End If
WScript.Echo e.Arguments.ItemDescriptor.ItemId & ": " & e.Vtq
End Sub

What matters is that an array of objects needs to be prepared upfront and passed to SubscribeMultipleItems; the rest of the Python code can remain the same.

The last difference is in how - in the above code - the ServerDescriptor is configure for XML-DA. What you need to do is instead of assigning to the ProgID ServerDescriptor.ServerClass property, you take the server URL (something like "") and assign it to the ServerDescriptor.UrlString property.

Best regards
Last edit: 30 May 2023 15:46 by support.

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

30 May 2023 14:33 #11775 by jnickles
I currently have a PLC from which I am trying to pull data and place into an excel chart for every day that the machine is running. I currently have a python script that pulls data from an excel sheet that has cells that use the excel option and are constantly changing . It pulls these values into another sheet which shows values over time. I am running into issues with cells not updating and would like to bypass using the excel option and just pull the PLC data into python.

The PLC has an OPC DA-XML sever. When I went to the documentation ('s.../Event%20Pull%20Mechanism.html) in the OPC XML-DA section there is no example for python. Is this because it is not possible in python (many of the other sections have python example code) or is the example code listed on another page?

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

Moderators: support
Time to create page: 0.170 seconds