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 CreateModbusMessageReadHoldingRegistersResponse()
        {
            ReadHoldingInputRegistersResponse response =
                ModbusMessageFactory.CreateModbusMessage <ReadHoldingInputRegistersResponse>(new byte[]
                                                                                             { 11, ModbusFunctionCodes.ReadHoldingRegisters, 4, 0, 3, 0, 4 });
            ReadHoldingInputRegistersResponse expectedResponse =
                new ReadHoldingInputRegistersResponse(ModbusFunctionCodes.ReadHoldingRegisters, 11, new RegisterCollection(3, 4));

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedResponse, response);
        }
        public void CreateModbusMessageReadCoilsResponse()
        {
            ReadCoilsInputsResponse response =
                ModbusMessageFactory.CreateModbusMessage <ReadCoilsInputsResponse>(new byte[]
                                                                                   { 11, ModbusFunctionCodes.ReadCoils, 1, 1 });
            ReadCoilsInputsResponse expectedResponse = new ReadCoilsInputsResponse(ModbusFunctionCodes.ReadCoils, 11, 1,
                                                                                   new DiscreteCollection(true, false, false, false));

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedResponse, response);
            Assert.Equal(expectedResponse.Data.NetworkBytes, response.Data.NetworkBytes);
        }
        public void CreateModbusMessageReadWriteMultipleRegistersRequest()
        {
            ReadWriteMultipleRegistersRequest request =
                ModbusMessageFactory.CreateModbusMessage <ReadWriteMultipleRegistersRequest>(new byte[]
                                                                                             { 0x05, 0x17, 0x00, 0x03, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x03, 0x06, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff });
            RegisterCollection writeCollection = new RegisterCollection(255, 255, 255);
            ReadWriteMultipleRegistersRequest expectedRequest = new ReadWriteMultipleRegistersRequest(5, 3, 6, 14,
                                                                                                      writeCollection);

            ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(expectedRequest, request);
        }
        public void CreateModbusMessageWriteMultipleCoilsResponse()
        {
            WriteMultipleCoilsResponse response =
                ModbusMessageFactory.CreateModbusMessage <WriteMultipleCoilsResponse>(new byte[]
                                                                                      { 17, ModbusFunctionCodes.WriteMultipleCoils, 0, 19, 0, 10 });
            WriteMultipleCoilsResponse expectedResponse = new WriteMultipleCoilsResponse(17, 19, 10);

            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);
        }