Fix error in debugios.py with long byte values

Long byte values > 4 Bytes are handled as TEXT values. In some cases this could crash the sps monitor. Now, if we are not able to convert the bytes to a str(), we'll switch that io to "number" format.
This commit is contained in:
2021-06-14 19:51:14 +02:00
parent c1e082107d
commit 0831e8253a
2 changed files with 11 additions and 3 deletions

View File

@@ -186,7 +186,7 @@ class DebugControl(QtWidgets.QWidget, Ui_wid_debugcontrol):
win = self.dict_windows[position]
for io in self.dict_ios[io_type][position]: # type: list
# ['name', bitlength, byte_address, 'bmk', bitaddress, 'byteorder', signed]
# ['name', bytelen, byte_address, 'bmk', bitaddress, 'byteorder', signed]
value_procimg = bytes(ba_values[io[2]:io[2] + io[1]])
if io[4] >= 0:
# Bit-IO

View File

@@ -344,14 +344,22 @@ class DebugIos(QtWidgets.QMainWindow, Ui_win_debugios):
if child.property("frm"):
value = struct.unpack(child.property("frm"), value)[0]
elif type(value) == bytes:
if child.property("struct_type") == "text":
try:
value = value.decode("utf-8")
except UnicodeDecodeError:
child.setProperty("struct_type", "number")
QtWidgets.QMessageBox.warning(
self, self.tr("Can not use format text"), self.tr(
"Can not convert bytes {0} to a text for IO '{1}'. Switch to number format instead!"
).format(value, io_name)
)
if child.property("struct_type") == "number":
value = str(int.from_bytes(
value,
byteorder="big" if child.property("big_endian") else "little",
signed=child.property("signed") or False
))
else:
value = value.decode()
child.setProperty("last_value", value)
if not just_last_value: