From bda11149df099385360f77ac1c018e1cd72bb8ed Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 24 Nov 2015 17:10:31 +0800 Subject: [PATCH] devices/thorlabs_tcube: fix more style issues --- artiq/devices/thorlabs_tcube/driver.py | 101 +++++-------------------- 1 file changed, 17 insertions(+), 84 deletions(-) diff --git a/artiq/devices/thorlabs_tcube/driver.py b/artiq/devices/thorlabs_tcube/driver.py index 72ea27907..a9c9d47fc 100644 --- a/artiq/devices/thorlabs_tcube/driver.py +++ b/artiq/devices/thorlabs_tcube/driver.py @@ -186,7 +186,7 @@ class Message: raise ValueError -class Tcube: +class _Tcube: def __init__(self, serial_dev): self.port = serial.serial_for_url(serial_dev, baudrate=115200, rtscts=True) @@ -202,16 +202,15 @@ class Tcube: msg.send(self.port) def handle_message(self, msg): - pass + # derived classes must implement this + raise NotImplementedError def send_request(self, msgreq_id, wait_for_msgs, param1=0, param2=0, data=None): Message(msgreq_id, param1, param2, data=data).send(self.port) - msg = msg_id = None - while msg is None or msg_id not in wait_for_msgs: + msg = None + while msg is None or msg.id not in wait_for_msgs: msg = Message.recv(self.port) self.handle_message(msg) - msg_id = msg.id - return msg def set_channel_enable_state(self, activated): @@ -238,7 +237,7 @@ class Tcube: self.chan_enabled = False else: raise MsgError("Channel state response is invalid: neither " - + "1 nor 2: {}".format(self.chan_enabled)) + "1 nor 2: {}".format(self.chan_enabled)) return self.chan_enabled def module_identify(self): @@ -247,7 +246,6 @@ class Tcube: Instruct hardware unit to identify itself by flashing its front panel led. """ - self.send(Message(MGMSG.MOD_IDENTIFY)) def hardware_start_update_messages(self, update_rate): @@ -258,13 +256,10 @@ class Tcube: :param update_rate: Rate at which you will receive status updates """ - self.send(Message(MGMSG.HW_START_UPDATEMSGS, param1=update_rate)) def hardware_stop_update_messages(self): - """Stop status updates from the controller. - """ - + """Stop status updates from the controller.""" self.send(Message(MGMSG.HW_STOP_UPDATEMSGS)) def hardware_request_information(self): @@ -282,9 +277,9 @@ class Tcube: return True -class Tpz(Tcube): +class Tpz(_Tcube): def __init__(self, serial_dev): - Tcube.__init__(self, serial_dev) + _Tcube.__init__(self, serial_dev) self.voltage_limit = self.get_tpz_io_settings()[0] def handle_message(self, msg): @@ -294,8 +289,8 @@ class Tpz(Tcube): if msg_id == MGMSG.HW_DISCONNECT: raise MsgError("Error: Please disconnect the TPZ001") elif msg_id == MGMSG.HW_RESPONSE: - raise MsgError("Hardware error, please disconnect" - + "and reconnect the TPZ001") + raise MsgError("Hardware error, please disconnect " + "and reconnect the TPZ001") elif msg_id == MGMSG.HW_RICHRESPONSE: (code, ) = st.unpack("` method between the three values 75 V, 100 V and 150 V. """ - if voltage < 0 or voltage > self.voltage_limit: raise ValueError("Voltage must be in range [0;{}]" .format(self.voltage_limit)) @@ -368,7 +360,6 @@ class Tpz(Tcube): :return: The output voltage. :rtype: float """ - get_msg = self.send_request(MGMSG.PZ_REQ_OUTPUTVOLTS, [MGMSG.PZ_GET_OUTPUTVOLTS], 1) return st.unpack("` method. """ - volt = round(output*32767/self.voltage_limit) payload = st.pack("` command. """ - self.send_request(MGMSG.MOT_MOVE_RELATIVE, [MGMSG.MOT_MOVE_COMPLETED, MGMSG.MOT_MOVE_STOPPED], 1) @@ -1057,7 +1007,6 @@ class Tdc(Tcube): :param relative_distance: The distance to move in position encoder counts. """ - payload = st.pack("` command. """ - self.send_request(MGMSG.MOT_MOVE_ABSOLUTE, [MGMSG.MOT_MOVE_COMPLETED, MGMSG.MOT_MOVE_STOPPED], param1=1) @@ -1083,18 +1031,16 @@ class Tdc(Tcube): integer that specifies the absolute distance in position encoder counts. """ - payload = st.pack("