public void Validate_ThrowsOnStartingAddressMismatch()
        {
            var request  = new WriteFileRecordRequest(17, new FileRecordCollection(1, 2, new byte[] { 4, 5 }));
            var response = new WriteFileRecordResponse(17, new FileRecordCollection(1, 4, new byte[] { 4, 5 }));

            Assert.Throws <IOException>(() => request.ValidateResponse(response));
        }
示例#2
0
        /// <summary>
        /// Write a file record to the device.
        /// </summary>
        /// <param name="slaveAdress">Address of device to write values to</param>
        /// <param name="fileNumber">The Extended Memory file number</param>
        /// <param name="startingAddress">The starting register address within the file</param>
        /// <param name="data">The data to be written</param>
        public void WriteFileRecord(byte slaveAdress, ushort fileNumber, ushort startingAddress, byte[] data)
        {
            ValidateMaxData("data", data, 244);
            var request = new WriteFileRecordRequest(slaveAdress, new FileRecordCollection(
                                                         fileNumber, startingAddress, data));

            Transport.UnicastMessage <WriteFileRecordResponse>(request);
        }
        public void CreateModbusMessageWriteFileRecordRequest()
        {
            var request =
                ModbusMessageFactory.CreateModbusMessage <WriteFileRecordRequest>(new byte[]
                                                                                  { 17, ModbusFunctionCodes.WriteFileRecord, 9, 6, 0, 1, 0, 2, 0, 1, 1, 2 });
            var expectedRequest = new WriteFileRecordRequest(17, new FileRecordCollection(1, 2, new byte[] { 1, 2 }));

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedRequest, request);
        }
        public void Create()
        {
            var request = new WriteFileRecordRequest(17, new FileRecordCollection(1, 2, new byte[] { 4, 5 }));

            Assert.Equal(ModbusFunctionCodes.WriteFileRecord, request.FunctionCode);
            Assert.Equal(17, request.SlaveAddress);
            Assert.Equal(1, request.Data.FileNumber);
            Assert.Equal(2, request.Data.StartingAddress);
            Assert.Equal(new byte[] { 4, 5 }, request.Data.DataBytes);
        }
        public void Initialize()
        {
            var response = new WriteFileRecordRequest();

            response.Initialize(new byte[] {
                17, ModbusFunctionCodes.WriteFileRecord, 9, 6, 0, 1, 0, 2, 0, 1, 4, 5
            });

            Assert.Equal(ModbusFunctionCodes.WriteFileRecord, response.FunctionCode);
            Assert.Equal(17, response.SlaveAddress);
            Assert.Equal(1, response.Data.FileNumber);
            Assert.Equal(2, response.Data.StartingAddress);
            Assert.Equal(new byte[] { 4, 5 }, response.Data.DataBytes);
        }
        public void ToString_Test()
        {
            var request = new WriteFileRecordRequest(17, new FileRecordCollection(1, 2, new byte[] { 4, 5 }));

            Assert.Equal("Write 2 bytes for file 1 starting at address 2.", request.ToString());
        }