GDT + HMI Integration: Real-Time Weight Display with Modbus Communication

Amazeng Technical Team
5 min read
GDTHMIModbusLoadcellQtIndustrial WeighingQML

A GDT digital transmitter and a touchscreen HMI panel communicating over Modbus RTU (RS485) or Modbus TCP (Ethernet) can replace a dedicated weight indicator: the panel reads net/gross weight from the GDT's registers and sends tare and zero commands over Modbus as well. Beyond a numeric display, this setup adds graphs, alarms, data logging and cloud connectivity. Below we walk through every step of the integration with the GDT Digital Transmitter, from the register map to the Qt/QML interface, error handling and polling rate, on HMI Industrial Display Solutions.

Why GDT + HMI?

Traditional Solution: Dedicated Indicator

Loadcell → GDT → 4-20mA → Weight Indicator (LED Display)

Limitations:

  • Numeric display only
  • No graphs
  • Physical tare button
  • No remote access
  • No logging

Modern Solution: GDT + HMI

Loadcell → GDT → Modbus TCP/RTU → HMI (7"/10.1" Touchscreen)

Advantages: ✅ Graphical trend display
✅ Touchscreen tare/zero
✅ Multi-tank view
✅ Alarm threshold settings
✅ Data logging to SD card
✅ Cloud integration via MQTT

Modbus Communication Architecture

Option 1: Modbus TCP (Ethernet)

┌─────────────┐         ┌─────────────┐
│   GDT-TCP   │  TCP/IP │ HMI Panel   │
│ 192.168.1.10├────────►│ 192.168.1.20│
│   Port 502  │  LAN    │   Qt/QML    │
└─────────────┘         └─────────────┘

Advantages:

  • High bandwidth and short response times
  • Copper cable segments up to 100 m between switches (CAT5e)
  • Several HMIs on the network can read the same GDT

Option 2: Modbus RTU (RS485)

┌─────────────┐         ┌─────────────┐
│   GDT-RTU   │  RS485  │ HMI Panel   │
│  Slave ID:1 ├────────►│   Master    │
│   (A, B)    │ 2-wire  │  (A, B, G)  │
└─────────────┘         └─────────────┘

Advantages:

  • Long line distance (up to 1200 m at low baud rates)
  • Noise-resistant (differential signaling)
  • Daisy-chain: multiple GDTs on one RS485 line

Wiring:

GDT         HMI
A    ────   A (RS485+)
B    ────   B (RS485-)
GND  ────   G (Ground - optional)

Termination Resistor:
Add a 120Ω resistor at the line ends (prevents reflections).

GDT Modbus Register Map

The register map used with the GDT Digital Transmitter in this example:

Holding Registers (Function Code 03 - Read)

RegisterDataTypeUnitDescription
0-1Channel 1 RawFloatmV/VChannel 1 raw value
2-3Channel 2 RawFloatmV/VChannel 2 raw value
4-5Channel 3 RawFloatmV/VChannel 3 raw value
6-7Channel 4 RawFloatmV/VChannel 4 raw value
8-9Net WeightFloatkgNet weight (gross - tare)
10-11Gross WeightFloatkgGross weight
12-13Tare ValueFloatkgActive tare value
14StatusUint16-Status flags
15AlarmUint16-Alarm flags

Float Format: IEEE 754 (Big-endian, 2 register)

The register addresses in this article are the map used in the example application. For the exact addresses, data types and word order of your device's firmware version, rely on the GDT's Modbus RTU/TCP command reference (communication protocol document).

How is a 32-bit float read from two registers?

When the net weight is 25.0 kg, its IEEE 754 representation is 0x41C80000, split across two registers like this:

RegisterValue (hex)Description
80x41C8High word (comes first in big-endian)
90x0000Low word

Combining the two words as reg8 << 16 | reg9 and interpreting the result as a float gives 25.0. If the words are combined in reverse order (0x000041C8), the result is a meaningless number of about 2.4 × 10⁻⁴¹; if the display constantly shows 0.00, this is the first thing to check. Also, in HMI software that uses "4xxxx" notation, zero-based register 8 is entered as 40009. For details of the frame structure, see our Modbus protocol integration article.

Coils (Function Code 05 - Write Single Coil)

CoilFunction
0Tare (zero the net weight)
1Zero (zero the gross weight)
2Calibration Mode ON
3Calibration Mode OFF

HMI Application (Qt/QML)

Modbus Client Backend (C++)

modbusClient.h

#ifndef MODBUSCLIENT_H
#define MODBUSCLIENT_H

#include <QObject>
#include <QTimer>
#include <QModbusClient>
#include <QModbusTcpClient>
#include <QModbusRtuSerialMaster>

class ModbusClient : public QObject
{
    Q_OBJECT
    Q_PROPERTY(float netWeight READ netWeight NOTIFY netWeightChanged)
    Q_PROPERTY(float grossWeight READ grossWeight NOTIFY grossWeightChanged)
    Q_PROPERTY(float tareValue READ tareValue NOTIFY tareValueChanged)
    Q_PROPERTY(bool connected READ isConnected NOTIFY connectionChanged)

public:
    explicit ModbusClient(QObject *parent = nullptr);

    // Getters
    float netWeight() const { return m_netWeight; }
    float grossWeight() const { return m_grossWeight; }
    float tareValue() const { return m_tareValue; }
    bool isConnected() const { return m_connected; }

    // Q_INVOKABLE methods (callable from QML)
    Q_INVOKABLE void connectTcp(const QString &host, int port);
    Q_INVOKABLE void connectRtu(const QString &port, int baudrate);
    Q_INVOKABLE void disconnect();
    Q_INVOKABLE void sendTare();
    Q_INVOKABLE void sendZero();

signals:
    void netWeightChanged();
    void grossWeightChanged();
    void tareValueChanged();
    void connectionChanged();
    void errorOccurred(const QString &error);

private slots:
    void readRegisters();
    void onStateChanged(QModbusDevice::State state);
    void onReadReady();

private:
    QModbusClient *m_modbusDevice = nullptr;
    QTimer *m_pollTimer = nullptr;

    float m_netWeight = 0.0f;
    float m_grossWeight = 0.0f;
    float m_tareValue = 0.0f;
    bool m_connected = false;

    int m_serverAddress = 1; // Modbus slave ID

    float registersToFloat(quint16 reg1, quint16 reg2);
};

#endif

modbusClient.cpp (Main Functions)

#include "modbusClient.h"
#include <QModbusDataUnit>

ModbusClient::ModbusClient(QObject *parent) : QObject(parent)
{
    m_pollTimer = new QTimer(this);
    connect(m_pollTimer, &QTimer::timeout, this, &ModbusClient::readRegisters);
}

void ModbusClient::connectTcp(const QString &host, int port)
{
    if (m_modbusDevice) {
        m_modbusDevice->disconnectDevice();
        delete m_modbusDevice;
    }

    m_modbusDevice = new QModbusTcpClient(this);
    m_modbusDevice->setConnectionParameter(
        QModbusDevice::NetworkAddressParameter, host);
    m_modbusDevice->setConnectionParameter(
        QModbusDevice::NetworkPortParameter, port);

    connect(m_modbusDevice, &QModbusDevice::stateChanged,
            this, &ModbusClient::onStateChanged);

    if (!m_modbusDevice->connectDevice()) {
        emit errorOccurred(m_modbusDevice->errorString());
    }
}

void ModbusClient::onStateChanged(QModbusDevice::State state)
{
    m_connected = (state == QModbusDevice::ConnectedState);
    emit connectionChanged();

    if (m_connected) {
        m_pollTimer->start(100); // Read every 100 ms
    } else {
        m_pollTimer->stop();
    }
}

void ModbusClient::readRegisters()
{
    if (!m_modbusDevice || !m_connected) return;

    // Read registers 8-13 (Net, Gross, Tare)
    auto *reply = m_modbusDevice->sendReadRequest(
        QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 8, 6),
        m_serverAddress);

    if (reply) {
        if (!reply->isFinished()) {
            connect(reply, &QModbusReply::finished, this, &ModbusClient::onReadReady);
        } else {
            delete reply;
        }
    }
}

void ModbusClient::onReadReady()
{
    auto *reply = qobject_cast<QModbusReply *>(sender());
    if (!reply) return;

    if (reply->error() == QModbusDevice::NoError) {
        const QModbusDataUnit unit = reply->result();

        // Net Weight (reg 8-9)
        m_netWeight = registersToFloat(unit.value(0), unit.value(1));
        emit netWeightChanged();

        // Gross Weight (reg 10-11)
        m_grossWeight = registersToFloat(unit.value(2), unit.value(3));
        emit grossWeightChanged();

        // Tare Value (reg 12-13)
        m_tareValue = registersToFloat(unit.value(4), unit.value(5));
        emit tareValueChanged();
    }

    reply->deleteLater();
}

float ModbusClient::registersToFloat(quint16 reg1, quint16 reg2)
{
    // IEEE 754 float conversion (big-endian)
    quint32 value = (static_cast<quint32>(reg1) << 16) | reg2;
    float result;
    memcpy(&result, &value, sizeof(float));
    return result;
}

void ModbusClient::sendTare()
{
    if (!m_modbusDevice || !m_connected) return;

    // Coil 0 = Tare command
    m_modbusDevice->sendWriteRequest(
        QModbusDataUnit(QModbusDataUnit::Coils, 0, 1),
        m_serverAddress);
}

void ModbusClient::sendZero()
{
    if (!m_modbusDevice || !m_connected) return;

    // Coil 1 = Zero command
    m_modbusDevice->sendWriteRequest(
        QModbusDataUnit(QModbusDataUnit::Coils, 1, 1),
        m_serverAddress);
}

QML User Interface

main.qml

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

ApplicationWindow {
    visible: true
    width: 1024
    height: 600
    title: "GDT Loadcell Monitor"

    // Background
    Rectangle {
        anchors.fill: parent
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#34495E" }
            GradientStop { position: 1.0; color: "#2C3E50" }
        }
    }

    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 20
        spacing: 20

        // Title and connection status
        RowLayout {
            Layout.fillWidth: true

            Text {
                text: "GDT Weighing System"
                font.pixelSize: 36
                font.bold: true
                color: "#ECF0F1"
            }

            Item { Layout.fillWidth: true }

            Rectangle {
                width: 20
                height: 20
                radius: 10
                color: modbusClient.connected ? "#2ECC71" : "#E74C3C"
            }

            Text {
                text: modbusClient.connected ? "Connected" : "No Connection"
                font.pixelSize: 18
                color: "#ECF0F1"
            }
        }

        // Main weight display
        Rectangle {
            Layout.fillWidth: true
            Layout.preferredHeight: 250
            color: "#1ABC9C"
            radius: 15

            ColumnLayout {
                anchors.centerIn: parent
                spacing: 10

                Text {
                    text: "NET WEIGHT"
                    font.pixelSize: 24
                    color: "white"
                    Layout.alignment: Qt.AlignHCenter
                }

                Text {
                    text: modbusClient.netWeight.toFixed(2)
                    font.pixelSize: 96
                    font.bold: true
                    color: "white"
                    Layout.alignment: Qt.AlignHCenter
                }

                Text {
                    text: "kg"
                    font.pixelSize: 36
                    color: "white"
                    Layout.alignment: Qt.AlignHCenter
                }
            }
        }

        // Gross and Tare displays
        RowLayout {
            Layout.fillWidth: true
            spacing: 20

            // Gross Weight
            Rectangle {
                Layout.fillWidth: true
                Layout.preferredHeight: 120
                color: "#3498DB"
                radius: 10

                ColumnLayout {
                    anchors.centerIn: parent

                    Text {
                        text: "Gross"
                        font.pixelSize: 18
                        color: "white"
                        Layout.alignment: Qt.AlignHCenter
                    }

                    Text {
                        text: modbusClient.grossWeight.toFixed(2) + " kg"
                        font.pixelSize: 32
                        font.bold: true
                        color: "white"
                        Layout.alignment: Qt.AlignHCenter
                    }
                }
            }

            // Tare Value
            Rectangle {
                Layout.fillWidth: true
                Layout.preferredHeight: 120
                color: "#E67E22"
                radius: 10

                ColumnLayout {
                    anchors.centerIn: parent

                    Text {
                        text: "Tare"
                        font.pixelSize: 18
                        color: "white"
                        Layout.alignment: Qt.AlignHCenter
                    }

                    Text {
                        text: modbusClient.tareValue.toFixed(2) + " kg"
                        font.pixelSize: 32
                        font.bold: true
                        color: "white"
                        Layout.alignment: Qt.AlignHCenter
                    }
                }
            }
        }

        // Control buttons
        RowLayout {
            Layout.fillWidth: true
            Layout.alignment: Qt.AlignHCenter
            spacing: 20

            Button {
                text: "TARE"
                font.pixelSize: 24
                implicitWidth: 200
                implicitHeight: 80

                background: Rectangle {
                    color: parent.pressed ? "#16A085" : "#1ABC9C"
                    radius: 10
                }

                contentItem: Text {
                    text: parent.text
                    font: parent.font
                    color: "white"
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }

                onClicked: modbusClient.sendTare()
            }

            Button {
                text: "ZERO"
                font.pixelSize: 24
                implicitWidth: 200
                implicitHeight: 80

                background: Rectangle {
                    color: parent.pressed ? "#C0392B" : "#E74C3C"
                    radius: 10
                }

                contentItem: Text {
                    text: parent.text
                    font: parent.font
                    color: "white"
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }

                onClicked: modbusClient.sendZero()
            }
        }
    }

    Component.onCompleted: {
        // Modbus TCP connection to the GDT
        modbusClient.connectTcp("192.168.1.10", 502)
    }
}

Real-World Application: Packaging Line

Scenario

In a food plant, products are packed into 25 kg bags. Each filling station has:

HMI Functions

  1. Target weight entry: The operator enters 25 kg on the touchscreen
  2. Fill monitoring: The weight increase is shown live
  3. Automatic stop: The valve closes at 24.5 kg
  4. Tare: Automatic tare for every new bag
  5. Counter: Total package count (written to SD card)

QML - Packaging Mode

Rectangle {
    property real targetWeight: 25.0
    property int packageCount: 0

    ColumnLayout {
        // Target weight indicator
        ProgressBar {
            from: 0
            to: targetWeight
            value: modbusClient.netWeight

            background: Rectangle {
                color: "#BDC3C7"
                radius: 5
            }

            contentItem: Item {
                Rectangle {
                    width: parent.width * (parent.value / parent.to)
                    height: parent.height
                    color: parent.value >= targetWeight ? "#2ECC71" : "#3498DB"
                    radius: 5
                }
            }
        }

        Text {
            text: modbusClient.netWeight.toFixed(2) + " / " + targetWeight + " kg"
            font.pixelSize: 48
        }

        // Package counter
        Text {
            text: "Total Packages: " + packageCount
            font.pixelSize: 32
        }

        Button {
            text: "NEW PACKAGE (TARE)"
            onClicked: {
                modbusClient.sendTare()
                packageCount++
            }
        }
    }

    // Automatic stop logic
    Connections {
        target: modbusClient
        function onNetWeightChanged() {
            if (modbusClient.netWeight >= targetWeight * 0.98) {
                // Valve close signal (Modbus coil write)
                // ...
            }
        }
    }
}

Error Handling and Diagnostics

Modbus Timeout

void ModbusClient::onReadReady()
{
    auto *reply = qobject_cast<QModbusReply *>(sender());

    if (reply->error() == QModbusDevice::TimeoutError) {
        emit errorOccurred("GDT not responding! Check the cable connection.");

        // Visual warning on the HMI
        m_connected = false;
        emit connectionChanged();
    }
}

CRC Errors (Modbus RTU)

Electrical noise on the RS485 line can cause CRC errors:

  • Improve cable quality (shielded CAT5)
  • Add termination resistors
  • Lower the baud rate (19200 → 9600)

Performance Optimization

Choosing the Polling Rate

// Fast: 100ms (10 Hz) - Dynamic weighing
m_pollTimer->start(100);

// Medium: 500ms (2 Hz) - Normal weighing
m_pollTimer->start(500);

// Slow: 1000ms (1 Hz) - Tank monitoring
m_pollTimer->start(1000);

Rule: Slow polling is enough for static weighing (tanks); dynamic weighing (conveyors) needs fast polling.

How is the data moved to the cloud?

The HMI panel can also act as a gateway: it displays the weight read from the GDT over Modbus locally, stores it in a database (SQLite/PostgreSQL) and publishes it to a cloud platform (e.g. AWS IoT Core) over MQTT. See our Cloud & IoT Data Collection solution for details.

GDT (Modbus) → HMI (Gateway) → MQTT → AWS IoT Core

Summary: what does GDT + HMI integration deliver?

Integrating the GDT Digital Transmitter with an HMI Panel gives weighing systems:

✅ Flexibility: Customize the UI as you like
✅ Functionality: Graphs, alarms, logging
✅ Scalability: One panel can display several GDTs and weighing points
✅ Extensibility: Ready for cloud integration

For a similar solution, contact us.