From bdabdf287f416f20673fa1c77996ccf79a3d6469 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Thu, 17 Oct 2019 11:10:00 +0200
Subject: [PATCH] Improve calibrator error handling

---
 china_io-2019/python/calibrator.py |  6 ++++--
 china_io-2019/python/serialio.py   | 15 ++++++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/china_io-2019/python/calibrator.py b/china_io-2019/python/calibrator.py
index dcd2be6..51423c5 100755
--- a/china_io-2019/python/calibrator.py
+++ b/china_io-2019/python/calibrator.py
@@ -112,9 +112,11 @@ class ChinaIO:
         analogIn = self.io.analogIn()
         analogOut = self.io.analogOut()
         if len(analogIn) != 4:
-            raise Exception('Did not find 4 analogIn channels')
+            raise Exception('Did not find 4 analogIn channels (%d)' %
+                            (len(analogIn)))
         if len(analogOut) != 2:
-            raise Exception('Did not find 2 analogOut channels')
+            raise Exception('Did not find 2 analogOut channels (%d)'
+                            (len(analogOut)))
         for i,c in analogIn.items():
             if c.bits != 18:
                 raise Exception('analogIn[%d] is not 18 bit (%d)' % (i, c.bits))
diff --git a/china_io-2019/python/serialio.py b/china_io-2019/python/serialio.py
index c2ff526..b910072 100644
--- a/china_io-2019/python/serialio.py
+++ b/china_io-2019/python/serialio.py
@@ -80,20 +80,25 @@ class SerialIOConfig:
         self.cond = threading.Condition()
         pass
 
+    def getConfig(self, what):
+        if what in self.config:
+            return self.config[what]
+        return []
+            
     def digitalIn(self):
-        return self.config[DigitalIn]
+        return self.getConfig(DigitalIn)
 
     def digitalOut(self):
-        return self.config[DigitalOut]
+        return self.getConfig(DigitalOut)
 
     def analogIn(self):
-        return self.config[AnalogIn]
+        return self.getConfig(AnalogIn)
 
     def analogOut(self):
-        return self.config[AnalogOut]
+        return self.getConfig(AnalogOut)
 
     def counter(self):
-        return self.config[Counter]
+        return self.getConfig(Counter)
 
     def __str__(self):
         return "%s" % self.config
-- 
GitLab