Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QModbusRtuSerialMaster wrong CRC received

QModbusRtuSerialMaster wrong CRC received

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 976 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.
  • J Offline
    J Offline
    juanras
    wrote on last edited by
    #1

    Hello, I'm trying to deploy an QT application to communicate with a slave device on MODBUS RTU RS-485, on an embedded linux board.
    I have correctly set up my development environment with QT Creator 5.1 and their corresponding Compiler, debugger obtained from the Yocto SDK.

    When I try to run my application to read some registers or when i sendReadRequest I'm always getting a wrong CRC received.

    void modbusMaster::readRegisterData(quint16 startAddress, quint16 num, quint16 slaveAddress)
    {
    if(!m_master)
    return;

    qDebug()<<"Read Register Data";
    
    
    QModbusDataUnit readUnit(QModbusDataUnit::HoldingRegisters,startAddress,num);
    
    if(auto *reply = m_master->sendReadRequest(readUnit,slaveAddress))
    {
    
        qDebug() << reply->isFinished();
    
        if(!reply->isFinished())
        {
            connect(reply,&QModbusReply::finished,this,&modbusMaster::readyRead);
        }
        else
        {
            delete reply;
        }
    
    }
    else
    {
        qDebug()<<m_master->errorString();
    }
    

    }

    void modbusMaster::readyRead()
    {
    qDebug()<<"Ready Read Function";

    auto reply = qobject_cast<QModbusReply*>(sender());
    if(!reply)
        return;
    
    
    if(reply->error() == QModbusDevice::NoError)
    {
        //qDebug() << "Reply";
        const QModbusDataUnit unit = reply->result();
    
        for(uint i=0; i< unit.valueCount();i++)
        {
           const QString entry = tr("Address: %1, Value: %2").arg(unit.startAddress() + i)
                                         .arg(QString::number(unit.value(i),
                                              unit.registerType() <= QModbusDataUnit::Coils ? 10 : 16));
    
           qDebug()<<entry;
    
           //emit readData_signal(unit.startAddress()+i,unit.value(i));
    
        }
    
    }
    else if (reply->error() == QModbusDevice::ProtocolError) {
        qDebug()<<"error Protocol Error"<<reply->errorString();
    }
    else {
        qDebug()<<"error:"<<reply->errorString();
    }
    
    reply->deleteLater();
    

    }

    The response I get is:

    Init mosbusMaster Class
    Read Register Data
    false
    qt.modbus: (RTU client) Discarding response with wrong CRC, received: 0 , calculated CRC: 8432
    qt.modbus: (RTU client) Discarding response with wrong CRC, received: 2020 , calculated CRC: 9022
    qt.modbus: (RTU client) Discarding response with wrong CRC, received: 0 , calculated CRC: 8432
    qt.modbus: (RTU client) Discarding response with wrong CRC, received: 2020 , calculated CRC: 9022
    Ready Read Function
    error: "Request timeout."

    I have tried to debug my application in many ways but I cannot stil make it work.

    Does anyone have some related issues with the ModbusRtuSerialMasterClass?

    Thanks

    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