![](/img/trans.png)
[英]How to connect the current user and the user of a web application using htpasswd in python?
[英]How to notify user that python application is unable to connect
這個python Tkinter GUI應用程序通過串行端口與嵌入式Linux目標通信。 如果應用程序無法使用串行端口連接到目標,是否可以通過tkMessageBox通知用戶? 當前,主機上的Linux啟動器圖標用於啟動此應用程序,因此,如果無法建立連接,則不會向用戶提供任何反饋。
def initialize(self):
self.ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
...
編輯:這是解決方案
def initialize(self):
try:
self.ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
except:
tkMessageBox.showerror(title="Error", message="No Connection")
sys.exit()
您是否使用了pyserial
庫? 它可以解決您的問題。
可以使用異常serial.SerialTimeoutException
,其中在寫入超時時引發異常。
我希望它是有用的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.