@@ -448,6 +448,34 @@ ModbusSimulationMap FormModSim::simulationMap() const
448448 return result;
449449}
450450
451+
452+ QModbusDataUnit FormModSim::serializeModbusDataUnit (QModbusDataUnit::RegisterType type,
453+ quint16 startAddress,
454+ quint16 length) const
455+ {
456+ QModbusDataUnit dataUnit;
457+
458+ const auto serverData = _mbMultiServer.data (type, startAddress, length);
459+
460+ const auto & unit = serverData;
461+
462+ if (startAddress >= unit.startAddress () &&
463+ (startAddress + length) <= (unit.startAddress () + unit.valueCount ())) {
464+
465+ int offset = startAddress - unit.startAddress ();
466+
467+ QVector<quint16> values;
468+ for (int i = 0 ; i < length; ++i) {
469+ values.append (unit.value (offset + i));
470+ }
471+
472+ dataUnit.setValues (values);
473+ dataUnit.setRegisterType (type);
474+ dataUnit.setStartAddress (startAddress);
475+ }
476+
477+ return dataUnit;
478+ }
451479// /
452480// / \brief FormModSim::startSimulation
453481// / \param type
@@ -459,6 +487,18 @@ void FormModSim::startSimulation(QModbusDataUnit::RegisterType type, quint16 add
459487 _dataSimulator->startSimulation (dataDisplayMode (), type, addr, params);
460488}
461489
490+ void FormModSim::configureModbusDataUnit (QModbusDataUnit::RegisterType type,
491+ quint16 startAddress,
492+ const QVector<quint16>& values) const
493+ {
494+ QModbusDataUnit unit;
495+ unit.setRegisterType (type);
496+ unit.setStartAddress (startAddress);
497+ unit.setValues (values);
498+ _mbMultiServer.setData (unit);
499+ }
500+
501+
462502// /
463503// / \brief FormModSim::descriptionMap
464504// / \return
0 commit comments