Professional OPC
Development Tools

logos

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

More
20 Feb 2024 17:45 #12572 by support
Replied by support on topic Using Python with Quick OPC
Examples for OPC client and subscriber development in Python are now on GitHub: github.com/OPCLabs/Examples-QuickOPC-Python .

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

More
21 Nov 2023 13:24 #12385 by support
Replied by support on topic Using Python with Quick OPC
Note: QuickOPC now supports Python in much better way, cleaner syntax, and public packages (pypi.org/project/opclabs-quickopc/) on Python Package Index . See What's new in QuickOPC 2023.2 for more information. And, over 270 examples are available in the User's Guide!

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

More
02 Jun 2023 20:24 #11786 by jnickles
That helped a lot and solved my issues, thank you so much!
The following user(s) said Thank You: support

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

More
02 Jun 2023 15:52 - 02 Jun 2023 16:06 #11785 by support
Replied by support on topic Using Python with Quick OPC
Hello.
I will start with one mistake that you are making, which is not directly the cause of the issue, but should be pointed out.

Your picture from the Connectivity Explorer shows that what you are subscribing to are not really OPC items, but (OPC) properties of these OPC items. There is a technical distinction between them that would need some lengthier explanation and I can do that if necessary, but what I want to say is that this is not advisable, and you should do it differently. It would even help if you were going through Excel as before. What you need to do is stay one level higher when selecting in the tree (left-hand side), and see the OPC items in the list (right-hand side). I have illustrated this in my picture with our demo OPC-XML server:



In the tree on the left, click on the "Analog Types". As a rule, only ever click on the folders in the tree (solid green) - not on the items in the tree, because that would then give you the properties in the list on the right side, and you do not want that generally.

If you then click on any item in the list on the right side, it will show Node path, Itemd ID etc. in the info pane below the tree and the list - as on my screenshot. And, "Add Live Data Row" (or double-clicking) should also be done on such nodes - not on the property nodes, unless there is a compelling reason for it.

With that said, now we come to the actual issue.

In OPC XML-DA, besides Item ID, the so-called Node Path is necessary with some OPC servers in order to identify the item. More info: opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...XML%20Nodes%20and%20Items.html . You do not really see the node path in our code examples, because the particular demo server we are using does not require node path. But your OPC server does, most likely. The node path will then go into the .NodePath property parallel to .ItemID that you are already setting.

So, you would take both the node path and the item ID from the info pane I described earlier. Fortunately I can see them both in your screenshot in the "Point" column as well, so I can give you an example. So, instead of having

 
itemSubscriptionArguments1.ItemDescriptor.ItemID = 'SIMOTION/unit/st_var/coreks/Meter'
 

you actually need:

 
itemSubscriptionArguments1.ItemDescriptor.NodePath = 'SIMOTION'
itemSubscriptionArguments1.ItemDescriptor.ItemID = 'unit/st_var.coreks.Meter'
 

(also note the combination of slash and dots in the item ID - this comes from the OPC server and you can copy it from the info pane, there is even a "Copy" icon next to the Node Path and Item ID strings).

Alternatively it would be possible to use Browse Path, which is a different thing altogether, but I do not want to complicate things with it (and it would be less effective).

I hope this helps.
Attachments:
Last edit: 02 Jun 2023 16:06 by support.

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

More
02 Jun 2023 12:51 #11784 by jnickles
I tried reinstalling QuickOPC and performing a windows restart and that cleared up that issue. When I ran the demo script it worked well. When I changed the demo script server information from the demo server to the server I want to connect to I ran into the following error:
SIMOTION/unit/st_var/coreks/Meter *** Failure: OPC NET API failure result "E_UNKNOWN_ITEM_NAME". The item ID is not defined in the server address space or no longer exists in the server address space. [...]

The code I changed was the first connection which I changed to the following:
itemSubscriptionArguments1 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
 
itemSubscriptionArguments1.ServerDescriptor.UrlString = 'http://192.168.214.1/soap/opcxml'
 
itemSubscriptionArguments1.ItemDescriptor.ItemID = 'SIMOTION/unit/st_var/coreks/Meter'
 
itemSubscriptionArguments1.GroupParameters.RequestedUpdateRate = 1000

I am not sure about how to format the ItemID as when I used the connection manager the item I want to subscribe to has a "NodePath". When I keep the "SIMOTION" in the front of the ItemID (SIMOTION/unit/st_var/coreks/Meter) and it is not present (unit/st_var/coreks/Meter) errors persist. I have attached a picture of the connection manager and the item I am talking about is highlighted.




Is this what is causing my error and how should I go about fixing it?

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

More
02 Jun 2023 04:34 #11783 by support
Replied by support on topic Using Python with Quick OPC
Hello.

The target computer must have QuickOPC installed with one of the options that include "Native (COM) development" on the 2nd page of the Setup wizard. Are you sure that this is the case?

Best regards

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

More
01 Jun 2023 19:34 #11782 by jnickles
Thank you so much for the example code! When I tried to run the code I copy and pasted onto the desired computer it threw the following error
Traceback (most recent call last):
  File "C:\Users\MERT MAKINA\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32com\client\dynamic.py", line 84, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "F:\OPC Python Puller\QuickOPCPull.py", line 13, in <module>
    client = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient')
  File "C:\Users\MERT MAKINA\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32com\client\__init__.py", line 118, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
  File "C:\Users\MERT MAKINA\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32com\client\dynamic.py", line 104, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Users\MERT MAKINA\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

I am not familiar with how to use the pywintypes package or commands and I am having trouble trying to fix the error.

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

More
01 Jun 2023 08:45 - 01 Jun 2023 08:56 #11781 by support
Replied by support on topic Using Python with Quick OPC
Hello,
here is the full example:

 
# This example shows how to subscribe to changes of multiple OPC XML-DA items and obtain the item changed 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...')
 
itemSubscriptionArguments1 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
itemSubscriptionArguments1.ServerDescriptor.UrlString = 'opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'
itemSubscriptionArguments1.ItemDescriptor.ItemID = 'Dynamic/Analog Types/Double'
itemSubscriptionArguments1.GroupParameters.RequestedUpdateRate = 1000
 
itemSubscriptionArguments2 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
itemSubscriptionArguments2.ServerDescriptor.UrlString = 'opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'
itemSubscriptionArguments2.ItemDescriptor.ItemID = 'Dynamic/Analog Types/Double[]'
itemSubscriptionArguments2.GroupParameters.RequestedUpdateRate = 1000
 
itemSubscriptionArguments3 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
itemSubscriptionArguments3.ServerDescriptor.UrlString = 'opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'
itemSubscriptionArguments3.ItemDescriptor.ItemID = 'Dynamic/Analog Types/Int'
itemSubscriptionArguments3.GroupParameters.RequestedUpdateRate = 1000
 
# Intentionally specifying an unknown item here, to demonstrate its behavior.
itemSubscriptionArguments4 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
itemSubscriptionArguments4.ServerDescriptor.UrlString = 'opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'
itemSubscriptionArguments4.ItemDescriptor.ItemID = 'SomeUnknownItem'
itemSubscriptionArguments4.GroupParameters.RequestedUpdateRate = 1000
 
arguments = [
    itemSubscriptionArguments1,
    itemSubscriptionArguments2,
    itemSubscriptionArguments3,
    itemSubscriptionArguments4,
    ]
client.SubscribeMultipleItems(arguments)
 
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
        if (eventArgs.Succeeded):
            print(eventArgs.Arguments.ItemDescriptor.ItemId, ': ', eventArgs.Vtq, sep='')
        else:
            print(eventArgs.Arguments.ItemDescriptor.ItemId, ' *** Failure: ', eventArgs.ErrorMessageBrief, sep='')
 
print('Unsubscribing item changes...')
client.UnsubscribeAllItems()
 
print('Finished.')
 


As you can see, the actual data received from the server is in eventArgs.Vtq. You can further qualify it to obtain e.g. eventArgs.Vtq.Value, eventArgs.Vtq.Timestamp, or eventArgs.Vtq.Quality.

I hope this helps
Best regards
Last edit: 01 Jun 2023 08:56 by support. Reason: code formatting

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

More
31 May 2023 12:45 #11780 by jnickles
Sorry for my misunderstanding, that makes a lot more sense. Thank you so much for offering to create an example for me, I am excited to get this working!

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

More
31 May 2023 09:49 #11779 by support
Replied by support on topic Using Python with Quick OPC
Hello.

No problem. I will put together a complete example in Python (the VBScript code was meant to show the idea of which objects to use and how, and to be converted to Python, not to be used "as is", in VBScript). Stay tuned.

Best regards

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

Moderators: support
Time to create page: 0.305 seconds