瀏覽代碼

catch serial exception on opening port

Thomas Buck 2 年之前
父節點
當前提交
cff57b659e
共有 2 個文件被更改,包括 11 次插入6 次删除
  1. 1
    1
      linux/PKGBUILD
  2. 10
    5
      linux/caselights

+ 1
- 1
linux/PKGBUILD 查看文件

@@ -1,7 +1,7 @@
1 1
 # Maintainer: Thomas Buck <thomas@xythobuz.de>
2 2
 pkgname=CaseLights
3 3
 pkgver=0.2
4
-pkgrel=2
4
+pkgrel=3
5 5
 pkgdesc="RGB LED and UV strip controls"
6 6
 arch=('any')
7 7
 license=('unknown')

+ 10
- 5
linux/caselights 查看文件

@@ -196,12 +196,17 @@ class CaseLights():
196 196
         self.serial = serial.Serial()
197 197
         self.serial.port = self.usedPort
198 198
         self.serial.baudrate = 115200
199
-        self.serial.open()
200
-        if self.serial.is_open:
201
-            print("connected to: " + self.usedPort)
202
-        else:
199
+
200
+        try:
201
+            self.serial.open()
202
+            if self.serial.is_open:
203
+                print("connected to: " + self.usedPort)
204
+            else:
205
+                print("error connecting to: " + self.usedPort)
206
+            return self.serial.is_open
207
+        except serial.serialutil.SerialException:
203 208
             print("error connecting to: " + self.usedPort)
204
-        return self.serial.is_open
209
+            return False
205 210
 
206 211
     def printRGBStrings(self, rs, gs, bs):
207 212
         if self.serial.is_open:

Loading…
取消
儲存