mirror of
https://github.com/naruxde/revpicommander.git
synced 2025-11-08 16:43:53 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user