Unsolved Problem about QModbusClient: read file record(0x14)
-
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:
The message box only show '0', the
str
is empty.Why?Can anybody help me, thanks!
-
I have the same issue with Modbus RTU. Does anybody knows the solvation of this problem?