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); }
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); }
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()); }
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()); }
public void Resize() { DiscreteCollection col = new DiscreteCollection(byte.MaxValue, byte.MaxValue); Assert.AreEqual(16, col.Count); col.RemoveAt(3); Assert.AreEqual(15, col.Count); }
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()); }
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); }
public void AddCoil() { DiscreteCollection col = new DiscreteCollection(); Assert.Equal(0, col.Count); col.Add(true); Assert.Equal(1, col.Count); }
public void Resize() { DiscreteCollection col = new DiscreteCollection(byte.MaxValue, byte.MaxValue); Assert.Equal(16, col.Count); col.RemoveAt(3); Assert.Equal(15, col.Count); }
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()); }
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]); }
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()); }
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); }
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)); }
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); }
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); }
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); }
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(); }
public void CreateNewDiscreteCollectionFromBytesParams_ZeroLengthArray() { DiscreteCollection col = new DiscreteCollection(new byte[0]); Assert.Equal(0, col.Count); }
public void NetworkBytes() { DiscreteCollection col = new DiscreteCollection(true, true); Assert.Equal <byte[]>(new byte[] { 3 }, col.NetworkBytes); }
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); }
public void CreateNewDiscreteCollectionFromBoolParams() { DiscreteCollection col = new DiscreteCollection(true, false, true); Assert.AreEqual(3, col.Count); }
public void CreateNewDiscreteCollectionInitialize() { DiscreteCollection col = new DiscreteCollection(true, true, true); Assert.AreEqual(3, col.Count); Assert.IsFalse(col.Contains(false)); }
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()); }
public void ByteCountEven() { DiscreteCollection col = new DiscreteCollection(true, true, false, false, false, false, false, false); Assert.AreEqual(1, col.ByteCount); }
public void ByteCountEven() { DiscreteCollection col = new DiscreteCollection(true, true, false, false, false, false, false, false); Assert.Equal(1, col.ByteCount); }
public void NetworkBytes() { DiscreteCollection col = new DiscreteCollection(true, true); Assert.AreEqual(new byte[] { 3 }, col.NetworkBytes); }
public void CreateNewDiscreteCollectionFromBoolParams() { DiscreteCollection col = new DiscreteCollection(true, false, true); Assert.Equal(3, col.Count); }
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); }