Good day, Qt users !
Im working with Qt Modbus Slave Example, and I have a question.

When we are creating a Map for modbus we use construction like :
Qt Code:
  1. reg.insert(QModbusDataUnit::InputRegisters, { QModbusDataUnit::InputRegisters, 0, 10 });
  2. // ^start address ^map size
To copy to clipboard, switch view to plain text mode 

The question is :
When I use just the code from example:
Qt Code:
  1. reg.insert(QModbusDataUnit::InputRegisters, { QModbusDataUnit::InputRegisters, 0, 10 });
To copy to clipboard, switch view to plain text mode 
10 Input registers are created from 0 address. No issues.
But when I want to start from different address lets say from 5, then I write :
Qt Code:
  1. reg.insert(QModbusDataUnit::InputRegisters, { QModbusDataUnit::InputRegisters, 5, 10 });
To copy to clipboard, switch view to plain text mode 
Then when I check and I can only read registrers 5-10, and 10-15 registers gives "Byte missing error" in my test program,

My qt server responds:
qt.modbus: (TCP server) Response PDU: 0x041400000000000000000000


Well, basically I can create 10 registers starting from 5 by using :
Qt Code:
  1. reg.insert(QModbusDataUnit::InputRegisters, { QModbusDataUnit::InputRegisters, 5, 15 });
To copy to clipboard, switch view to plain text mode 
But then then still 5 registers after 15 will respond me "Byte missing error";

So to conclude :
1. I create 10 registers from 0 to 10;
No issues, Map of 10 with 10 entries, map full;
2. I create 10 registers from 5 to 15
Map of 15 filled with 10 registers from 5 and 5 empty registers in the end.
If I will move the start position ( 5 ) the quantity of empty registers( returning "Byte missing error") will rise accordingly;

If you have any thoughts about it, I will appreciate it.


Part of code from Qt Modbus Slave Example:

Qt Code:
  1. void MainWindow::on_connectType_currentIndexChanged(int index)
  2. {
  3. if (modbusDevice) {
  4. modbusDevice->disconnect();
  5. delete modbusDevice;
  6. modbusDevice = nullptr;
  7. }
  8.  
  9. ModbusConnection type = static_cast<ModbusConnection> (index);
  10. if (type == Serial) {
  11. modbusDevice = new QModbusRtuSerialSlave(this);
  12. } else if (type == Tcp) {
  13. modbusDevice = new QModbusTcpServer(this);
  14. if (ui->portEdit->text().isEmpty())
  15. ui->portEdit->setText(QLatin1Literal("127.0.0.1:502"));
  16. }
  17. ui->listenOnlyBox->setEnabled(type == Serial);
  18.  
  19. if (!modbusDevice) {
  20. ui->connectButton->setDisabled(true);
  21. if (type == Serial)
  22. statusBar()->showMessage(tr("Could not create Modbus slave."), 5000);
  23. else
  24. statusBar()->showMessage(tr("Could not create Modbus server."), 5000);
  25. } else {
  26. QModbusDataUnitMap reg;
  27. reg.insert(QModbusDataUnit::Coils, { QModbusDataUnit::Coils, 0, 10 });
  28. reg.insert(QModbusDataUnit::DiscreteInputs, { QModbusDataUnit::DiscreteInputs, 0, 10 });
  29. reg.insert(QModbusDataUnit::InputRegisters, { QModbusDataUnit::InputRegisters, 0, 10 });
  30. reg.insert(QModbusDataUnit::HoldingRegisters, { QModbusDataUnit::HoldingRegisters, 0,10 });
  31.  
  32. modbusDevice->setMap(reg);
  33.  
  34. connect(modbusDevice, &QModbusServer::dataWritten,
  35. this, &MainWindow::updateWidgets);
  36. connect(modbusDevice, &QModbusServer::stateChanged,
  37. this, &MainWindow::onStateChanged);
  38. connect(modbusDevice, &QModbusServer::errorOccurred,
  39. this, &MainWindow::handleDeviceError);
  40.  
  41. connect(ui->listenOnlyBox, &QCheckBox::toggled, this, [this](bool toggled) {
  42. if (modbusDevice)
  43. modbusDevice->setValue(QModbusServer::ListenOnlyMode, toggled);
  44. });
  45. emit ui->listenOnlyBox->toggled(ui->listenOnlyBox->isChecked());
  46. connect(ui->setBusyBox, &QCheckBox::toggled, this, [this](bool toggled) {
  47. if (modbusDevice)
  48. modbusDevice->setValue(QModbusServer::DeviceBusy, toggled ? 0xffff : 0x0000);
  49. });
  50. emit ui->setBusyBox->toggled(ui->setBusyBox->isChecked());
  51.  
  52. setupDeviceData();
  53. }
  54. }
To copy to clipboard, switch view to plain text mode