示例#1
0
        public void BuildWriteRegisterCommandTest( )
        {
            ModbusTcpNet modbusTcp = new ModbusTcpNet("127.0.0.1");

            OperateResult <byte[]> command = modbusTcp.BuildWriteRegisterCommand("s=2;123", new byte[] { 0x12, 0x34, 0x56, 0x78 });

            Assert.IsTrue(command.IsSuccess, "command create failed");

            if (command.Content[2] == 0x00 &&
                command.Content[3] == 0x00 &&
                command.Content[4] == 0x00 &&
                command.Content[5] == 0x0B &&
                command.Content[6] == 0x02 &&
                command.Content[7] == 0x10 &&
                command.Content[8] == 0x00 &&
                command.Content[9] == 0x7B &&
                command.Content[10] == 0x00 &&
                command.Content[11] == 0x02 &&
                command.Content[12] == 0x04 &&
                command.Content[13] == 0x12 &&
                command.Content[14] == 0x34 &&
                command.Content[15] == 0x56 &&
                command.Content[16] == 0x78)
            {
            }
            else
            {
                Assert.Fail("command check failed : " + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(command.Content, ' '));
            }
        }