Exemple #1
0
    private async Task <byte[]> ReadBlockAsync(ModbusReadBlockConfiguration readBlock)
    {
        switch (readBlock.Function)
        {
        case ModbusFunctions.ReadCoilStatus:
        {
            var result = await modbusClient.ReadCoilsAsync(readBlock.AddressOffset, readBlock.Count);

            return(result);
        }

        case ModbusFunctions.ReadInputStatus:
        {
            var result = await modbusClient.ReadInputsAsync(readBlock.AddressOffset, readBlock.Count);

            return(result);
        }

        case ModbusFunctions.ReadHoldingRegister:
        {
            var result = await modbusClient.ReadHoldingRegistersAsync(readBlock.AddressOffset, readBlock.Count);

            return(readBlock.ByteSwap ? result.ReadDataByteSwap() : result.RawData);
        }

        case ModbusFunctions.ReadInputRegister:
        {
            var result = await modbusClient.ReadInputRegistersAsync(readBlock.AddressOffset, readBlock.Count);

            return(readBlock.ByteSwap ? result.ReadDataByteSwap() : result.RawData);
        }

        default:
            return(null);
        }
    }