Important: Please read the Qt Code of Conduct -

Communication driver multi protocol API

  • Hello,

    I have to develop some drivers to communicate with industrial machines. These machines use different protocol (ModBus, OpenProtocol, ...) and different interface (Ethernet, RS232, RS422, USB, ...).
    I want to have a common API for my drivers to communicate with these machines.
    I want that because I will have to add a new communication driver to my system to manage a new machine.

    Do you know some examples of open source project or have some codes that can inspire me to solve my problem. Or if you think that my idea is absolutely stupid, please, explain me why and guide me on the good way.


  • @Francis-Chapet That's not stupid. That's a common thing. What you need is a common interface from which you inherit in the classes where you implement your communication protocols. Like QAbstract... classes in Qt framework. You can take inspiration of QIODevice which is typically the base of all communication in Qt (QSerialPort, QAbstractSocket, QBuffer, QFileDevice, QLocalSocket, QNetworkReply, QProcess and probably more.. )

    But that's basically always the same thing:

    • open
    • close
    • read
    • write
    • events (ready read, connection state changed,...)
    • setconfig

    For the content of your data, you can use raw data like string or byte array, or a use the same principle of the base interface (abstract class) with specific implementation for each protocol. But as everything is always represented by bits at the end, byte arrays are usually enough to cover all the needs, you can always provide methods in your protocol's classes to convert the data to another format and vice versa.

  • @Gojir4 Thank you

  • Lifetime Qt Champion


    You might want to check the QtSerialBus module.

Log in to reply