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.
Method Call in Python
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
I am glad it works, and thanks for additional example.
Best regards
Please Log in or Create an account to join the conversation.
Your example works also fine with me.
The example, I have been referring to in my previous post, was on the UA Sample Server, doing things like 'halt', 'reset', resume', 'start' and 'suspend'. The view path is: /Boiler #1/Simulation, same for Boiler #2.
As I knew, that my VB example didn't threw any exception when I used it, I was on the way to prepare it, to be able to show it to you and to provide the instructions. These are: One has to make sure, the CurrentState of the Simulation is 'Running' when calling the method 'Suspend', and the CurrentState should be 'Suspended' when calling the method 'Resume'.
Which brought me to the idea, to apply the same rules, when using Python ;o) Doing so it works. Sorry for bothering You, but there where too many options for me when using the first time python and com for that purpose.
# This example shows how to call a single method expecting no arguments.
import win32com.client
# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.UA.EasyUAClient')
# dummy inputs
inputs = []
typeCodes = []
# Perform the operation 1344 to suspend, 1345 to resume
outputs = client.CallMethod(
'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
'nsu=http://opcfoundation.org/UA/Boiler/;i=1287',
'nsu=http://opcfoundation.org/UA/Boiler/;i=1344,
inputs,
typeCodes)
Please Log in or Create an account to join the conversation.
Regarding PowerShell: This is clear. PowerShell can recognize .NET method overloads. But it does not know about extension methods. The method you are calling is implemented as an extension method on IEasyUAClient. It needs to be called as static method in PowerShell, exactly as you did.
Regarding the UA method call: I am getting exception in VB.NET code as well. I think it has to do with the method you have chosen - I do not know this method, maybe something's wrong with the arguments really.
Here is an example that I have made and it works well; in addition, it shows how to truly pass arguments in and out of the method. It calls the same UA method we are using in our other examples.
# This example shows how to call a single method, and pass arguments to and from it.
import win32com.client
# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.UA.EasyUAClient')
#
inputs = [False, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
typeCodes = [
3, # TypeCode.Boolean
5, # TypeCode.SByte
6, # TypeCode.Byte
7, # TypeCode.Int16
8, # TypeCode.UInt16
9, # TypeCode.Int32
10, # TypeCode.UInt32
11, # TypeCode.Int64
12, # TypeCode.UInt64
13, # TypeCode.Single
14 # TypeCode.Double
]
# Perform the operation
outputs = client.CallMethod(
'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
'nsu=http://test.org/UA/Data/;i=10755',
'nsu=http://test.org/UA/Data/;i=10756',
inputs,
typeCodes)
# outputs[0] contains the actual results; outputs[1] and outputs[2] are copies of inputs and typeCodes.
# Display results
for i, value in enumerate(outputs[0]):
print('outputs[', i, ']: ', value)
# Example output:
#outputs[0]: False
#outputs[1]: 1
#outputs[2]: 2
#outputs[3]: 3
#outputs[4]: 4
#outputs[5]: 5
#outputs[6]: 6
#outputs[7]: 7
#outputs[8]: 8
#outputs[9]: 9.0
#outputs[10]: 10.0
Please Log in or Create an account to join the conversation.
I think you are heading in the right direction. Rational:
When using VB, it seems to be smart enough to overlay the CallMethod, with the one with no args. When doing the same thing with PowerShell, it will not find the overlay by itself. What I do here is the following:
#MethodCall without Arguments
[OpcLabs.EasyOpc.UA.IEasyUAClientExtension]::CallMethod($client, $NeroEndpointDescriptor, $LinMotObjectNode, $LinearMotor_LV0_Enable)
#MethodCall with Arguments
$client.CallMethod($NeroEndpointDescriptor, $FluidObjectNode, $Fluid_LV1_Pressure_Pulse, $arrRefArg, $arrRefType)
This way it works fine in PowerShell. Maybe I just miss to add another type, to also enable PowerShell to overlay on its own. Currently I'm only adding:
Add-Type -Path 'C:\Program Files (x86)\OPC Labs QuickOPC 2018.3\Assemblies\net452\OpcLabs.EasyOpcUA.dll'
Back to Python
Thus like PowerShell, Python needs more exact instructions.
Topic (1) - Using the CallMethod with Args for Methods, which don't expect arguments
I tried, Python doesn't crash, but throws an execption
iArgs = []
iTypes = []
rslt = client.CallMethod('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer', 'nsu=http://opcfoundation.org/UA/Boiler/;i=1287','nsu=http://opcfoundation.org/UA/Boiler/;i=1344', iArgs, iTypes)
Error Message:
Nachricht = (-2147352567, 'Ausnahmefehler aufgetreten.', (0, 'OpcLabs.EasyOpcUA', "OPC-UA service result - An error specific to OPC-UA service occurred.\r\n---- SERVICE RESULT ----\r\nStatus Code: {BadArgumentsMissing} = 0x80760000 (2155216896)\r\n\r\n+ The client method called was 'CallMultipleMethods'.", None, 0, -2146232832), None)
Quelle =
Stapelüberwachung:
File "C:\users\texus\source\repos\perwavesscript\perwavesscript\<comobject opclabs.easyopc.ua.easyuaclient>", line 4, in CallMethod
File "C:\Users\texus\source\repos\PerwavesScript\PerwavesScript\CallAMethod.py", line 11, in <module>
rslt = client.CallMethod('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer', 'nsu=http://opcfoundation.org/UA/Boiler/;i=1287','nsu=http://opcfoundation.org/UA/Boiler/;i=1344', iArgs, iTypes)
Topic (2) - com Examples
Like VBA I get them working, but they are not specific enough to really help me in my situation. Even if they are com examples, they look and feel very much the same as the .net things. I could not identify one which brings together the win32com dispatch and the CallMethod.
Maybe you have one specific example in mind, I did miss. Just let me know, I will give it a trail ;o)
Please Log in or Create an account to join the conversation.
The CallMethod method requires 4th and 5th argument: See opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User's...._EasyUAClient~CallMethod.html .
You need to pass them in - can be empty arrays. The callers (Python) should check the number of arguments and not just crash, though.
Remember that I suggested to take one of the COM-based examples (see my previous post and the link) as a starting point.
I hope this helps. Let me know.
Best regards
Please Log in or Create an account to join the conversation.
Step ONE
Thus I'm trying to adapt a simple example. I used one of your example code, and tailored it. Just to "suspend" and "resume" the Simulation of the UA Sample Server. First in VB to make sure it works.
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel
Module Module1
Sub Main()
Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
' Instantiate the client object
Dim client = New EasyUAClient()
' Perform the operation -> 1344 - suspend, 1345 - resume
Dim outputs() As Object
Try
outputs = client.CallMethod(
endpointDescriptor,
"nsu=http://opcfoundation.org/UA/Boiler/;i=1287",
"nsu=http://opcfoundation.org/UA/Boiler/;i=1345")
Catch uaException As UAException
Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
Exit Sub
End Try
End Sub
End Module
That one works fine (but it is implemented via .net)
Step TWO
Than the adapted code for Python:
import win32com.client
client = win32com.client.Dispatch('OPCLabs.EasyOPC.UA.EasyUAClient')
client.CallMethod('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer', 'nsu=http://opcfoundation.org/UA/Boiler/;i=1287','nsu=http://opcfoundation.org/UA/Boiler/;i=1344')
which leads Python to crash. No error feedback, just crashing.
Step THREE
Trying to get the data "CurrentState" in Python when calling the Methods manually via UAExpert works fine. Also an adapted example from your code.
import time
import win32com.client
client = win32com.client.Dispatch('OPCLabs.EasyOPC.UA.EasyUAClient')
client.PullDataChangenotificationQueueCapacity = 1000
print('Subscribing...')
client.SubscribeDataChange('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer','nsu=http://opcfoundation.org/UA/Boiler/;i=1288', 1000)
endTime = time.time() + 60
while time.time() < endTime:
eventArgs = client.PullDataChangeNotification(2*1000)
if eventArgs is not None:
print(eventArgs)
print('Finished')
[] Success; Running {System.String} @2019-03-03T14:00:07.741 @@2019-03-03T14:09:06.597; Good
[] Success; Suspended {System.String} @2019-03-03T14:00:07.741 @@2019-03-03T14:09:13.799; Good
[] Success; Running {System.String} @2019-03-03T14:00:07.741 @@2019-03-03T14:09:22.860; Good
[] Success; Halted {System.String} @2019-03-03T14:00:07.741 @@2019-03-03T14:09:29.597; Good
[] Success; Ready {System.String} @2019-03-03T14:00:07.741 @@2019-03-03T14:09:35.444; Good
[] Success; Running {System.String} @2019-03-03T14:00:07.741 @@2019-03-03T14:09:41.022; Good
Thus the endpointDescriptor (VB and Python), objectNodeDescriptor (VB) and methodNodeDescriptor (VB) seem to be right. Any idea, what I'm making wrong with the Method Call?
Please Log in or Create an account to join the conversation.
We have examples in other languages, but not Python. See:
- opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...all%20a%20single%20method.html
- opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...Call%20multiple%20methods.html
You should be able to take one of the COM-based examples (C++, Free Pascal, Object Pascal, VB6 or VBScript) and convert it to Python. If you run into problems, let me know.
There are some solutions to use .NET from Python but we have not tried them out. It's up to you.
Best regards
Please Log in or Create an account to join the conversation.
My first question: when using the com interface is it at all possible to call methods?
If yes would you have a link to an example?
If not any chance to use .net with Python?
Please Log in or Create an account to join the conversation.