Beispiel #1
0
        public void FuncReadHoldingRegistersDataTest()
        {
            List <byte> expected = new List <byte>();

            expected.Add(0xAA);
            expected.Add(0xBB);
            expected.Add(0xCC);
            expected.Add(0xDD);
            MemoryMap memory = new MemoryMap();

            memory.AddHoldingRegister(new Register(0)
            {
                Value = 100
            });
            memory.AddHoldingRegister(new Register(1)
            {
                Value = 100
            });
            memory.SetHoldingRegister(0, 0xAABB);
            memory.SetHoldingRegister(1, 0xCCDD);
            FunctionsImplementation imp      = new FunctionsImplementation(memory);
            List <byte>             response = imp.FuncReadHoldingRegisters(0, 2);

            for (int i = 2; i < response.Count; i++)
            {
                Assert.AreEqual(expected[i - 2], response[i]);
            }
        }
Beispiel #2
0
        public void FuncReadHoldingRegistersByteCountTest()
        {
            byte      expected = 0x04;
            MemoryMap memory   = new MemoryMap();

            memory.AddHoldingRegister(new Register(0)
            {
                Value = 100
            });
            memory.AddHoldingRegister(new Register(1)
            {
                Value = 100
            });
            memory.SetHoldingRegister(0, 0xAABB);
            memory.SetHoldingRegister(1, 0xCCDD);
            FunctionsImplementation imp      = new FunctionsImplementation(memory);
            List <byte>             response = imp.FuncReadHoldingRegisters(1, 2);

            Assert.AreEqual(expected, response[1]);
        }
Beispiel #3
0
        public void GetHoldingRegisterTest()
        {
            UInt16    index = 10;
            MemoryMap map   = new MemoryMap();

            map.AddHoldingRegister(new Register(index)
            {
                Value = 100
            });
            map.SetHoldingRegister(index, 100);
            UInt16 result = map.GetHoldingRegister(index);

            Assert.AreEqual(result, 100);
        }
Beispiel #4
0
        public void SetHoldingRegisterTest()
        {
            UInt16    index   = 0;
            UInt16    address = 3;
            MemoryMap map     = new MemoryMap();

            map.AddHoldingRegister(new Register(address)
            {
                Value = 100
            });
            map.SetHoldingRegister(address, 100);
            UInt16 result = map.HoldingRegisters[index].Value;

            Assert.AreEqual(result, 100);
        }