Ejemplo n.º 1
0
        public void WriteSingleRegisterResponseTcpTest()
        {
            string expected = "00-1E-00-00-00-06-11-06-00-01-00-03";
            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();

            WriteSingleRegisterResponse inputs = WriteSingleRegisterResponse.Decode(message);

            byte[] msg    = inputs.Encode();
            string actual = System.BitConverter.ToString(msg);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void WriteSingleRegisterResponseSerializeRtuTest()
        {
            string expected = "11-06-00-01-00-03-9A-9B";
            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();
            WriteSingleRegisterResponse inputs = WriteSingleRegisterResponse.Decode(message);
            string jsonString = inputs.Serialize();
            WriteSingleRegisterResponse inputs2 = JsonConvert.DeserializeObject <WriteSingleRegisterResponse>(jsonString);

            byte[] msg    = inputs2.Encode();
            string actual = System.BitConverter.ToString(msg);

            Assert.AreEqual(expected, actual);
        }