コード例 #1
0
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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
ファイル: PacketTest.cs プロジェクト: yobisoft/yobisoft
        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));
            }
        }