public void WriteMultipleRegistersResponseTcpTest() { string expected = "00-23-00-00-00-06-1C-10-00-64-00-02"; string hex = expected.Replace("-", ""); byte[] message = Enumerable.Range(0, hex.Length) .Where(x => x % 2 == 0) .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) .ToArray(); WriteMultipleRegistersResponse inputs = WriteMultipleRegistersResponse.Decode(message); byte[] msg = inputs.Encode(); string actual = System.BitConverter.ToString(msg); Assert.AreEqual(expected, actual); }
public void WriteMultipleRegistersResponseSerializeRtuTest() { string expected = "1C-10-00-64-00-02-03-9A"; string hex = expected.Replace("-", ""); byte[] message = Enumerable.Range(0, hex.Length) .Where(x => x % 2 == 0) .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) .ToArray(); WriteMultipleRegistersResponse inputs = WriteMultipleRegistersResponse.Decode(message); string jsonString = inputs.Serialize(); WriteMultipleRegistersResponse inputs2 = JsonConvert.DeserializeObject <WriteMultipleRegistersResponse>(jsonString); byte[] msg = inputs2.Encode(); string actual = System.BitConverter.ToString(msg); Assert.AreEqual(expected, actual); }