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