@@ -803,7 +803,19 @@ inline QXmlStreamReader& operator >>(QXmlStreamReader& xml, FormModSim* frm)
803803 QHashIterator it (simulations);
804804 while (it.hasNext ()) {
805805 const auto item = it.next ();
806- frm->startSimulation (dd.PointType , item.key () - (dd.ZeroBasedAddress ? 0 : 1 ), item.value ());
806+ switch (dd.PointType ) {
807+ case QModbusDataUnit::Coils:
808+ case QModbusDataUnit::DiscreteInputs:
809+ if (item->Mode == SimulationMode::Toggle || item->Mode == SimulationMode::Random)
810+ frm->startSimulation (dd.PointType , item.key () - (dd.ZeroBasedAddress ? 0 : 1 ), item.value ());
811+ break ;
812+ case QModbusDataUnit::InputRegisters:
813+ case QModbusDataUnit::HoldingRegisters:
814+ if (item->Mode != SimulationMode::No && item->Mode != SimulationMode::Toggle)
815+ frm->startSimulation (dd.PointType , item.key () - (dd.ZeroBasedAddress ? 0 : 1 ), item.value ());
816+ break ;
817+ default : break ;
818+ }
807819 }
808820 }
809821
@@ -822,7 +834,18 @@ inline QXmlStreamReader& operator >>(QXmlStreamReader& xml, FormModSim* frm)
822834 while (it.hasNext ()) {
823835 const auto item = it.next ();
824836 const auto index = item.key () - dd.PointAddress ;
825- values[index] = item.value ();
837+ switch (dd.PointType ) {
838+ case QModbusDataUnit::Coils:
839+ case QModbusDataUnit::DiscreteInputs:
840+ values[index] = qBound<quint16>(0 , item.value (), 1 );
841+ break ;
842+ case QModbusDataUnit::InputRegisters:
843+ case QModbusDataUnit::HoldingRegisters:
844+ values[index] = item.value ();
845+ break ;
846+ default : break ;
847+ }
848+ if (index >= values.length ()) break ;
826849 }
827850
828851 frm->configureModbusDataUnit (dd.DeviceId , dd.PointType , dd.PointAddress - (dd.ZeroBasedAddress ? 0 : 1 ), values);
0 commit comments