HP3562A/__init__.py

Thu, 03 Jan 2008 19:06:48 +0100

author
David Douard <david.douard@logilab.fr>
date
Thu, 03 Jan 2008 19:06:48 +0100
changeset 19
42af82fdb8bb
parent 16
de9122b5680a
child 39
8becd52c2171
permissions
-rw-r--r--

fixes

13
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 """
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 HP3562A
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 =======
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5 Module for communicating with the HP 3562A Digital Signal Analyzer.
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 Subpackages
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 -----------
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 Constants
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 ---------
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 """
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
15 import struct
15
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
16 import re
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
17 import gpib
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
18 import numpy
13
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
20 ########################################
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
21 # HP3562A internal binary types decoders
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
22
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
23 def decode_float(s):
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
24 if len(s) == 4:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
25 i1, i2, e = struct.unpack('>hbb', s)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
26 i2 = i2 * 2**(-23)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
27 return (i1/32768. + i2)*2**e
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
28 else:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
29 i1, i2, i3, i4, e = struct.unpack('>hhhbb', s)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
30 if i2 < 0:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
31 i2 = (i2+32768.)*2**(-15)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
32 else:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
33 i2 = i2*2**(-15)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
34 if i3 < 0:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
35 i3 = (i3+32768.)*2**(-30)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
36 else:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
37 i3 = i3*2**(-15)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
38 i4 = i4 * 2**(-38)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
39 return (i1+i2+i3+i4)*2**(e-15)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
40
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
41 # def decode_float(s):
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
42 # assert len(s) in [4,8]
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
43 # # exponential term
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
44 # e = ord(s[-1])
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
45 # if e & 0x80:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
46 # e = e - 256
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
47
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
48 # # mantissa
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
49 # m = [ord(x) for x in s[:-1]]
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
50 # M = 0.
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
51 # for i in range(len(s)-1):
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
52 # #M += m[i]<<(i*8)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
53 # M += float(m[i])/2**((i+1)*8)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
54 # # XXX how do we deal negative numbers?
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
55 # #if m[0] & 0x80:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
56 # # M = M - 2^(len(s))
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
57 # return M * 2**(e+1)
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
58
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
59 def decode_string(s):
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
60 nb = ord(s[0])
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
61 s = s[1:nb+2]
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
62 r = ""
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
63 # XXX why do we need to do this? It's not described in the manual...
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
64 for c in s:
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
65 r += chr(ord(c) & 0x7F)
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
66 return r
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
67
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
68
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
69 ###
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
70 # Some useful functions
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
71 def format_header(header, head_struct, columns=80):
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
72 """
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
73 Pretty print a data block (trace, state or coord)
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
74 """
15
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
75 bool_re = re.compile(r'((?P<before>.*) )?(?P<flag>\w+/\w+)( (?P<after>.*))?')
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
76
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
77 todisp = []
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
78 for row in head_struct:
15
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
79 key = row[0]
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
80 typ = row[1]
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
81 if typ is None:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
82 continue
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
83 val = header.get(key, "N/A")
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
84 if isinstance(val, basestring):
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
85 val = repr(val)
15
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
86 elif typ is bool and isinstance(val, typ):
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
87 m = bool_re.match(key)
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
88 if m:
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
89 d = m.groupdict()
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
90 key = ""
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
91 if d['before']:
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
92 key += d['before']
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
93 if d['after']:
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
94 key += d['after']
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
95 key = key.capitalize()
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
96 val = d['flag'].split('/')[not val]
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
97 else:
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
98 val = str(val)
b930440af354 make header_formatter a little bit smarter (interpret bool values when it can)
David Douard <david.douard@logilab.fr>
parents: 14
diff changeset
99 else:
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
100 val = str(val)
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
101 todisp.append((key+":", val))
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
102 maxk = max([len(k) for k, v in todisp])
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
103 maxv = max([len(v) for k, v in todisp])
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
104 fmt = "%%-%ds %%-%ds"%(maxk, maxv)
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
105 w = maxk+maxv+4
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
106 ncols = columns/w
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
107 if ncols:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
108 nrows = len(todisp)/ncols
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
109 else:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
110 nrows = len(todisp)
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
111 res = ""
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
112 for i in range(nrows):
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
113 res += "| ".join([fmt%todisp[j*nrows+i] for j in range(ncols)]) + "\n"
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
114 return res
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
115
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
116 def decode_header(data, header_struct, idx=0):
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
117 d = data
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
118 if d[idx:].startswith('#'):
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
119 # we have a preliminary header here...
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
120 typ = d[idx:idx+2]
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
121 assert typ == "#A"
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
122 idx += 2
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
123 totlen = struct.unpack('>h', d[idx:idx+2])[0]
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
124 idx += 2
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
125 tt=0
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
126 header = {}
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
127 for i, (nam, dtype, fmt, nbytes) in enumerate(header_struct):
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
128 if dtype is None:
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
129 idx += nbytes
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
130 continue
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
131 elif dtype == str:
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
132 val = decode_string(d[idx:])
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
133 else:
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
134 if fmt:
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
135 v = struct.unpack('>'+fmt, d[idx: idx+nbytes])[0]
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
136 if isinstance(dtype, dict):
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
137 val = dtype.get(int(v), "N/A")
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
138 else:
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
139 val = dtype(v)
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
140 else:
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
141 val = dtype(d[idx: idx+nbytes])
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
142 header[nam] = val
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
143 idx += nbytes
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
144 return header, idx
13
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
145
16
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
146 def read_trace(data, idx, nelts):
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
147 assert len(data[idx:]) >= (nelts*4), "data[idx:] is too small (%s for %s)"%(len(data[idx:]), (nelts*4))
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
148 resu = []
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
149 for i in range(nelts):
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
150 resu.append(decode_float(data[idx: idx+4]))
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
151 idx += 4
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
152 return numpy.array(resu, dtype=float)
de9122b5680a Several improvements (code refactoring) + add stuff to decode binary coordinate data block ("DCBN" command)
David Douard <david.douard@logilab.fr>
parents: 15
diff changeset
153
13
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
154 #####################
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
155 # HP3562A constants
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
156
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
157 # GPIB buffer size is 3x80 characters lines
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
158 class STATUS_BYTE(gpib.Constants):
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
159 # HP3562A Status Byte, as returned by a serial poll
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
160 _constants = [(0x40, "RQS", "Request Service"), # when sent in response to a serial poll
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
161 (0x20, "ERR", "GPIB error"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
162 (0x10, "RDY", "ready to accept GPIB commands"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
163 ]
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
164
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
165 conditions = [(0, "NSR", "No service requested"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
166 (1, "USRQ1", "User SRQ #1"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
167 (2, "USRQ1", "User SRQ #2"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
168 (3, "USRQ1", "User SRQ #3"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
169 (4, "USRQ1", "User SRQ #4"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
170 (5, "USRQ1", "User SRQ #5"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
171 (6, "USRQ1", "User SRQ #6"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
172 (7, "USRQ1", "User SRQ #7"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
173 (8, "USRQ1", "User SRQ #8"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
174 (9, "EOD", "End of disk action"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
175 (10, "EOP", "End of plot action"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
176 (11, "STCH", "Instrument status changed"), # any change in
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
177 # the status register sets this condition
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
178 (12, "PWR", "Power on"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
179 (13, "KEY", "Key pressed"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
180 (14, "DCP", "Device clear plotter (listen)"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
181 # ...
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
182 ]
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
183 def __init__(self):
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
184 super(STATUS_BYTE, self).__init__()
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
185 self._conditions = dict([(x[0], x[1]) for x in self.conditions])
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
186 self._rev_conditions = dict([(x[1], x[0]) for x in self.conditions])
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
187 self._long_conditions = dict([(x[0], x[2]) for x in self.conditions])
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
188
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
189 def byte_condition(self, byte):
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
190 byte = byte & 0x8F
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
191 return self._conditions.get(byte, "N/A")
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
192
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
193 class IS_REGISTER(gpib.Constants):
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
194 _constants = [(0x01, "MEASP", "measeurement pause"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
195 (0x02, "ASQP", "Auto sequence pause"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
196 (0X04, "EOM", "End of measurement, capture or throughput"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
197 (0x08, "EOAS", "End of auto sequence"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
198 (0x10, "SWPR", "Sweep point ready"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
199 (0x20, "CH1OV", "Channel 1 overrange"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
200 (0x40, "CH2OV", "Channel 2 overrange"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
201 (0X80, "CH1HR", "Channel 1 half range"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
202 (0x100, "CH2HR", "Channel 2 half range"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
203 (0x200, "SFALT", "Source falt"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
204 (0x400, "RUNL", "Reference unlock"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
205 (0x800, "RMKT", "Remote marker knob turn"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
206 (0x1000, "REKT", "Remote entry knob turn"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
207 (0x2000, "ASRC", "Asctive Status Register changed"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
208 (0x4000, "PWRF", "Power-on test failed"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
209 ]
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
210
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
211 class StatusQuery(gpib.Constants):
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
212 _command = "STA?"
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
213 _constants = [(0x01, "N/A", "Not used"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
214 (0x02, "N/A", "Not used"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
215 (0x04, "KEY", "Key pressed"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
216 (0x08, "N/A", "Not used"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
217 (0x10, "RDY", "Ready"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
218 (0x20, "ERR", "Error"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
219 (0x40, "RQS", "Request"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
220 (0x80, "MOS", "Message on screen"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
221 (0x100, "MEASP", "measeurement pause"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
222 (0x200, "ASQP", "Auto sequence pause"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
223 (0X400, "EOM", "End of measurement, capture or throughput"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
224 (0x800, "EOAS", "End of auto sequence"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
225 (0x1000, "SWPR", "Sweep point ready"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
226 (0x2000, "CH1OV", "Channel 1 overrange"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
227 (0x4000, "CH2OV", "Channel 2 overrange"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
228 (0x8000, "MAOV", "Math overflow"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
229 ]
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
230 class ActivityStatysRegister(gpib.Constants):
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
231 _command = "AS?"
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
232 _constants = [(0x01, "CKFL", "Check fault log"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
233 (0x02, "FITR", "Filling time record"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
234 (0x04, "FLTR", "Filters settings"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
235 (0x08, "CFTP", "Curve fir in progress"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
236 (0x10, "MSSM", "Missed sample"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
237 (0x20, "TMPR", "Timed preview"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
238 (0x40, "ACDA", "Accept date"),
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
239 #...
78e3e839658b some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff changeset
240 ]
14
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
241
07e2cbf140df several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents: 13
diff changeset
242

mercurial