public void ProtocolDataUnit()
 {
     RegisterCollection data = new RegisterCollection(1, 2, 3, 4);
     DiagnosticsRequestResponse request = new DiagnosticsRequestResponse(Modbus.DiagnosticsReturnQueryData, 5,
         data);
     Assert.Equal(new byte[] {8, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4}, request.ProtocolDataUnit);
 }
		public void ReturnQueryDataRequestResponse()
		{
			RegisterCollection data = new RegisterCollection(1, 2, 3, 4);
			DiagnosticsRequestResponse request = new DiagnosticsRequestResponse(Modbus.DiagnosticsReturnQueryData, 5, data);
			Assert.AreEqual(Modbus.Diagnostics, request.FunctionCode);
			Assert.AreEqual(Modbus.DiagnosticsReturnQueryData, request.SubFunctionCode);
			Assert.AreEqual(5, request.SlaveAddress);
			Assert.AreEqual(data.NetworkBytes, request.Data.NetworkBytes);
		}
Esempio n. 3
0
        public void CreateModbusMessageReturnQueryDataRequestResponse()
        {
            const byte         slaveAddress = 5;
            RegisterCollection data         = new RegisterCollection(50);

            byte[] frame = new byte[] { slaveAddress, 8, 0, 0 }.Concat(data.NetworkBytes).ToArray();
            DiagnosticsRequestResponse message =
                ModbusMessageFactory.CreateModbusMessage <DiagnosticsRequestResponse>(frame);
            DiagnosticsRequestResponse expectedMessage =
                new DiagnosticsRequestResponse(Modbus.DiagnosticsReturnQueryData, slaveAddress, data);

            Assert.Equal(expectedMessage.SubFunctionCode, message.SubFunctionCode);
            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedMessage, message);
        }
        /// <summary>
        ///     Serial Line only.
        ///     Diagnostic function which loops back the original data.
        ///     NModbus only supports looping back one ushort value, this is a limitation of the "Best Effort" implementation of
        ///     the RTU protocol.
        /// </summary>
        /// <param name="slaveAddress">Address of device to test.</param>
        /// <param name="data">Data to return.</param>
        /// <returns>Return true if slave device echoed data.</returns>
        public bool ReturnQueryData(byte slaveAddress, ushort data)
        {
            DiagnosticsRequestResponse request;
            DiagnosticsRequestResponse response;

            request = new DiagnosticsRequestResponse(
                Modbus.DiagnosticsReturnQueryData,
                slaveAddress,
                new RegisterCollection(data));

            response = Transport.UnicastMessage <DiagnosticsRequestResponse>(request);

            return(response.Data[0] == data);
        }
 public void CreateModbusRequestForDiagnostics()
 {
     DiagnosticsRequestResponse diagnosticsRequest = new DiagnosticsRequestResponse(0, 2,
         new RegisterCollection(45));
     IModbusMessage request = ModbusMessageFactory.CreateModbusRequest(diagnosticsRequest.MessageFrame);
     Assert.AreEqual(typeof (DiagnosticsRequestResponse), request.GetType());
 }
        public void CreateModbusMessageReturnQueryDataRequestResponse()
        {
            const byte slaveAddress = 5;
            RegisterCollection data = new RegisterCollection(50);
            byte[] frame = new byte[] { slaveAddress, 8, 0, 0 }.Concat(data.NetworkBytes).ToArray();
            DiagnosticsRequestResponse message =
                ModbusMessageFactory.CreateModbusMessage<DiagnosticsRequestResponse>(frame);
            DiagnosticsRequestResponse expectedMessage =
                new DiagnosticsRequestResponse(Modbus.DiagnosticsReturnQueryData, slaveAddress, data);

            Assert.AreEqual(expectedMessage.SubFunctionCode, message.SubFunctionCode);
            AssertModbusMessagePropertiesAreEqual(expectedMessage, message);
        }
        public void ToString_Test()
        {
            var message = new DiagnosticsRequestResponse(Modbus.DiagnosticsReturnQueryData, 3, new RegisterCollection(5));

            Assert.AreEqual("Diagnostics message, sub-function return query data - {5}.", message.ToString());
        }
Esempio n. 8
0
		/// <summary>
		/// Serial Line only.
		/// Diagnostic function which loops back the original data.
		/// NModbus only supports looping back one ushort value, this is a limitation of the "Best Effort" implementation of the RTU protocol.
		/// </summary>
		/// <param name="slaveAddress">Address of device to test.</param>
		/// <param name="data">Data to return.</param>
		/// <returns>Return true if slave device echoed data.</returns>
		public bool ReturnQueryData(byte slaveAddress, ushort data)
		{
			DiagnosticsRequestResponse request = new DiagnosticsRequestResponse(Modbus.DiagnosticsReturnQueryData, slaveAddress, new RegisterCollection(data));
			DiagnosticsRequestResponse response = Transport.UnicastMessage<DiagnosticsRequestResponse>(request);

			return response.Data[0] == data;
		}
 public void CreateModbusMessageReturnQueryDataRequestResponseTooSmall()
 {
     byte[] frame = new byte[] { 5, 8, 0, 0, 5 };
     DiagnosticsRequestResponse message = ModbusMessageFactory.CreateModbusMessage <DiagnosticsRequestResponse>(frame);
 }
        public void ToString_Test()
        {
            var message = new DiagnosticsRequestResponse(Modbus.DiagnosticsReturnQueryData, 3, new RegisterCollection(5));

            Assert.Equal("Diagnostics message, sub-function return query data - {5}.", message.ToString());
        }
        public void CreateModbusRequestForDiagnostics()
        {
            MockRepository mocks = new MockRepository();
            var mockSlave = mocks.PartialMock<ModbusSlave>((byte) 1, new EmptyTransport());

            DiagnosticsRequestResponse diagnosticsRequest = new DiagnosticsRequestResponse(0, 2, new RegisterCollection(45));
            IModbusMessage request = ModbusMessageFactory.CreateModbusRequest(mockSlave, diagnosticsRequest.MessageFrame);
            Assert.AreEqual(typeof(DiagnosticsRequestResponse), request.GetType());
        }