local ua = require("opcua.api") local queue = require("opcua.binary.queue") local model = ua.baseModel(ua.clientConfig({})) -- Use the namespace model to write and read a single typed value. local function roundTrip(typeId, value) local bytes = queue.new(1024) model:createBinaryEncoder(bytes):Encode(typeId, value) return model:createBinaryDecoder(bytes):Decode(typeId) end -- Display text may carry a language tag. Browse names identify nodes within a namespace. local text = {Locale = "en-US", Text = "Temperature"} local name = {ns = 1, Name = "Temperature"} assert(roundTrip(ua.DataTypeId.LocalizedText, text).Text == text.Text) assert(roundTrip(ua.DataTypeId.QualifiedName, name).ns == 1) -- Keep the element type when sending an array of readings. local readings = { Type = ua.VariantType.UInt32, Value = {1, 2, 3, 4}, IsArray = true, ArrayDimensions = {4} } assert(roundTrip(ua.DataTypeId.Variant, readings).Value[4] == 4) -- A DataValue adds the quality and the time of the measurement. local sample = { Type = ua.VariantType.Double, Value = 21.5, StatusCode = ua.StatusCode.Good, SourceTimestamp = os.time() } assert(roundTrip("i=23", sample).Value == 21.5) -- BuildInfo illustrates an ExtensionObject with a known structured body. local build = { TypeId = "i=338", Body = { ProductUri = ua.Version.ProductUri, ManufacturerName = ua.Version.ManufacturerName, ProductName = ua.Version.ProductName, SoftwareVersion = ua.Version.Version, BuildNumber = ua.Version.BuildNumber, BuildDate = os.time() } } assert(roundTrip("i=338", build.Body).ProductName == ua.Version.ProductName)