fix wrong data bug

This commit is contained in:
SelfConfusion 2024-07-12 21:48:12 +08:00
parent 8f12454e19
commit 4f85e5b1f2
1 changed files with 10 additions and 10 deletions

View File

@ -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")