Mercurial > ~darius > hgwebdir.cgi > pyinst
diff rsib.py @ 14:55c8dae6d1db
Add test code and some (not enabled) sequence checking.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 10 Aug 2011 12:49:15 +0930 |
parents | 85dfc0babc36 |
children | 6e7619f2dffd |
line wrap: on
line diff
--- a/rsib.py Sat May 16 23:35:22 2009 +0930 +++ b/rsib.py Wed Aug 10 12:49:15 2011 +0930 @@ -75,7 +75,7 @@ MSG_HELLO = 0x40 # We send this on connect MSG_CMDREP = 0x80 # Reply from the instrument to us MSG_CMD = 0x90 # Command to the instrument - +MSG_SRQ = 0x91 # Query SRQ import socket class RSIBDevice(object): @@ -133,9 +133,12 @@ raise "Reply out of order, got 0x%02x expected 0x%02x" % (ord(rx[6]), self.tag) rxlen = ord(rx[0]) << 24 | ord(rx[1]) << 16 | ord(rx[2]) << 8 | ord(rx[3]) + print "Msg ID 0x%02x" % (ord(rx[4])) + if False and ord(rx[4]) != MSG_CMDREP: + raise "Unexpected Msg ID 0x%02x" % (ord(rx[4])) + if ord(rx[5]) != 0: print "Mystery byte %d != 0" % (ord(rx[5])) - # Fetch the actual reply now we know the length reply = '' while len(reply) < rxlen: @@ -146,7 +149,45 @@ return(reply) + def queryrsb(self): + msg = '\x00\x00\x00\x00\xd1\x18\x00' + self.s2.send(msg) + + reply = '' + while len(reply) < 7: + rx = self.s2.recv(7) + if rx == '': + raise "EOF from device" + reply += rx + # '\x00\x00\x00\x00\x80\x04\x01' => STB = 4 + if rx[4] != '\x80': + raise "Incorrect Msg ID in response to STB query" + + return ord(rx[5]) + + def waitsrq(self): + msg = '\x00\x00\x00\x00\xb1\x00\x00' + + def testsrq(self): + msg = '\x00\x00\x00\x00\x91\x00\x00' + self.s2.send(msg) + reply = '' + while len(reply) < 7: + rx = self.s2.recv(7) + if rx == '': + raise "EOF from device" + reply += rx + + # 00 00 00 00 80 14 08 - SRQ = 0 + # 00 00 00 00 a0 64 07 - SRQ = 1 + if rx == '\x00\x00\x00\x00\x80\x14\x08': + return False + elif rx == '\x00\x00\x00\x00\xa0\x64\x07': + return True + else: + raise "Unknown SRQ byte sequence - " + str(map(ord, rx)) + def test(r): import numpy from matplotlib import pylab