Skip to content

Commit 5cfdac9

Browse files
fallensbourdeauducq
authored andcommittedFeb 20, 2015
Lda: replace assert with direct exception raising
1 parent 0dd5692 commit 5cfdac9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
 

Diff for: ‎artiq/devices/lda/driver.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def write(self, command, length, data=bytes()):
156156
buf = struct.pack("BBB6s", 0, command, length, data)
157157
res = self._check_error(self.hidapi.hid_write(self._dev, buf,
158158
len(buf)))
159-
assert res == len(buf), res
159+
if res != len(buf):
160+
raise IOError
160161

161162
def set(self, command, data):
162163
"""Sends a SET command to the Lab Brick device.
@@ -165,8 +166,10 @@ def set(self, command, data):
165166
:param data: payload of the command.
166167
"""
167168

168-
assert command & 0x80
169-
assert data
169+
if not data:
170+
raise ValueError("Data is empty")
171+
if not (command & 0x80):
172+
raise ValueError("Set commands must have most significant bit set")
170173
self.write(command, len(data), data)
171174

172175
def get(self, command, length, timeout=1000):
@@ -179,14 +182,17 @@ def get(self, command, length, timeout=1000):
179182
:rtype: bytes
180183
"""
181184

182-
assert not command & 0x80
185+
if command & 0x80:
186+
raise ValueError("Get commands must not have most significant bit"
187+
" set")
183188
status = None
184189
self.write(command, length)
185190
buf = ctypes.create_string_buffer(8)
186191
while status != command:
187192
res = self._check_error(self.hidapi.hid_read_timeout(self._dev,
188193
buf, len(buf), timeout))
189-
assert res == len(buf), res
194+
if res != len(buf):
195+
raise IOError
190196
status, length, data = struct.unpack("BB6s", buf.raw)
191197
data = data[:length]
192198
logger.info("%s %s %r", command, length, data)

0 commit comments

Comments
 (0)
Please sign in to comment.