comparison usb488.py @ 5:51d1fc44a753

Add variable timeout for reads. Modify the example to use it & print how long curve takes.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 13 May 2009 17:17:01 +0930
parents 6b360c30eed6
children 813e183cfd49
comparison
equal deleted inserted replaced
4:6b360c30eed6 5:51d1fc44a753
193 #print "Sending %s bytes of data: %s" % (len(chunk), chunk) 193 #print "Sending %s bytes of data: %s" % (len(chunk), chunk)
194 wrote = self.handle.bulkWrite(self.bulkoutep, chunk) 194 wrote = self.handle.bulkWrite(self.bulkoutep, chunk)
195 if wrote != len(chunk): 195 if wrote != len(chunk):
196 raise "Short write, got %d, expected %d" % (wrote, len(chunk)) 196 raise "Short write, got %d, expected %d" % (wrote, len(chunk))
197 197
198 def read(self): 198 def read(self, timeout = 0.2):
199 """Read data from the device""" 199 """Read data from the device, waits for up to timeout seconds for each USB transaction"""
200
201 # Mangle into milliseconds
202 _timeout = int(timeout * 1000.0)
200 203
201 # Maximum we accept at once 204 # Maximum we accept at once
202 # Was 2^31 - 1 but that seems to make things take too long to 205 # Was 2^31 - 1 but that seems to make things take too long to
203 # read (perhaps libusb tries to malloc it..) 206 # read (perhaps libusb tries to malloc it..)
204 datalen = 10240 207 datalen = 10240
216 # Bump tag 219 # Bump tag
217 self.incrtag() 220 self.incrtag()
218 221
219 # Send it 222 # Send it
220 #print "Sending " + str(pkt) 223 #print "Sending " + str(pkt)
221 wrote = self.handle.bulkWrite(self.bulkoutep, pkt) 224 wrote = self.handle.bulkWrite(self.bulkoutep, pkt, _timeout)
222 if wrote != len(pkt): 225 if wrote != len(pkt):
223 print "Short write, got %d, expected %d" % (wrote, len(pkt)) 226 print "Short write, got %d, expected %d" % (wrote, len(pkt))
224 227
225 #print "Reading.." 228 #print "Reading.."
226 read = self.handle.bulkRead(self.bulkinep, datalen) 229 read = self.handle.bulkRead(self.bulkinep, datalen, _timeout)
227 #print "Read %s bytes: %s" % (len(read), str(read)) 230 #print "Read %s bytes: %s" % (len(read), str(read))
228 231
229 if read[0] != DEV_DEP_MSG_IN: 232 if read[0] != DEV_DEP_MSG_IN:
230 raise "Unexpected Msg ID, got %s expected %d" % (read[0], DEV_DEP_MSG_IN) 233 raise "Unexpected Msg ID, got %s expected %d" % (read[0], DEV_DEP_MSG_IN)
231 if read[1] != exptag: 234 if read[1] != exptag: