Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Modbus RTU client: send failed error
Forum Updated to NodeBB v4.3 + New Features

Modbus RTU client: send failed error

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 323 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    Here the output of my program:

    State changed -> QModbusDevice::State(ConnectingState)
    State changed -> QModbusDevice::State(ConnectedState)
    
    (RTU client) Sent Serial PDU: 0x0303fe0001 ((null):0, (null))
    >> "Tx: 0x010303fe0001e5be"
     (RTU client) Sent Serial ADU: 0x010303fe0001e5be ((null):0, (null))
     (RTU client) Send failed: 0x0303fe0001 ((null):0, (null))
    Error "Request timeout." 
    << "Rx: 0x0103020000b844"
    (RTU client) Response buffer: "0103020000b844" ((null):0, (null))
    (RTU client) Received ADU: "0103020000b844" ((null):0, (null))
    (RTU client) Cannot match response with open request, ignoring ((null):0, (null))
    

    Here my code:

        QModbusClient *_modbus;
    
        bool ModbusMaster::open()
        {
            _modbus = new QModbusRtuSerialMaster(this);
    
            connect(_modbus, &QModbusClient::stateChanged, this, &ModbusMaster::state_changed);
            connect(_modbus, &QModbusClient::errorOccurred, this, &ModbusMaster::error_occurred);
            _modbus->setConnectionParameter(QModbusDevice::SerialPortNameParameter, _port);
    
            _retry = RTU_RETRY; // 0
            _timeout = RTU_TIMEOUT;  // 1000
    
            _modbus->setTimeout(_timeout);
            _modbus->setNumberOfRetries(_retry);
    
            return _modbus->connectDevice();
    }
    
        bool ModbusMaster::read(QModbusDataUnit::RegisterType type, int startAddress, quint16 count)
        {
            if (!_modbus) return false;
            if (_modbus->state() != QModbusDevice::ConnectedState) return false;
    
            QModbusDataUnit req(type, startAddress, count);    
            if (auto *reply = _modbus->sendReadRequest(req, _id))
            {
                if (!reply->isFinished()) connect(reply, &QModbusReply::finished, this, &ModbusMaster::readReady);
                else delete reply;
                return true;
            }
            return false;
        }
    
    
        void ModbusMaster::readReady()
        {
            auto reply = qobject_cast<QModbusReply *>(sender());
            if (!reply) return;
            reply->deleteLater();
    
            if (reply->error() == QModbusDevice::NoError)
            {
                const QModbusDataUnit unit = reply->result();
                // do something
            }
            else if (reply->error() == QModbusDevice::ProtocolError)
            {
                QStringList msg = QStringList() << "Error protocol" << reply->errorString() << QString::number(reply->rawResult().exceptionCode()) << QString::number(reply->result().startAddress());
                emit errorOccurred(msg.join(", "));
            }
            else emit errorOccurred(reply->errorString());
        }
    

    What does may cause a failure during send?
    Of course the tty port is available and I can write to it.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved