Exemplo n.º 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]);
            }
        }
Exemplo n.º 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]);
        }
Exemplo n.º 3
0
        public void ReadWriteRegTest()
        {
            byte func      = 0x03;
            byte byteCount = 0x04;
            byte reg1ValHi = 0xAA;
            byte reg1ValLo = 0xBB;
            byte reg2ValHi = 0xCC;
            byte reg2ValLo = 0xDD;

            List <byte> response;
            List <byte> expected = new List <byte>();

            expected.Add(func);
            expected.Add(byteCount);
            expected.Add(reg1ValHi);
            expected.Add(reg1ValLo);
            expected.Add(reg2ValHi);
            expected.Add(reg2ValLo);

            MemoryMap memory = new MemoryMap();

            memory.AddHoldingRegister(new Register(0)
            {
                Value = 100
            });
            memory.AddHoldingRegister(new Register(1)
            {
                Value = 100
            });
            FunctionsImplementation imp = new FunctionsImplementation(memory);

            imp.FuncWriteSingleRegister(0, 0xAABB);
            imp.FuncWriteSingleRegister(1, 0xCCDD);
            response = imp.FuncReadHoldingRegisters(0, 2);
            for (int i = 0; i < response.Count; i++)
            {
                Assert.AreEqual(expected[i], response[i]);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void FuncWriteSingleRegisterResponseTest()
        {
            List <byte> expected = new List <byte>();

            expected.Add(0x06);
            expected.Add(0x00);
            expected.Add(0x00);
            expected.Add(0xAA);
            expected.Add(0xBB);
            MemoryMap memory = new MemoryMap();

            memory.AddHoldingRegister(new Register(0)
            {
                Value = 100
            });
            FunctionsImplementation imp      = new FunctionsImplementation(memory);
            List <byte>             response = imp.FuncWriteSingleRegister(0, 0xAABB);

            for (int i = 0; i < response.Count; i++)
            {
                Assert.AreEqual(expected[i], response[i]);
            }
        }
Exemplo n.º 7
0
        public void FuncWriteSingleRegisterTest()
        {
            UInt16      index       = 0;
            UInt16      register    = 0;
            List <byte> expected    = new List <byte>();
            List <byte> writedValue = new List <byte>();

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

            memory.AddHoldingRegister(new Register(0)
            {
                Value = 100
            });
            FunctionsImplementation imp = new FunctionsImplementation(memory);

            imp.FuncWriteSingleRegister(index, 0xAABB);
            register = memory.GetHoldingRegister(0);
            writedValue.AddRange(Utility.GetBytesFromReg(register));
            Assert.AreEqual(expected[0], writedValue[0]);
            Assert.AreEqual(expected[1], writedValue[1]);
        }