HendiCtrl: better Exceptions
This commit is contained in:
@@ -6,7 +6,10 @@ import sys
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
class HendiException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class HendiCtrl:
|
||||||
class HendiCtrl:
|
class HendiCtrl:
|
||||||
def __init__(self, port, speed):
|
def __init__(self, port, speed):
|
||||||
self.ser = serial.Serial(port, speed)
|
self.ser = serial.Serial(port, speed)
|
||||||
@@ -32,8 +35,12 @@ class HendiCtrl:
|
|||||||
}
|
}
|
||||||
self.poly_w2d = np.polyfit(powers, digits, 5)
|
self.poly_w2d = np.polyfit(powers, digits, 5)
|
||||||
self.poly_d2w = np.polyfit(digits, powers, 5)
|
self.poly_d2w = np.polyfit(digits, powers, 5)
|
||||||
|
|
||||||
|
try:
|
||||||
self.sw_id = self.getSoftwareIdentifier()
|
self.sw_id = self.getSoftwareIdentifier()
|
||||||
self.sw_ver = self.getSoftwareVersion()
|
self.sw_ver = self.getSoftwareVersion()
|
||||||
|
except HendiException:
|
||||||
|
print("HendiCtrl: Hendi not found")
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def remote_open(self):
|
def remote_open(self):
|
||||||
@@ -113,7 +120,7 @@ class HendiCtrl:
|
|||||||
self.__write(req)
|
self.__write(req)
|
||||||
rsp = self.__read()
|
rsp = self.__read()
|
||||||
if "OK" not in rsp[0]:
|
if "OK" not in rsp[0]:
|
||||||
raise Exception(rsp[1])
|
raise HendiException(f"Communication error")
|
||||||
|
|
||||||
return rsp[1]
|
return rsp[1]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user