Scripting - OPC-UA - get tag datatype

Is there an easy way to get the OPC-UA tags configuration. I want to dynamically create my tags by browsing OPC-UA and I want to be able to get the dataypes for each type.

Also what is the best and fasted way to browse ALL tags on an OPC-US server ?

I’m not sure if this is what you’re looking for but as of 8.1.1 the result structure returned by system.opc.browseServer includes the class of the Ignition datatype in it: https://docs.inductiveautomation.com/display/DOC81/system.opc.browseServer

1 Like

Thanks, I will update i’m currently on 8.1

I have upgrade to 8.1.1 but i’ve got error on getDataType()…

AttributeError: ‘com.inductiveautomation.ignition.common.opc.BasicO’ object has no attribute ‘getDataType’

I have tried in scripting console…

def browseOPC(opc_server, opc_path):
	opcs = system.opc.browseServer(opc_server,opc_path)
	
	for opc in opcs:
		print opc.getDataType()
		browseOPC(opc_server, opc_path + "." + str(opc.getDisplayName()))
		
browseOPC("Local_CODESYS","nsu=CODESYSSPV3/3S/IecVarAccess;s=|var|CODESYS Control Win V3 x64.AMT_DUMMIES.MAIN.amt_dummies")

I don’t remember the intricacies of why, some backwards compatibility gaff or serialization thing, but this is only available when called from gateway scope, which the user manual does manage to mention.

Serialization thing.

	results = system.opc.browseServer(
		"Eclipse Milo OPC UA Demo Server",
		"ns=2;s=CTT/Static/All Profiles/Scalar"
	)
	
	for r in results: 
		print "displayName=%s, dataType=%s" % (r.displayName, r.dataType)

Results:

displayName=Boolean, dataType=class java.lang.Boolean
displayName=SByte, dataType=class java.lang.Byte
displayName=Byte, dataType=class java.lang.Short
displayName=Int16, dataType=class java.lang.Short
displayName=UInt16, dataType=class java.lang.Integer
displayName=Int32, dataType=class java.lang.Integer
displayName=UInt32, dataType=class java.lang.Long
displayName=Int64, dataType=class java.lang.Long
displayName=UInt64, dataType=class java.lang.Long
displayName=Float, dataType=class java.lang.Float
displayName=Double, dataType=class java.lang.Double
displayName=String, dataType=class java.lang.String
displayName=DateTime, dataType=class java.util.Date
displayName=Guid, dataType=class java.util.UUID
displayName=ByteString, dataType=class [Ljava.lang.Short;
displayName=XmlElement, dataType=class org.eclipse.milo.opcua.stack.core.types.builtin.XmlElement
displayName=NodeId, dataType=class org.eclipse.milo.opcua.stack.core.types.builtin.NodeId
displayName=ExpandedNodeId, dataType=class org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId
displayName=StatusCode, dataType=class org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode
displayName=QualifiedName, dataType=class org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName
displayName=LocalizedText, dataType=class org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText
displayName=ExtensionObject, dataType=class com.inductiveautomation.ignition.common.document.Document
displayName=Integer, dataType=class java.lang.Number
displayName=UInteger, dataType=class java.lang.Number

A number of those datatypes are classes that only exist in gateway scope because the OPC UA stack is not loaded into clients, so the results can’t be serialized and sent to a client either.

Excuse my ignorence, but how I can test a code that can only be accessible on gateway. I can’t test it in the scripting console and I thinks that no gateway console exist.

Write it in a tag change script and print results to console or log them with the system.util.getLogger function.

Or just jump to what you’ll probably do in production - write a message handler that you can invoke from client side by using system.util.sendMessage or .sendRequest.

Either way you don’t get all the interactivity of the console but there’s just no way around that when you are writing code that can only run in the gateway.

1 Like

OK, thanks.

.sendRequest() for the win!

{ I enthusiastically cheered that function’s introduction. }