[Interest] QModbusTcpClient - More than one Modbus ID query in TCP Package

Alexander Blasche alexander.blasche at qt.io
Wed Dec 21 10:02:12 CET 2016


I have a couple of questions to understand your use case better.

> -----Original Message-----
> From: Interest [mailto:interest-bounces+alexander.blasche=qt.io at qt-
> project.org] On Behalf Of Pfeiffer, Stephan

....
> void BModbus::requestRequiredSlot(BModbusData *data)
> 
> {
> 
>     QModbusDataUnit du(QModbusDataUnit::HoldingRegisters, data->address(),
> data->datatype().second);
> 
>     QModbusReply *reply = c->sendReadRequest(du,255);
> 
>     connect(reply,&QModbusReply::finished,this,&BModbus::readyReadSlot);
> 
> }
> 
> Everything is working fine if I poll one Modbus address.
> The Wireshark Protocol says that only one query is placed in one TCP-package.
>
> If I query more than one modbus address, then there are all modbus queries in
> one TCP-package (also logged with Wireshark). And my device only sends an
> answer to the last ID in the package.

I take it that you repeat the sendReadRequest() call above multiple times in quick succession (almost like in a loop)?

When you talk about ID, are you talking about the server address (255 above) or are you talking about different holding register addresses (data->address() above) on the same server address?

> Can anyone help me so that the QModbusTcpClient packs every Modbus ID into
> a seperate TCP-package instead of all in one?

Once I have an answer I might be able to help. There is two more hints which I can give you which might help to debug the problem:

1.) You can enable more detailed logging output by adding

QLoggingCategory::setFilterRules(QStringLiteral("qt.modbus* = true"));

As first line to your main() function. 

2.) The relevant code for your use case is in qmodbustcpclient_p.h. enqueueRequest() is the function that ultimately creates the ADU/PDU. There you can see the relevant logging output.

--
Alex



More information about the Interest mailing list