4

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.

Rekshino
  • 6,954
  • 2
  • 19
  • 44
  • 1
    You may need to look into converting the value string to a UaString.. I am afraid i do not have example code though. http://documentation.unified-automation.com/uasdkcpp/1.2.0/classUaString.html – Andrew Drake Jul 25 '18 at 18:35

0 Answers0