nauful / LibUA

Open-source OPC UA client and server library
Apache License 2.0
262 stars 94 forks source link

Write and read non-ascii value #126

Closed xrcdev closed 1 year ago

xrcdev commented 1 year ago
    Dictionary<string, NodeVariable> AduSentDic = new Dictionary<string, NodeVariable>();
     var processOrderNode = new NodeVariable(new NodeId(2, prefix + "ProcessOrder_String"), new 
     QualifiedName("ProcessOrder_String"),
                                 new LocalizedText("ProcessOrder"),
                                 new LocalizedText("ProcessOrder_String"), 0, 0,
                                  AccessLevel.CurrentRead | AccessLevel.CurrentWrite,
                                  AccessLevel.CurrentRead | AccessLevel.CurrentWrite,
                                  0, false,
                                  new NodeId(UAConst.String));
            aduSend.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), processOrderNode.Id, false));
            processOrderNode.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), processOrderNode.Id, true));
            AddressSpaceTable.TryAdd(processOrderNode.Id, processOrderNode);

  AduSentDic.Add(nameof(adu.ProcessOrder), processOrderNode);

and I got the value by code var processOrder = AduSentDic[nameof(aduS.ProcessOrder)].Value; in the HandleWriteRequest method but the result is "order123?123" not "order123啊123" image

image

xrcdev commented 1 year ago

Where did it go wrong? Did I use this great library incorrectly?

nauful commented 1 year ago

Hello,

I appreciate that you like my library. It looks like a bug in encoding and decoding UA strings in .NET that I hadn't ported back from .NET Core. I have pushed a fix to master for .NET and .NET Core. Please try now and let me know if it works.

If not, these are the methods to look at and debug: https://github.com/nauful/LibUA/blob/c8e642d10b1f39543bc1487c8e0fa496ef743b17/NET%20Core/LibUA/MemoryBufferExtensions.cs#L2220 CodingSizeUAString EncodeUAString DecodeUAString

xrcdev commented 1 year ago

This perfectly solved the problem, thank you very much.