fix can not connect to serial bug
This commit is contained in:
		@@ -10,4 +10,3 @@ pyinstaller==6.9.0
 | 
			
		||||
pyinstaller-hooks-contrib==2024.7
 | 
			
		||||
pyserial==3.5
 | 
			
		||||
PyYAML==6.0.1
 | 
			
		||||
serial==0.0.97
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								src/main.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/main.py
									
									
									
									
									
								
							@@ -6,6 +6,7 @@ import serial.tools
 | 
			
		||||
import serial.tools.list_ports as ls_ports
 | 
			
		||||
 | 
			
		||||
from typing import Optional, Any
 | 
			
		||||
import platform
 | 
			
		||||
import functools
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -19,6 +20,7 @@ class App(ctk.CTk):
 | 
			
		||||
    gain_values = gain_default.copy()
 | 
			
		||||
    gain_values_store = gain_default.copy()
 | 
			
		||||
    gain_enable = [True for i in range(5)]
 | 
			
		||||
    system_platform = platform.system()
 | 
			
		||||
 | 
			
		||||
    def __init__(self) -> None:
 | 
			
		||||
        super().__init__()
 | 
			
		||||
@@ -45,8 +47,12 @@ class App(ctk.CTk):
 | 
			
		||||
            ctk.set_widget_scaling(0.8)
 | 
			
		||||
 | 
			
		||||
        # 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)
 | 
			
		||||
        elif self.system_platform == "Windows":
 | 
			
		||||
          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}")
 | 
			
		||||
 | 
			
		||||
@@ -287,11 +293,11 @@ class App(ctk.CTk):
 | 
			
		||||
                try:
 | 
			
		||||
                    self.serial = serial.Serial(self.select_port, self.serial_baudrate)
 | 
			
		||||
                except AttributeError:
 | 
			
		||||
                    print("Please Select Serial Port")
 | 
			
		||||
                    messagebox.showError("Please Select Serial Port")
 | 
			
		||||
                    print("Port or Baudrate Wrong")
 | 
			
		||||
                    messagebox.showError("Port or Baudrate Wrong")
 | 
			
		||||
                except serial.serialutil.SerialException:
 | 
			
		||||
                    print("Can't Control the Serial Port")
 | 
			
		||||
                    messagebox.showError("Can't Control the Serial Port")
 | 
			
		||||
                    print("Can't Connect to the Serial Port")
 | 
			
		||||
                    messagebox.showError("Can't Connect to the Serial Port")
 | 
			
		||||
                else:
 | 
			
		||||
                    self.serial_status = True
 | 
			
		||||
                    self.serial_button_text.set("断开连接")
 | 
			
		||||
 
 | 
			
		||||
@@ -78,6 +78,8 @@ class Message(CTkMessagebox):
 | 
			
		||||
        )
 | 
			
		||||
        if isHighDPI:
 | 
			
		||||
            self._set_scaling(1.7, 1.7)
 | 
			
		||||
        else:
 | 
			
		||||
            self._set_scaling(1.1, 1.1)
 | 
			
		||||
 | 
			
		||||
def showError(message:str)->None:
 | 
			
		||||
    Message(title="Error", message=message, icon="cancel", isHighDPI=isHighDIP)
 | 
			
		||||
		Reference in New Issue
	
	Block a user