OPC import from script

I’m trying to import tags from Kepware at runtime, using a script.
I configured a OPC-UA server, it is connected and works perfectly.
Anyway this code taken from manual doesn’t work.

[code]#Browse Ignition’s OPC-UA Server. This can be changed to match any connected OPC server.
server = “VendorOPCServer”

#Focus on the “SLC” device connection. This must match a valid device connection in the OPC server.
device = “Line”

#Specify that the folder path should contain “B3”.
folderPath = “*”

#This example is not filtering on a specific OPCItemPath, so it pass Python’s None for this parameter
opcItemPath = None

#Call browseSimple and store the results in a variable. Note that it may take some time to complete the browse.
OpcObjects = system.opc.browseSimple(server, device, folderPath, opcItemPath)

#For each returned address, print out the
for address in OpcObjects:
print address.getOpcItemPath()[/code]
It gives me an exception:

[code]Java Traceback:
at org.python.core.Py.JavaError(Py.java:495)
at org.python.core.Py.JavaError(Py.java:488)
at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:188)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.call(ScriptManager.java:430)
at org.python.core.PyObject.call(PyObject.java:441)
at org.python.core.PyObject.call(PyObject.java:447)
at org.python.pycode._pyx587.f$0(:17)
at org.python.pycode._pyx587.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at org.python.core.Py.exec(Py.java:1319)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:215)
at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)
at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)
at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$InterpreterWorker.doInBackground(JythonConsole.java:419)
at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$InterpreterWorker.doInBackground(JythonConsole.java:407)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: java.lang.NullPointerException
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:329)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:303)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:260)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.moduleInvokeSafe(GatewayInterface.java:842)
at com.ialabs.scripting.functions.OPCFunctionsImpl.browseSimple(OPCFunctionsImpl.java:29)
at sun.reflect.GeneratedMethodAccessor1091.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:186)
… 20 more
Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
at com.inductiveautomation.xopc2.client.OpcUaConnection.browse(OpcUaConnection.java:587)
at com.inductiveautomation.ignition.gateway.opc.OPCManagerImpl$ServerWrapper.browse(OPCManagerImpl.java:781)
at com.inductiveautomation.ignition.gateway.opc.OPCManagerImpl.browse(OPCManagerImpl.java:445)
at com.ialabs.scripting.functions.OPCFunctionsImpl._browse(OPCFunctionsImpl.java:55)
at com.ialabs.scripting.functions.OPCFunctionsImpl._browse(OPCFunctionsImpl.java:94)
at com.ialabs.scripting.functions.OPCFunctionsImpl._browse(OPCFunctionsImpl.java:94)
at com.ialabs.scripting.functions.OPCFunctionsImpl._browse(OPCFunctionsImpl.java:94)
at com.ialabs.scripting.functions.OPCFunctionsImpl._browse(OPCFunctionsImpl.java:94)
at com.ialabs.scripting.functions.OPCFunctionsImpl.browseSimple(OPCFunctionsImpl.java:47)
at com.ialabs.scripting.RPCHandler.browseSimple(RPCHandler.java:138)
at sun.reflect.GeneratedMethodAccessor39.invoke(null)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.ModuleInvoke.invoke(ModuleInvoke.java:123)
at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:390)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:85)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:837)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1160)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1092)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:518)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:246)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:156)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
Traceback (most recent call last):
File “”, line 14, in
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:329)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:303)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:260)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.moduleInvokeSafe(GatewayInterface.java:842)
at com.ialabs.scripting.functions.OPCFunctionsImpl.browseSimple(OPCFunctionsImpl.java:29)
at sun.reflect.GeneratedMethodAccessor1091.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: java.lang.NullPointerException[/code]

Any idea?
Thank you!

Double check your server and device name. I just tried it in 7.9.1 and the code worked as expected.

I’m using 7.9.0 (b2016101208)
Our product provider’s tech support says they’re experiencing the same problem. :scratch:

Anyway I’m focusing on system.opc.browseSimple() because it’s the only function to extract the OPC tag type, since the system.opc.browseServer() can’t. Is there another way to get the type?