I am using an SDK from Unified Automation that is essentially some C# source code that creates and runs an OPC UA Server. At the moment, I am able to write only to data tags that are either initialized as integers or doubles due to the nature of the write functions within the code. There is a write function for each data type as shown:
private void Write(int blockAddress, int offset, int value)
{
byte[] bytes = BitConverter.GetBytes(value);
Array.Copy(bytes, 0, m_registers, blockAddress + offset, bytes.Length);
}
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);
}
The problem lies with BitConverter as converting a string is not as straight forward. So far I have tried using:
private void Write(int blockAddress, int offset, string value)
{
byte[] bytes = Encoding.ASCII.GetBytes(value);
Array.Copy(bytes, 0, m_registers, blockAddress + offset, bytes.Length);
}
Later on however when reading it in Kepware I get an unusual result: See the first line
Any help appreciated.