Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="slaveAddress"></param>
 /// <param name="startReadAddress"></param>
 /// <param name="numberOfPointsToRead"></param>
 /// <param name="startWriteAddress"></param>
 /// <param name="writeData"></param>
 public ReadWriteMultipleRegistersRequest(byte slaveAddress, ushort startReadAddress, ushort numberOfPointsToRead,
                                          ushort startWriteAddress, RegisterCollection writeData)
     : base(slaveAddress, Modbus.ReportSlaveId)
 {
     _readRequest = new ReadHoldingInputRegistersRequest(Modbus.ReadHoldingRegisters, slaveAddress,
                                                         startReadAddress, numberOfPointsToRead);
     _writeRequest = new WriteMultipleRegistersRequest(slaveAddress, startWriteAddress, writeData);
 }
        protected override void InitializeUnique(byte[] frame)
        {
            if (frame.Length < _minimumFrameSize + frame[10])
            {
                throw new FormatException("Message frame does not contain enough bytes.");
            }

            byte[] readFrame  = CollectionUtility.Slice(frame, 2, 4);
            byte[] writeFrame = CollectionUtility.Slice(frame, 6, frame.Length - 6);
            byte[] header     = { SlaveAddress, FunctionCode };

            _readRequest  = ModbusMessageFactory.CreateModbusMessage <ReadHoldingInputRegistersRequest>(CollectionUtility.Concat(header, readFrame));
            _writeRequest = ModbusMessageFactory.CreateModbusMessage <WriteMultipleRegistersRequest>(CollectionUtility.Concat(header, writeFrame));
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="frame"></param>
        protected override void InitializeUnique(byte[] frame)
        {
            if (frame.Length < MinimumFrameSize + frame[10])
            {
                throw new FormatException("Message frame does not contain enough bytes.");
            }

            byte[] readFrame  = new byte[2 + 4];
            byte[] writeFrame = new byte[frame.Length - 6 + 2];

            readFrame[0] = writeFrame[0] = SlaveAddress;
            readFrame[1] = writeFrame[1] = FunctionCode;

            Buffer.BlockCopy(frame, 2, readFrame, 2, 4);
            Buffer.BlockCopy(frame, 6, writeFrame, 2, frame.Length - 6);

            _readRequest  = ModbusMessageFactory.CreateModbusMessage <ReadHoldingInputRegistersRequest>(readFrame);
            _writeRequest = ModbusMessageFactory.CreateModbusMessage <WriteMultipleRegistersRequest>(writeFrame);
        }