comparison usb488.py @ 66:bf411c7f5e78

Perform a dummy write/read after initiateClear and check the event/error queue bit.
author Daniel O'Connor <doconnor@gsoft.com.au>
date Tue, 19 Jan 2021 17:13:21 +1030
parents 29bcef559283
children 98b9258c75b6
comparison
equal deleted inserted replaced
65:29bcef559283 66:bf411c7f5e78
113 STATUS_PENDING = 0x02 113 STATUS_PENDING = 0x02
114 STATUS_FAILED = 0x80 114 STATUS_FAILED = 0x80
115 STATUS_TRANSFER_NOT_IN_PROGRESS = 0x81 115 STATUS_TRANSFER_NOT_IN_PROGRESS = 0x81
116 STATUS_SPLIT_NOT_IN_PROGRESS = 0x82 116 STATUS_SPLIT_NOT_IN_PROGRESS = 0x82
117 STATUS_SPLIT_IN_PROGRESS = 0x83 117 STATUS_SPLIT_IN_PROGRESS = 0x83
118
119 # SCPI error/event queue status register bit
120 STATUS_EVE_QUEUE = 0x04
118 121
119 class USB488Device(object): 122 class USB488Device(object):
120 def __init__(self, vendor = None, product = None, serial = None, path = None): 123 def __init__(self, vendor = None, product = None, serial = None, path = None):
121 """Search for a USB488 class device, if specified vendor, 124 """Search for a USB488 class device, if specified vendor,
122 product, serial and path will refine the search""" 125 product, serial and path will refine the search"""
211 # Data to the device (mandatory) 214 # Data to the device (mandatory)
212 if self.bulkoutep == None: 215 if self.bulkoutep == None:
213 raise BaseException("Can't find bulk-out endpoint") 216 raise BaseException("Can't find bulk-out endpoint")
214 217
215 self.tag = 1 218 self.tag = 1
219
220 # Flush out any pending data
216 self.initiateClear() 221 self.initiateClear()
222 # Perform dummy write/read otherwise the next read times out
223 try:
224 self.ask('*STB?', timeout = 0.001)
225 except usb.USBError:
226 pass
227 # Clear status register
228 for i in range(10):
229 self.write('*CLS')
230 if int(self.ask('*STB?')) & STATUS_EVE_QUEUE == 0:
231 break
232 else:
233 raise BaseException('Unable to clear status register')
217 234
218 def __str__(self): 235 def __str__(self):
219 rtn = "Mfg: %s Prod: %s" % (self.vendname, self.prodname) 236 rtn = "Mfg: %s Prod: %s" % (self.vendname, self.prodname)
220 if self.serial != "": 237 if self.serial != "":
221 rtn += " S/N: " + self.serial 238 rtn += " S/N: " + self.serial
222 239
223 return rtn 240 return rtn
224 241
225 def incrtag(self): 242 def incrtag(self):
226 self.tag = (self.tag + 1) % 255 243 self.tag = (self.tag + 1) % 255
227 if self.tag == 0: 244 if self.tag == 0:
228 self.tag += 1 245 self.tag += 1
229 246
248 alignlen = ((len(pkt) // 4) + 1) * 4 265 alignlen = ((len(pkt) // 4) + 1) * 4
249 pkt = pkt + [0] * (alignlen - len(pkt)) 266 pkt = pkt + [0] * (alignlen - len(pkt))
250 267
251 # Bump the tag 268 # Bump the tag
252 self.incrtag() 269 self.incrtag()
253 270
254 # Split it up into maxPacket sized chunks and send.. 271 # Split it up into maxPacket sized chunks and send..
255 while len(pkt) > 0: 272 while len(pkt) > 0:
256 chunk = pkt[0:self.maxPacket] 273 chunk = pkt[0:self.maxPacket]
257 pkt = pkt[self.maxPacket:] 274 pkt = pkt[self.maxPacket:]
258 275