예제 #1
0
        public void PresetMultipleRegsRequest()
        {
            byte     slaveAddress = 1;
            Function function     = Function.PresetMultipleRegs;
            ushort   address      = 0x0002;

            ushort[] values  = { TestClass.CoilOn, TestClass.CoilOff, 0x7777 };
            byte[]   ethalon =
            { slaveAddress
              , (byte)function
              , Helper.Hi(address)
              , Helper.Lo(address)
              , Helper.Hi((ushort)values.Length)
              , Helper.Lo((ushort)values.Length)
              , (byte)(values.Length * 2)
              , Helper.Hi(values[0])
              , Helper.Lo(values[0])
              , Helper.Hi(values[1])
              , Helper.Lo(values[1])
              , Helper.Hi(values[2])
              , Helper.Lo(values[2]) };
            TestClass test = TestClass.CreateWriteRequest(slaveAddress, function, address, values);

            Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
        }
예제 #2
0
        public void ReadCoilStatusRequest()
        {
            byte     slaveAddress = 1;
            Function function     = Function.ReadCoilStatus;
            ushort   address      = 0x0002;
            ushort   coilCount    = 0x0004;

            byte[] ethalon =
            { slaveAddress
              , (byte)function
              , Helper.Hi(address)
              , Helper.Lo(address)
              , Helper.Hi(coilCount)
              , Helper.Lo(coilCount) };
            TestClass test = TestClass.CreateReadRequest(slaveAddress, function, address, coilCount);

            Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
        }
예제 #3
0
        public void PresetSingleRegisterResponse()
        {
            byte     slaveAddress = 1;
            Function function     = Function.PresetSingleRegister;
            ushort   address      = 0x2233;
            ushort   count        = 0x4455;

            byte[] ethalon =
            { slaveAddress
              , (byte)function
              , Helper.Hi(address)
              , Helper.Lo(address)
              , Helper.Hi(count)
              , Helper.Lo(count) };
            TestClass test = TestClass.CreateResponse(slaveAddress, function, address, count);

            Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
        }
예제 #4
0
        public void PresetSingleRegisterRequest()
        {
            byte     slaveAddress = 1;
            Function function     = Function.PresetSingleRegister;
            ushort   address      = 0x0002;
            ushort   value        = 0x0003;

            byte[] ethalon =
            { slaveAddress
              , (byte)function
              , Helper.Hi(address)
              , Helper.Lo(address)
              , Helper.Hi(value)
              , Helper.Lo(value) };
            TestClass test = TestClass.CreateWriteRequest(slaveAddress, function, address, value);

            Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
        }
예제 #5
0
        public void DiagnosticRequest()
        {
            byte     slaveAddress = 1;
            Function function     = Function.Diagnostic;
            ushort   subfunction  = 0x0002;
            ushort   data         = 0x0004;

            byte[] ethalon =
            { slaveAddress
              , (byte)function
              , Helper.Hi(subfunction)
              , Helper.Lo(subfunction)
              , Helper.Hi(data)
              , Helper.Lo(data) };
            TestClass test = TestClass.CreateReadRequest(slaveAddress, function, subfunction, data);

            Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
        }
예제 #6
0
        public void ReadHoldingRegistersRequest()
        {
            byte     slaveAddress = 1;
            Function function     = Function.ReadHoldingRegisters;
            ushort   address      = 0x0002;
            ushort   regCount     = 0x0004;

            byte[] ethalon =
            { slaveAddress
              , (byte)function
              , Helper.Hi(address)
              , Helper.Lo(address)
              , Helper.Hi(regCount)
              , Helper.Lo(regCount) };
            TestClass test = TestClass.CreateReadRequest(slaveAddress, function, address, regCount);

            Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
        }
예제 #7
0
        public void ForceMultipleCoilsResponse()
        {
            byte     slaveAddress = 1;
            Function function     = Function.ForceMultipleCoils;
            ushort   address      = 0x2233;
            // no check for coil count
            ushort count = 0x4455;

            byte[] ethalon =
            { slaveAddress
              , (byte)function
              , Helper.Hi(address)
              , Helper.Lo(address)
              , Helper.Hi(count)
              , Helper.Lo(count) };
            TestClass test = TestClass.CreateResponse(slaveAddress, function, address, count);

            Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
        }
예제 #8
0
        public void ForceMultipleCoilsRequest()
        {
            byte     slaveAddress = 1;
            Function function     = Function.ForceMultipleCoils;
            ushort   address      = 0x0002;

            ushort[] values  = { TestClass.CoilOn, TestClass.CoilOff, 0x7777 };
            byte[]   ethalon =
            { slaveAddress
              , (byte)function
              , Helper.Hi(address)
              , Helper.Lo(address)
              , Helper.Hi(3)
              , Helper.Lo(3)
              , 1
              , 0x05 };
            TestClass test = TestClass.CreateWriteRequest(slaveAddress, function, address, values);

            Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
        }
예제 #9
0
        public void ForceSingleCoilRequest()
        {
            byte     slaveAddress = 1;
            Function function     = Function.ForceSingleCoil;
            ushort   address      = 0x0002;

            /// no check for coil value
            ushort[] values = { TestClass.CoilOn, TestClass.CoilOff, 0x7777 };
            foreach (var value in values)
            {
                byte[] ethalon =
                { slaveAddress
                  , (byte)function
                  , Helper.Hi(address)
                  , Helper.Lo(address)
                  , Helper.Hi(value)
                  , Helper.Lo(value) };
                TestClass test = TestClass.CreateWriteRequest(slaveAddress, function, address, value);
                Assert.IsTrue(ethalon.SequenceEqual(test.Bytes));
            }
        }