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:
2023-08-25 09:45:40 +02:00
parent 92abe46152
commit be03bbe6f3

View File

@@ -38,9 +38,7 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
self.outputs = outputs.copy() self.outputs = outputs.copy()
self.write_values = False self.write_values = False
min_input = min(inputs, key=lambda k: k[2]) self.length = self._calc_device_length(self.inputs, self.outputs)
max_output = max(outputs, key=lambda k: k[2])
self.length = max_output[2] + max_output[1] - min_input[2]
self.style_sheet = "" self.style_sheet = ""
self._create_io(self.inputs, self.saw_inp, True) 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, \ return max_int_value / 2 * -1 if signed else 0.0, \
max_int_value / 2 - 1 if signed else max_int_value - 1 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): def _create_io(self, lst_ios: list, container: QtWidgets.QWidget, read_only: bool):
lst_names = list(lst[0] for lst in lst_ios) lst_names = list(lst[0] for lst in lst_ios)
layout = container.layout() # type: QtWidgets.QFormLayout layout = container.layout() # type: QtWidgets.QFormLayout
@@ -293,10 +308,7 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
"""Update IOs after driver reset of piCtory.""" """Update IOs after driver reset of piCtory."""
# Check device length, this has to match to reuse this device # Check device length, this has to match to reuse this device
min_input = min(inputs, key=lambda k: k[2]) if self.length != self._calc_device_length(inputs, outputs):
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:
return False return False
# Remove IOs, which was remove or renamed # Remove IOs, which was remove or renamed