mirror of
https://github.com/naruxde/revpicommander.git
synced 2025-11-08 16:43:53 +01:00
fix: PLC monitor crashes when a device has no inputs or outputs
The calculation of the length for a device is now carried out depending on the list content of the inputs and outputs. A length of 0 is now also possible. Signed-off-by: Sven Sager <akira@narux.de>
This commit is contained in:
@@ -38,9 +38,7 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
|
||||
self.outputs = outputs.copy()
|
||||
self.write_values = False
|
||||
|
||||
min_input = min(inputs, key=lambda k: k[2])
|
||||
max_output = max(outputs, key=lambda k: k[2])
|
||||
self.length = max_output[2] + max_output[1] - min_input[2]
|
||||
self.length = self._calc_device_length(self.inputs, self.outputs)
|
||||
|
||||
self.style_sheet = ""
|
||||
self._create_io(self.inputs, self.saw_inp, True)
|
||||
@@ -62,6 +60,23 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
|
||||
return max_int_value / 2 * -1 if signed else 0.0, \
|
||||
max_int_value / 2 - 1 if signed else max_int_value - 1
|
||||
|
||||
@staticmethod
|
||||
def _calc_device_length(inputs: list, outputs: list) -> int:
|
||||
"""Calculate the device length with IO data."""
|
||||
if inputs and outputs:
|
||||
min_input = min(inputs, key=lambda k: k[2])
|
||||
max_output = max(outputs, key=lambda k: k[2])
|
||||
elif inputs:
|
||||
min_input = min(inputs, key=lambda k: k[2])
|
||||
max_output = max(inputs, key=lambda k: k[2])
|
||||
elif outputs:
|
||||
min_input = min(outputs, key=lambda k: k[2])
|
||||
max_output = max(outputs, key=lambda k: k[2])
|
||||
else:
|
||||
return 0
|
||||
|
||||
return max_output[2] + max_output[1] - min_input[2]
|
||||
|
||||
def _create_io(self, lst_ios: list, container: QtWidgets.QWidget, read_only: bool):
|
||||
lst_names = list(lst[0] for lst in lst_ios)
|
||||
layout = container.layout() # type: QtWidgets.QFormLayout
|
||||
@@ -293,10 +308,7 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
|
||||
"""Update IOs after driver reset of piCtory."""
|
||||
|
||||
# Check device length, this has to match to reuse this device
|
||||
min_input = min(inputs, key=lambda k: k[2])
|
||||
max_output = max(outputs, key=lambda k: k[2])
|
||||
new_length = max_output[2] + max_output[1] - min_input[2]
|
||||
if self.length != new_length:
|
||||
if self.length != self._calc_device_length(inputs, outputs):
|
||||
return False
|
||||
|
||||
# Remove IOs, which was remove or renamed
|
||||
|
||||
Reference in New Issue
Block a user