Ejemplo n.º 1
0
        /// <summary>
        ///    Reads contiguous block of holding registers.
        /// </summary>
        /// <param name="slaveAddress">Address of device to read values from.</param>
        /// <param name="startAddress">Address to begin reading.</param>
        /// <param name="numberOfPoints">Number of holding registers to read.</param>
        /// <returns>Holding registers status</returns>
        public ushort[] ReadHoldingRegisters(byte slaveAddress, ushort startAddress, ushort numberOfPoints, byte registerSize)
        {
            ValidateNumberOfPoints("numberOfPoints", numberOfPoints, 125);

            switch (registerSize)
            {
            case 4:
                var request = new ReadHoldingInputRegistersRequest32(
                    Modbus.ReadHoldingRegisters,
                    slaveAddress,
                    startAddress,
                    numberOfPoints);
                return(PerformReadRegisters(request));

                break;

            default:
                return(ReadHoldingRegisters(slaveAddress, startAddress, numberOfPoints));

                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///    Asynchronously reads contiguous block of holding registers.
        /// </summary>
        /// <param name="slaveAddress">Address of device to read values from.</param>
        /// <param name="startAddress">Address to begin reading.</param>
        /// <param name="numberOfPoints">Number of holding registers to read.</param>
        /// <returns>A task that represents the asynchronous read operation</returns>
        public Task <ushort[]> ReadHoldingRegistersAsync(byte slaveAddress, ushort startAddress, ushort numberOfPoints, byte registerSize)
        {
            ValidateNumberOfPoints("numberOfPoints", numberOfPoints, 125);
            ReadHoldingInputRegistersRequest request;

            switch (registerSize)
            {
            case 4:
                request = new ReadHoldingInputRegistersRequest32(
                    Modbus.ReadHoldingRegisters,
                    slaveAddress,
                    startAddress,
                    numberOfPoints);
                return(PerformReadRegistersAsync(request));

            default:
                request = new ReadHoldingInputRegistersRequest(
                    Modbus.ReadHoldingRegisters,
                    slaveAddress,
                    startAddress,
                    numberOfPoints);
                return(PerformReadRegistersAsync(request));
            }
        }