Calling OpcUa Server Methods

Hi,

I’m new to Ignition. I’d like to create a button on my dashboard to call a method on my opc server, some thing like system.opcua.callMethod(“Ignition-Hound”, “ns=2;i=111”, “ns=2;i=162”, null);

I have learned a little about the various contexts in which scripts can run but wherever I try and use a script I don’t have access to an opcua package or module. I can use system.opc but not system.opcua

What am I doing wrong?

Thanks in advance!

system.opcua.callMethod has a Gateway scope.

Need a bit more information:

Visoin or Perspective
What version.
Any error you’re receiving.
Pertinent code sample

Thank you for your reply!

I started using Vision but I think I’m about to switch to Perspective. The version of Ignition is 8.1.4.

The code example would be:
Add a button in the ActionPerformed script add:
system.opcua.callMethod(“Ignition-Hound”, “ns=2;i=111”, “ns=2;i=162”, null);

The error is:
Traceback (most recent call last):
File “event:actionPerformed”, line 1, in
AttributeError: ‘com.inductiveautomation.ignition.common.script.Imm’ object has no attribute 'opcua’

at org.python.core.Py.AttributeError(Py.java:207)
at org.python.core.PyObject.noAttributeError(PyObject.java:1032)
at org.python.core.PyObject.__getattr__(PyObject.java:1027)
at org.python.pycode._pyx58.f$0(<event:actionPerformed>:1)
at org.python.pycode._pyx58.call_function(<event:actionPerformed>)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:796)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:206)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:297)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
at com.sun.proxy.$Proxy59.actionPerformed(Unknown Source)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.desktop/java.awt.Component.processEvent(Unknown Source)
at java.desktop/java.awt.Container.processEvent(Unknown Source)
at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

Ignition v8.1.4 (b2021040109)
Java: Azul Systems, Inc. 11.0.9

With an OpcUa client like UaExpert I can call the method and the server handles the method call and returns a result indicating success (or failure).

As @lrose mentioned this function is only available in gateway scope, meaning you can’t call it from the actionPerformed of a Vision button.

If you need to make this happen from a client you need to send a message to a message handler on the gateway that will then call it and possibly return the result.

Thank you both for replying so swiftly. I’ll see what I can work out. Is there a bit of configuration to do on my part for example when I try to script a gateway event I don’t have access to a system.opcua package just system.opc which presumably is the older OPC not opcua?

It may just not be showing up in the auto complete menu… I think there was a bug regarding that for a variety of functions but I’m not sure what version it was fixed in (or if it has been fixed yet).

You should still be able to call it from gateway scope even if it doesn’t auto complete.

2 Likes

I’ve got it working. I think it was a bit harder than it needed to be but I’m grateful for the help I got yesterday. If it would be helpful for anyone else I can document what I did in another reply.

Jason, It would be helpfull to see what you did to get it to work. I have simular issue.

Thanks.

In your Ignition Designer double click Gateway Scripts. In the dialog select Message

Click +

image

Give your Message Handler a name

This code will make a bit more sense when we look at the Button that sends the message

	logger = system.util.logger("MyLogger")
	logger.info("Hello from the gateway")
	method = payload['method']
	if method == 'start':
		logger.info("89,92")
		system.opcua.callMethod("PressOperatorController", "ns=2;i=89", "ns=2;i=92", [])
	if method == 'stop':
		logger.info("89,91")
		system.opcua.callMethod("PressOperatorController", "ns=2;i=89", "ns=2;i=91", [])
	return True

I’m using a Button to call the method. Right click and Configure Events

image

In the OnClick event I use this line

returnValue = system.util.sendRequest(project='POC2', messageHandler='new-gw-handler', payload={"method": "start"})

Can explain more if needed but I think the only bit that’s needs explaining now is the system.opcua.callMethod line.

system.opcua.callMethod(connectionName, objectId, methodId, inputs)


* Parameters

String connectionName - The name of the OPC UA connection to the server that the method resides in.

String objectId - The NodeId of the Object Node the Method is a member of.

String methodId - The NodeId of the Method Node to call.

List inputs - A list of input values expected by the method.

Is that enough to get you going?

2 Likes

Yes, I will give it a try today. Thank you for the help. I appreciate it.

I got it working with your instructions. thank you.