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. Problem about QModbusClient: read file record(0x14)

Problem about QModbusClient: read file record(0x14)

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 364 Views
  • 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.
  • E Offline
    E Offline
    Ehehe
    wrote on last edited by
    #1

    I want to write a host software to read file by modbus protocol, used the read file record function code(0x14), encode the QModbusRequest and use QModbusClient::readRawRequest(), the reply has no error, but has no data .

    The send code

    char data0[] = {0x0e, 0x06, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x06, 0x00, 0x03, 0x00, 0x09, 0x00, 0x02};
    QByteArray data(data0, 15);
    QModbusRequest req1(QModbusRequest::ReadFileRecord, data);
    rep = mb_client->sendRawRequest(req1, 1);
    if (rep->isFinished()) {
        delete rep;
    }
    else {
        connect(rep, &QModbusReply::finished, this, &MyClass::on_rep_finish);
    }
    

    And the receive code

    void MyClass::on_rep_finish()
    {
        QModbusReply *reply = qobject_cast(sender());
        if (!reply) {
            return;
        }
        if (reply->error() == QModbusDevice::NoError) {
            const QModbusDataUnit unit = reply->result();
            QString str;
            auto values = unit.values();
            for (uint i = 0; i < unit.valueCount(); i++) {
                str += QString::number(unit.value(i)) + " ";
            }
            QMessageBox::about(this, "recv", str + QString::number(unit.valueCount()));
        }
        else {
            QMessageBox::about(this, "recv", reply->errorString());
        }
        delete reply;
    }
    

    I use the tcp/ip tool to creat a tcp server, receive this frame (hex):
    00 00 00 00 00 11 01 14 0E 06 00 04 00 01 00 02 06 00 03 00 09 00 02
    and response this frame (hex):
    00 00 00 00 00 0F 01 14 0C 05 06 0D FE 00 20 05 06 33 CD 00 40

    The frame as same as show in *MODBUS APPLICATION PROTOCOL SPECIFICATION V1.1b3* chapter 6.14, in order to avoid message error.
    

    However the program show this message box:
    recv.png

    The message box only show '0', the str is empty.

    Why?Can anybody help me, thanks!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AlexSveshn68
      wrote on last edited by
      #2

      I have the same issue with Modbus RTU. Does anybody knows the solvation of this problem?

      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