@@ -156,7 +156,8 @@ def write(self, command, length, data=bytes()):
156
156
buf = struct .pack ("BBB6s" , 0 , command , length , data )
157
157
res = self ._check_error (self .hidapi .hid_write (self ._dev , buf ,
158
158
len (buf )))
159
- assert res == len (buf ), res
159
+ if res != len (buf ):
160
+ raise IOError
160
161
161
162
def set (self , command , data ):
162
163
"""Sends a SET command to the Lab Brick device.
@@ -165,8 +166,10 @@ def set(self, command, data):
165
166
:param data: payload of the command.
166
167
"""
167
168
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" )
170
173
self .write (command , len (data ), data )
171
174
172
175
def get (self , command , length , timeout = 1000 ):
@@ -179,14 +182,17 @@ def get(self, command, length, timeout=1000):
179
182
:rtype: bytes
180
183
"""
181
184
182
- assert not command & 0x80
185
+ if command & 0x80 :
186
+ raise ValueError ("Get commands must not have most significant bit"
187
+ " set" )
183
188
status = None
184
189
self .write (command , length )
185
190
buf = ctypes .create_string_buffer (8 )
186
191
while status != command :
187
192
res = self ._check_error (self .hidapi .hid_read_timeout (self ._dev ,
188
193
buf , len (buf ), timeout ))
189
- assert res == len (buf ), res
194
+ if res != len (buf ):
195
+ raise IOError
190
196
status , length , data = struct .unpack ("BB6s" , buf .raw )
191
197
data = data [:length ]
192
198
logger .info ("%s %s %r" , command , length , data )
0 commit comments