/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
    \page qtserialbus-libmodbus-overview.html
    \title Using libmodbus Backend

    \brief Overview of how to use the libmodbus backend.

    Libmodbus is a free software library to send/receive data according to the Modbus protocol.
    Libmodbus only supports TCP and serial port connections.

    \section1 Creating Modbus Devices

    At first it is necessary to check that QModbus provides the desired backend:

    \code
        foreach (const QByteArray &backend, QCanBus::instance()->plugins()) {
            if (backend == "libmodbus") {
                // were found
                break;
            }
        }
    \endcode

    Where, \e libmodbus is the backend name.

    Further, it is necessary to request from QModbus the device with the active libmodbus
    interface.
    As libmodbus device may be either client or server device, you have to choose between
    QModbus::createServer() and QModbus::createClient() as appropriate:

    \code
        QModbusServer *server = QModbus::createServer("libmodbus");
    \endcode

    or

    \code
        QModbusClient *client = QModbus::createClient("libmodbus");
    \endcode

    For every server, tables must be initialized before connecting it to the network.
    Next example will set up every table to be size of ten values. Maps can also
    be not set at all, in that case they will be size zero. Value of every field is
    initialized to zero.

    \code
        modbusServer->setMap(QModbusDevice::DiscreteInputs, 10);
        modbusServer->setMap(QModbusDevice::Coils, 10);
        modbusServer->setMap(QModbusDevice::InputRegisters, 10);
        modbusServer->setMap(QModbusDevice::HoldingRegisters, 10);
    \endcode

    Before connection each device must also be given a connection to the network.
    Remember that libmodbus only supports serial port and tcp. Application data unit (ADU)
    is the package type specified for the connection type. Generally serial port uses
    QModbusDevice::RemoteTerminalUnit adu and tcp uses QModbusDevice::TCP adu.

    \code
        QSerialPort *serialPort = new QSerialPort("ttyS0");
        modbusServer->setDevice(serialPort, QModbusDevice::RemoteTerminalUnit)
        modbusServer->setSlaveId(1);
        modbusServer->connectDevice();
    \endcode

    Reading and writing with a client device can be done either with single field at once
    or by bigger block of adjacent fields. If you try to read/write a list of QModbusDataUnits
    that are not adjacent to each other read/write will be unsuccessful.

    \code
        QList<QModbusDataUnit> units;
        units.append(QModbusDataUnit(QModbusDevice::HoldingRegisters, 3, 0x1af5));
        units.append(QModbusDataUnit(QModbusDevice::HoldingRegisters, 4, 0x1001));
        units.append(QModbusDataUnit(QModbusDevice::HoldingRegisters, 5, 0xff34));
        modbusClient->write(units);
    \endcode



 */
