QModbusRtuSerialMaster wrong CRC received
-
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