0

The story behind: Using a QModbusTcpClient I am trying to read the content from a device connected to a Modbus/TCP network. For that purpose I have written a Windows program (tested on 7 and 10) in Qt C++ (Qt version 5.7.0) which essentially calls QModbusClient::sendReadRequest with QModbusDataUnit::QModbusDataUnit(RegisterType type, int address, quint16 size) as a parameter, where type is HoldingRegisters, address equals to 1000 (could be another address, it is not important for this particular issue) and size is the length of the desired data to be read from the device.

The issue: Everything works well when size is less or equal to 63 registers. Every attempt to go beyond this value results in an error, which depends on the device I am testing the program with, but generally says invalid request.

Tests:

  1. I have tested this with several real devices and with a Modbus/TCP simulator obtaining the same results, i.e. size <= 63 -> okay; size > 63 -> error
  2. Modpoll from another side allows me to read a data chunk from the same devices and simulator with a size greater than 63 registers

Some research: Here it is stated, that there is indeed a limitation, but it is 256 bytes, which equals to 128 16-bit registers, in other words - way above the limit of my read attempts.

My suspicion: It appears that QModbusTcpClient does not allow reading more than a 63 registers.

Question: Have anyone experienced such an issue using QModbusTcpClient and is there a way to overcome this limitation, apart from reading the data on two passes?

esote
  • 831
  • 12
  • 25
scopchanov
  • 7,966
  • 10
  • 40
  • 68

1 Answers1

0

Well, the solution, which worked in my case is to take the matter in my hands and write my own class to communicate with the Modbus devices. The class inherits from QObject, so the signal-slot system is still at disposal, however the actual functionality is based around the winsock2.h. Here is a sample program, which does the job for what I need. Another useful sources I have stumbled upon are this book, the example program from the winsocket 2 reference and of course the Modbus specification. It turned out, that it is not so difficult and with a little bit of help from the sources I've mentioned I was able to solve the problem I've had.

scopchanov
  • 7,966
  • 10
  • 40
  • 68