Mercurial > ~darius > hgwebdir.cgi > pyinst
diff 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 |
line wrap: on
line diff
--- 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]