# HG changeset patch # User Daniel O'Connor # Date 1611038601 -37800 # Node ID bf411c7f5e7871cb37ce4964b659dd36714de849 # Parent 29bcef5592839c0ca603b53d3bb7dea31174262d Perform a dummy write/read after initiateClear and check the event/error queue bit. diff -r 29bcef559283 -r bf411c7f5e78 usb488.py --- a/usb488.py Tue Jan 19 16:06:29 2021 +1030 +++ b/usb488.py Tue Jan 19 17:13:21 2021 +1030 @@ -116,6 +116,9 @@ STATUS_SPLIT_NOT_IN_PROGRESS = 0x82 STATUS_SPLIT_IN_PROGRESS = 0x83 +# SCPI error/event queue status register bit +STATUS_EVE_QUEUE = 0x04 + class USB488Device(object): def __init__(self, vendor = None, product = None, serial = None, path = None): """Search for a USB488 class device, if specified vendor, @@ -213,7 +216,21 @@ raise BaseException("Can't find bulk-out endpoint") self.tag = 1 + + # Flush out any pending data self.initiateClear() + # Perform dummy write/read otherwise the next read times out + try: + self.ask('*STB?', timeout = 0.001) + except usb.USBError: + pass + # Clear status register + for i in range(10): + self.write('*CLS') + if int(self.ask('*STB?')) & STATUS_EVE_QUEUE == 0: + break + else: + raise BaseException('Unable to clear status register') def __str__(self): rtn = "Mfg: %s Prod: %s" % (self.vendname, self.prodname) @@ -221,7 +238,7 @@ rtn += " S/N: " + self.serial return rtn - + def incrtag(self): self.tag = (self.tag + 1) % 255 if self.tag == 0: @@ -250,7 +267,7 @@ # Bump the tag self.incrtag() - + # Split it up into maxPacket sized chunks and send.. while len(pkt) > 0: chunk = pkt[0:self.maxPacket]