Browse Source

catch serial exception on opening port

Thomas Buck 2 years ago
parent
commit
cff57b659e
2 changed files with 11 additions and 6 deletions
  1. 1
    1
      linux/PKGBUILD
  2. 10
    5
      linux/caselights

+ 1
- 1
linux/PKGBUILD View File

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

+ 10
- 5
linux/caselights View File

196
         self.serial = serial.Serial()
196
         self.serial = serial.Serial()
197
         self.serial.port = self.usedPort
197
         self.serial.port = self.usedPort
198
         self.serial.baudrate = 115200
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
             print("error connecting to: " + self.usedPort)
208
             print("error connecting to: " + self.usedPort)
204
-        return self.serial.is_open
209
+            return False
205
 
210
 
206
     def printRGBStrings(self, rs, gs, bs):
211
     def printRGBStrings(self, rs, gs, bs):
207
         if self.serial.is_open:
212
         if self.serial.is_open:

Loading…
Cancel
Save