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
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
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:
Please Log in or Create an account to join the conversation.
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.
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.
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.
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
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
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.