public void CreateModbusMessageWriteMultipleRegistersResponse()
        {
            WriteMultipleRegistersResponse response =
                ModbusMessageFactory.CreateModbusMessage <WriteMultipleRegistersResponse>(new byte[]
                                                                                          { 17, ModbusFunctionCodes.WriteMultipleRegisters, 0, 1, 0, 2 });
            WriteMultipleRegistersResponse expectedResponse = new WriteMultipleRegistersResponse(17, 1, 2);

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedResponse, response);
            Assert.Equal(expectedResponse.StartAddress, response.StartAddress);
            Assert.Equal(expectedResponse.NumberOfPoints, response.NumberOfPoints);
        }
        public void CreateModbusMessageWriteSingleRegisterRequestResponse()
        {
            WriteSingleRegisterRequestResponse request =
                ModbusMessageFactory.CreateModbusMessage <WriteSingleRegisterRequestResponse>(new byte[]
                                                                                              { 17, ModbusFunctionCodes.WriteSingleRegister, 0, 1, 0, 3 });
            WriteSingleRegisterRequestResponse expectedRequest = new WriteSingleRegisterRequestResponse(17, 1, 3);

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedRequest, request);
            Assert.Equal(expectedRequest.StartAddress, request.StartAddress);
            Assert.Equal(expectedRequest.Data.NetworkBytes, request.Data.NetworkBytes);
        }
        public void CreateModbusMessageReadCoilsRequest()
        {
            ReadCoilsInputsRequest request =
                ModbusMessageFactory.CreateModbusMessage <ReadCoilsInputsRequest>(new byte[]
                                                                                  { 11, ModbusFunctionCodes.ReadCoils, 0, 19, 0, 37 });
            ReadCoilsInputsRequest expectedRequest = new ReadCoilsInputsRequest(ModbusFunctionCodes.ReadCoils, 11, 19, 37);

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(request, expectedRequest);
            Assert.Equal(expectedRequest.StartAddress, request.StartAddress);
            Assert.Equal(expectedRequest.NumberOfPoints, request.NumberOfPoints);
        }
        public void CreateModbusMessageReadHoldingRegistersRequest()
        {
            ReadHoldingInputRegistersRequest request =
                ModbusMessageFactory.CreateModbusMessage <ReadHoldingInputRegistersRequest>(new byte[]
                                                                                            { 17, ModbusFunctionCodes.ReadHoldingRegisters, 0, 107, 0, 3 });
            ReadHoldingInputRegistersRequest expectedRequest =
                new ReadHoldingInputRegistersRequest(ModbusFunctionCodes.ReadHoldingRegisters, 17, 107, 3);

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedRequest, request);
            Assert.Equal(expectedRequest.StartAddress, request.StartAddress);
            Assert.Equal(expectedRequest.NumberOfPoints, request.NumberOfPoints);
        }
        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(ModbusFunctionCodes.DiagnosticsReturnQueryData, slaveAddress, data);

            Assert.Equal(expectedMessage.SubFunctionCode, message.SubFunctionCode);
            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedMessage, message);
        }
        public void CreateModbusMessageWriteMultipleCoilsRequest()
        {
            WriteMultipleCoilsRequest request =
                ModbusMessageFactory.CreateModbusMessage <WriteMultipleCoilsRequest>(new byte[]
                                                                                     { 17, ModbusFunctionCodes.WriteMultipleCoils, 0, 19, 0, 10, 2, 205, 1 });
            WriteMultipleCoilsRequest expectedRequest = new WriteMultipleCoilsRequest(17, 19,
                                                                                      new DiscreteCollection(true, false, true, true, false, false, true, true, true, false));

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedRequest, request);
            Assert.Equal(expectedRequest.StartAddress, request.StartAddress);
            Assert.Equal(expectedRequest.NumberOfPoints, request.NumberOfPoints);
            Assert.Equal(expectedRequest.ByteCount, request.ByteCount);
            Assert.Equal(expectedRequest.Data.NetworkBytes, request.Data.NetworkBytes);
        }
        public void CreateModbusMessageWriteMultipleRegistersRequest()
        {
            WriteMultipleRegistersRequest request =
                ModbusMessageFactory.CreateModbusMessage <WriteMultipleRegistersRequest>(new byte[]
                                                                                         { 11, ModbusFunctionCodes.WriteMultipleRegisters, 0, 5, 0, 1, 2, 255, 255 });
            WriteMultipleRegistersRequest expectedRequest = new WriteMultipleRegistersRequest(11, 5,
                                                                                              new RegisterCollection(ushort.MaxValue));

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedRequest, request);
            Assert.Equal(expectedRequest.StartAddress, request.StartAddress);
            Assert.Equal(expectedRequest.NumberOfPoints, request.NumberOfPoints);
            Assert.Equal(expectedRequest.ByteCount, request.ByteCount);
            Assert.Equal(expectedRequest.Data.NetworkBytes, request.Data.NetworkBytes);
        }