I am using the .Net based OPC UA Client/Server SDK to run an OPC UA server in C#. I want to make available and write to tags that are strings.
Creating tags that are strings in datatype isn’t a problem in SystemConfiguration.xml. For example:
Code: Select all
<Properties>
<Name>User</Name>
<DataType>i=12</DataType>
<Value>0</Value>
<Writeable>true</Writeable>
</Properties>
Ints:
Code: Select all
private void Write(int blockAddress, int offset, int value)
{
byte[] bytes = BitConverter.GetBytes(value);
Array.Copy(bytes, 0, m_registers, blockAddress + offset, bytes.Length);
}
Code: Select all
private void Write(int blockAddress, int offset, double value)
{
byte[] bytes = BitConverter.GetBytes((float)value);
Array.Copy(bytes, 0, m_registers, blockAddress + offset, bytes.Length);
}
Code: Select all
private void WriteString(int blockAddress, int offset, string value)
{
byte[] bytes = Encoding.ASCII.GetBytes((string)value);
Array.Copy(bytes, 0, m_registers, blockAddress + offset, bytes.Length);
}
For example, if I write “test” to the “User” tag this is the result I get in UAExpert (screenshot attached).
Is this correct or should I be able to get the exact string that I entered?
I have also tried following the official documentation which is to use the UaModeler to export auto-generated code and include it in my project however I run into a similar problem which is the string is there but has a Null value and is un-writeable.