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
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
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.
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.
* 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.