From 4f85e5b1f2642ac2846d14b5f1903834e8c9ccab Mon Sep 17 00:00:00 2001 From: SelfConfusion <1822250894@qq.com> Date: Fri, 12 Jul 2024 21:48:12 +0800 Subject: [PATCH] fix wrong data bug --- src/main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.py b/src/main.py index 938ee8b..e2a539f 100644 --- a/src/main.py +++ b/src/main.py @@ -48,11 +48,11 @@ class App(ctk.CTk): # find the center point if self.system_platform == "Linux": - center_x = int(screen_width / 2 - width / 2) - center_y = int(screen_height / 2 - height / 2) + center_x = int(screen_width / 2 - width / 2) + center_y = int(screen_height / 2 - height / 2) elif self.system_platform == "Windows": - center_x = int(screen_width / 2 - width / 4) - center_y = int(screen_height / 2 - height / 4) + center_x = int(screen_width / 2 - width / 4) + center_y = int(screen_height / 2 - height / 4) # set the position of the self to the center of the screen self.geometry(f"{width}x{height}+{center_x}+{center_y}") @@ -345,15 +345,15 @@ class App(ctk.CTk): case _: return "error" - def toAscii(num: float) -> str: - return chr(int(num)) - if self.serial_status: for i in range(5): if self.gain_enable[i]: - bytes = f"{switchSign(i)}{toAscii(self.gain_values[i])}{toAscii(self.gain_values[i] % 1 * 256)}\0" - print(f"Send:{bytes}") - self.serial.write(bytes.encode()) + bytes = list(map(lambda x: ord(x), list(switchSign(i)))) + bytes.append(int(self.gain_values[i])) + bytes.append(int(self.gain_values[i] % 1 * 256)) + bytes.append(0) + print(f"Send:{bytes} \t Hex:0x" + f"{hex(int( self.gain_values[i] * 256 )).replace('0x', '')}".zfill(4)) + self.serial.write(bytes) else: print("Please Connect to Serial") messagebox.showError("Please Connect Serial Port")