public void WriteDataSingle()
 {
     ModbusDataCollection<bool> destination = new ModbusDataCollection<bool>(true, true);
     DiscreteCollection newValues = new DiscreteCollection(false);
     DataStore.WriteData(new DataStore(), newValues, destination, 0, new object());
     Assert.Equal(false, destination[1]);
 }
 public void DataReadCoilsResponse()
 {
     DiscreteCollection col = new DiscreteCollection(false, true, false, true, false, true, false, false, false, false);
     ModbusMessageWithData<DiscreteCollection> message = new ReadCoilsInputsResponse(Modbus.ReadCoils, 11, 1, col);
     Assert.AreEqual(col.Count, message.Data.Count);
     Assert.AreEqual(col.NetworkBytes, message.Data.NetworkBytes);
 }
예제 #3
0
        internal static ReadCoilsInputsResponse ReadDiscretes(ReadCoilsInputsRequest request, DataStore dataStore, ModbusDataCollection <bool> dataSource)
        {
            DiscreteCollection      data     = DataStore.ReadData <DiscreteCollection, bool>(dataStore, dataSource, request.StartAddress, request.NumberOfPoints, dataStore.SyncRoot);
            ReadCoilsInputsResponse response = new ReadCoilsInputsResponse(request.FunctionCode, request.SlaveAddress, data.ByteCount, data);

            return(response);
        }
예제 #4
0
        public void WriteDataTooLarge()
        {
            ModbusDataCollection <bool> slaveCol  = new ModbusDataCollection <bool>(true);
            DiscreteCollection          newValues = new DiscreteCollection(false, false);

            Assert.Throws <InvalidModbusRequestException>(() => new DataStore().WriteData(newValues, slaveCol, 1, new object()));
        }
        public void ToString_WriteMultipleCoilsRequest()
        {
            DiscreteCollection        col     = new DiscreteCollection(true, false, true, false, true, true, true, false, false);
            WriteMultipleCoilsRequest request = new WriteMultipleCoilsRequest(34, 45, col);

            Assert.AreEqual("Write 9 coils starting at address 45.", request.ToString());
        }
예제 #6
0
		public void WriteDataMultiple()
		{
			ModbusDataCollection<bool> destination = new ModbusDataCollection<bool>(false, false, false, false, false, false, true);
			DiscreteCollection newValues = new DiscreteCollection(true, true, true, true);
			DataStore.WriteData(new DataStore(), newValues, destination, 0, new object());
			Assert.AreEqual(new bool[] { false, true, true, true, true, false, false, true }, destination.ToArray());
		}
예제 #7
0
		public void Resize()
		{
			DiscreteCollection col = new DiscreteCollection(byte.MaxValue, byte.MaxValue);
			Assert.AreEqual(16, col.Count);
			col.RemoveAt(3);
			Assert.AreEqual(15, col.Count);
		}
예제 #8
0
        public void WriteDataTooLarge()
        {
            ModbusDataCollection <bool> slaveCol  = new ModbusDataCollection <bool>(true);
            DiscreteCollection          newValues = new DiscreteCollection(false, false);

            DataStore.WriteData(new DataStore(), newValues, slaveCol, 1, new object());
        }
        public void ToString_WriteMultipleCoilsRequest()
        {
            DiscreteCollection col = new DiscreteCollection(true, false, true, false, true, true, true, false, false);
            WriteMultipleCoilsRequest request = new WriteMultipleCoilsRequest(34, 45, col);

            Assert.Equal("Write 9 coils starting at address 45.", request.ToString());
        }
예제 #10
0
        public void CreateNewDiscreteCollectionInitialize()
        {
            DiscreteCollection col = new DiscreteCollection(true, true, true);

            Assert.Equal(3, col.Count);
            Assert.False((bool)col.Contains(false));
        }
 public void AddCoil()
 {
     DiscreteCollection col = new DiscreteCollection();
     Assert.AreEqual(0, col.Count);
     col.Add(true);
     Assert.AreEqual(1, col.Count);
 }
예제 #12
0
        public void AddCoil()
        {
            DiscreteCollection col = new DiscreteCollection();

            Assert.Equal(0, col.Count);
            col.Add(true);
            Assert.Equal(1, col.Count);
        }
예제 #13
0
        public void Resize()
        {
            DiscreteCollection col = new DiscreteCollection(byte.MaxValue, byte.MaxValue);

            Assert.Equal(16, col.Count);
            col.RemoveAt(3);
            Assert.Equal(15, col.Count);
        }
예제 #14
0
        public void DataReadCoilsResponse()
        {
            DiscreteCollection col = new DiscreteCollection(false, true, false, true, false, true, false, false, false, false);
            ModbusMessageWithData <DiscreteCollection> message = new ReadCoilsInputsResponse(Modbus.ReadCoils, 11, 1, col);

            Assert.AreEqual(col.Count, message.Data.Count);
            Assert.AreEqual(col.NetworkBytes, message.Data.NetworkBytes);
        }
 public void CreateNewDiscreteCollectionFromBytesParamsOrder2()
 {
     DiscreteCollection col = new DiscreteCollection(157, 7);
     Assert.AreEqual(
         new bool[]
         {true, false, true, true, true, false, false, true, true, true, true, false, false, false, false, false},
         col.ToArray());
 }
예제 #16
0
        public void WriteDataSingle()
        {
            ModbusDataCollection <bool> destination = new ModbusDataCollection <bool>(true, true);
            DiscreteCollection          newValues   = new DiscreteCollection(false);

            DataStore.WriteData(new DataStore(), newValues, destination, 0, new object());
            Assert.AreEqual(false, destination[1]);
        }
예제 #17
0
        public void WriteDataMultiple()
        {
            ModbusDataCollection <bool> destination = new ModbusDataCollection <bool>(false, false, false, false, false, false, true);
            DiscreteCollection          newValues   = new DiscreteCollection(true, true, true, true);

            DataStore.WriteData(new DataStore(), newValues, destination, 0, new object());
            Assert.AreEqual(new bool[] { false, true, true, true, true, false, false, true }, destination.ToArray());
        }
예제 #18
0
		public void BytesPersistence()
		{
			DiscreteCollection col = new DiscreteCollection(byte.MaxValue, byte.MaxValue);
			Assert.AreEqual(16, col.Count);
			byte[] originalBytes = col.NetworkBytes;
			col.RemoveAt(3);
			Assert.AreEqual(15, col.Count);
			Assert.AreNotEqual(originalBytes, col.NetworkBytes);
		}
예제 #19
0
        public void CreateNewDiscreteCollectionFromBytesParamsOrder2()
        {
            DiscreteCollection col = new DiscreteCollection(157, 7);

            Assert.Equal(
                new bool[]
                { true, false, true, true, true, false, false, true, true, true, true, false, false, false, false, false },
                Enumerable.ToArray <bool>(col));
        }
예제 #20
0
        public void CreateNewDiscreteCollectionFromBytesParamsOrder2()
        {
            var col = new DiscreteCollection(157, 7);

            Assert.Equal(
                new bool[]
                { true, false, true, true, true, false, false, true, true, true, true, false, false, false, false, false },
                col.ToArray());
        }
 public void CreateReadInputsResponse()
 {
     ReadCoilsInputsResponse response = new ReadCoilsInputsResponse(Modbus.ReadInputs, 5, 2, new DiscreteCollection(true, true, true, true, true, true, false, false, true, true, false));
     Assert.AreEqual(Modbus.ReadInputs, response.FunctionCode);
     Assert.AreEqual(5, response.SlaveAddress);
     Assert.AreEqual(2, response.ByteCount);
     DiscreteCollection col = new DiscreteCollection(true, true, true, true, true, true, false, false, true, true, false);
     Assert.AreEqual(col.NetworkBytes, response.Data.NetworkBytes);
 }
예제 #22
0
        public void BytesPersistence()
        {
            DiscreteCollection col = new DiscreteCollection(byte.MaxValue, byte.MaxValue);

            Assert.Equal(16, col.Count);
            byte[] originalBytes = col.NetworkBytes;
            col.RemoveAt(3);
            Assert.Equal(15, col.Count);
            Assert.NotEqual <byte[]>(originalBytes, col.NetworkBytes);
        }
 public void CreateWriteMultipleCoilsRequest()
 {
     DiscreteCollection col = new DiscreteCollection(true, false, true, false, true, true, true, false, false);
     WriteMultipleCoilsRequest request = new WriteMultipleCoilsRequest(34, 45, col);
     Assert.Equal(Modbus.WriteMultipleCoils, request.FunctionCode);
     Assert.Equal(34, request.SlaveAddress);
     Assert.Equal(45, request.StartAddress);
     Assert.Equal(9, request.NumberOfPoints);
     Assert.Equal(2, request.ByteCount);
     Assert.Equal(col.NetworkBytes, request.Data.NetworkBytes);
 }
        public void CreateReadInputsResponse()
        {
            ReadCoilsInputsResponse response = new ReadCoilsInputsResponse(Modbus.ReadInputs, 5, 2, new DiscreteCollection(true, true, true, true, true, true, false, false, true, true, false));

            Assert.AreEqual(Modbus.ReadInputs, response.FunctionCode);
            Assert.AreEqual(5, response.SlaveAddress);
            Assert.AreEqual(2, response.ByteCount);
            DiscreteCollection col = new DiscreteCollection(true, true, true, true, true, true, false, false, true, true, false);

            Assert.AreEqual(col.NetworkBytes, response.Data.NetworkBytes);
        }
예제 #25
0
        protected override IModbusMessage Handle(ReadCoilsInputsRequest request, ISlaveDataStore dataStore)
        {
            bool[] discretes = dataStore.CoilDiscretes.ReadPoints(request.StartAddress, request.NumberOfPoints);

            DiscreteCollection data = new DiscreteCollection(discretes);

            return(new ReadCoilsInputsResponse(
                       request.FunctionCode,
                       request.SlaveAddress,
                       data.ByteCount, data));
        }
        public void CreateWriteMultipleCoilsRequest()
        {
            DiscreteCollection        col     = new DiscreteCollection(true, false, true, false, true, true, true, false, false);
            WriteMultipleCoilsRequest request = new WriteMultipleCoilsRequest(34, 45, col);

            Assert.AreEqual(Modbus.WriteMultipleCoils, request.FunctionCode);
            Assert.AreEqual(34, request.SlaveAddress);
            Assert.AreEqual(45, request.StartAddress);
            Assert.AreEqual(9, request.NumberOfPoints);
            Assert.AreEqual(2, request.ByteCount);
            Assert.AreEqual(col.NetworkBytes, request.Data.NetworkBytes);
        }
        public void CreateNewDiscreteCollectionFromBytesParams()
        {
            DiscreteCollection col = new DiscreteCollection(1, 2, 3);
            Assert.Equal(24, col.Count);
            var expected = new bool[]
            {
                true, false, false, false, false, false, false, false,
                false, true, false, false, false, false, false, false,
                true, true, false, false, false, false, false, false,
            };

            Assert.Equal(expected, col);
        }
예제 #28
0
        public void CreateNewDiscreteCollectionFromBytesParams()
        {
            DiscreteCollection col = new DiscreteCollection(1, 2, 3);

            Assert.Equal(24, col.Count);
            var expected = new bool[]
            {
                true, false, false, false, false, false, false, false,
                false, true, false, false, false, false, false, false,
                true, true, false, false, false, false, false, false,
            };

            Assert.Equal(expected, col);
        }
예제 #29
0
        public void UnicastMessage()
        {
            var data = new DiscreteCollection(true, false, true, false, false, false, false, false);
            var mock = new Mock <ModbusTransport>()
            {
                CallBase = true
            };
            var transport = mock.Object;

            mock.Setup(t => t.Write(It.IsNotNull <IModbusMessage>()));
            mock.Setup(t => t.ReadResponse <ReadCoilsInputsResponse>())
            .Returns(new ReadCoilsInputsResponse(Modbus.ReadCoils, 2, 1, data));
            mock.Setup(t => t.OnValidateResponse(It.IsNotNull <IModbusMessage>(), It.IsNotNull <IModbusMessage>()));

            var request          = new ReadCoilsInputsRequest(Modbus.ReadCoils, 2, 3, 4);
            var expectedResponse = new ReadCoilsInputsResponse(Modbus.ReadCoils, 2, 1, data);
            var response         = transport.UnicastMessage <ReadCoilsInputsResponse>(request);

            Assert.Equal(expectedResponse.MessageFrame, response.MessageFrame);
            mock.VerifyAll();
        }
예제 #30
0
        public void CreateNewDiscreteCollectionFromBytesParams_ZeroLengthArray()
        {
            DiscreteCollection col = new DiscreteCollection(new byte[0]);

            Assert.Equal(0, col.Count);
        }
예제 #31
0
        public void NetworkBytes()
        {
            DiscreteCollection col = new DiscreteCollection(true, true);

            Assert.Equal <byte[]>(new byte[] { 3 }, col.NetworkBytes);
        }
예제 #32
0
 public void WriteDataTooLarge()
 {
     ModbusDataCollection<bool> slaveCol = new ModbusDataCollection<bool>(true);
     DiscreteCollection newValues = new DiscreteCollection(false, false);
     Assert.Throws<InvalidModbusRequestException>(() => DataStore.WriteData(new DataStore(), newValues, slaveCol, 1, new object()));
 }
        public void ByteCount()
        {
            DiscreteCollection col = new DiscreteCollection(true, true, false, false, false, false, false, false, false);

            Assert.AreEqual(2, col.ByteCount);
        }
예제 #34
0
		public void CreateNewDiscreteCollectionFromBoolParams()
		{
			DiscreteCollection col = new DiscreteCollection(true, false, true);
			Assert.AreEqual(3, col.Count);
		}
예제 #35
0
		public void CreateNewDiscreteCollectionInitialize()
		{
			DiscreteCollection col = new DiscreteCollection(true, true, true);
			Assert.AreEqual(3, col.Count);
			Assert.IsFalse(col.Contains(false));
		}
 public void CreateNewDiscreteCollectionFromBytesParams_ZeroLengthArray()
 {
     DiscreteCollection col = new DiscreteCollection(new byte[0]);
     Assert.Equal(0, col.Count);
 }
        public void CreateNewDiscreteCollectionFromBytesParams()
        {
            DiscreteCollection col = new DiscreteCollection(1, 2, 3);

            Assert.AreEqual(24, col.Count);
        }
        public void CreateNewDiscreteCollectionFromBytesParamsOrder()
        {
            DiscreteCollection col = new DiscreteCollection(194);

            Assert.AreEqual(new bool[] { false, true, false, false, false, false, true, true }, col.ToArray());
        }
예제 #39
0
		public void CreateNewDiscreteCollectionFromBytesParams()
		{
			DiscreteCollection col = new DiscreteCollection(1, 2, 3);
			Assert.AreEqual(24, col.Count);
		}
예제 #40
0
		public void ByteCountEven()
		{
			DiscreteCollection col = new DiscreteCollection(true, true, false, false, false, false, false, false);
			Assert.AreEqual(1, col.ByteCount);
		}
예제 #41
0
        public void ByteCountEven()
        {
            DiscreteCollection col = new DiscreteCollection(true, true, false, false, false, false, false, false);

            Assert.Equal(1, col.ByteCount);
        }
예제 #42
0
		public void NetworkBytes()
		{
			DiscreteCollection col = new DiscreteCollection(true, true);
			Assert.AreEqual(new byte[] { 3 }, col.NetworkBytes);
		}
예제 #43
0
        public void CreateNewDiscreteCollectionFromBoolParams()
        {
            DiscreteCollection col = new DiscreteCollection(true, false, true);

            Assert.Equal(3, col.Count);
        }
예제 #44
0
 public void WriteDataTooLarge()
 {
     ModbusDataCollection<bool> slaveCol = new ModbusDataCollection<bool>(true);
     DiscreteCollection newValues = new DiscreteCollection(false, false);
     DataStore.WriteData(new DataStore(), newValues, slaveCol, 1, new object());
 }
 public void ByteCount()
 {
     DiscreteCollection col = new DiscreteCollection(true, true, false, false, false, false, false, false, false);
     Assert.Equal(2, col.ByteCount);
 }