Tue, 31 Mar 2009 00:13:05 +0200
fixes in HP8904 device description
63
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
62
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
66
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
2 | # This program is free software; you can redistribute it and/or modify it under |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
3 | # the terms of the GNU General Public License as published by the Free Software |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
4 | # Foundation; either version 2 of the License, or (at your option) any later |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
5 | # version. |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
6 | # |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
7 | # This program is distributed in the hope that it will be useful, but WITHOUT |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
8 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
9 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
10 | # |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
11 | # You should have received a copy of the GNU General Public License along with |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
12 | # this program; if not, write to the Free Software Foundation, Inc., |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
13 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
14 | """ Copyright (c) 2007-2008 David Douard (Paris, FRANCE). |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
15 | http://www.logilab.org/project/pygpibtoolkit -- mailto:david.douard@logilab.fr |
2a97995628a3
added copyright header to every python file
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
16 | |
63
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
62
diff
changeset
|
17 | Several utility functions for GPIB data conversions |
53
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
18 | """ |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
19 | import struct |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
20 | import re |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
21 | import numpy |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
22 | |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
23 | ######################################## |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
24 | # internal binary types decoders |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
25 | |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
26 | def decode_float(s): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
27 | """ |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
28 | Decode a Float from the HP binary representation. |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
29 | """ |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
30 | if len(s) == 4: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
31 | i1, i2, e = struct.unpack('>hbb', s) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
32 | i2 = i2 * 2**(-23) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
33 | return (i1/32768. + i2)*2**e |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
34 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
35 | i1, i2, i3, i4, e = struct.unpack('>hhhbb', s) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
36 | if i2 < 0: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
37 | i2 = (i2+32768.)*2**(-15) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
38 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
39 | i2 = i2*2**(-15) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
40 | if i3 < 0: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
41 | i3 = (i3+32768.)*2**(-30) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
42 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
43 | i3 = i3*2**(-15) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
44 | i4 = i4 * 2**(-38) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
45 | return (i1+i2+i3+i4)*2**(e-15) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
46 | |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
47 | def decode_string(s): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
48 | """ |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
49 | Decode a string from the HP binay representation. |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
50 | """ |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
51 | nb = ord(s[0]) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
52 | s = s[1:nb+2] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
53 | r = "" |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
54 | # XXX why do we need to do this? It's not described in the manual... |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
55 | for c in s: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
56 | r += chr(ord(c) & 0x7F) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
57 | return r |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
58 | |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
59 | ### |
63
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
62
diff
changeset
|
60 | # Datablock useful functions |
53
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
61 | def format_datablock_header(header, head_struct, columns=80): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
62 | """ |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
63 | Pretty print a data block (trace, state or coord) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
64 | """ |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
65 | bool_re = re.compile(r'((?P<before>.*) )?(?P<flag>\w+/\w+)( (?P<after>.*))?') |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
66 | |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
67 | todisp = [] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
68 | for row in head_struct: |
62
486a480d196b
finish some previous unfinished (!) refactoring
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
69 | pname = row[0] |
486a480d196b
finish some previous unfinished (!) refactoring
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
70 | key = row[1] |
486a480d196b
finish some previous unfinished (!) refactoring
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
71 | typ = row[2] |
53
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
72 | if typ is None: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
73 | continue |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
74 | val = header.get(key, "N/A") |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
75 | if isinstance(val, basestring): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
76 | val = repr(val) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
77 | elif typ is bool and isinstance(val, typ): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
78 | m = bool_re.match(key) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
79 | if m: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
80 | d = m.groupdict() |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
81 | key = "" |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
82 | if d['before']: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
83 | key += d['before'] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
84 | if d['after']: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
85 | key += d['after'] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
86 | key = key.capitalize() |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
87 | val = d['flag'].split('/')[not val] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
88 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
89 | val = str(val) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
90 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
91 | val = str(val) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
92 | todisp.append((key+":", val)) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
93 | maxk = max([len(k) for k, v in todisp]) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
94 | maxv = max([len(v) for k, v in todisp]) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
95 | fmt = "%%-%ds %%-%ds"%(maxk, maxv) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
96 | w = maxk+maxv+4 |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
97 | ncols = columns/w |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
98 | if ncols: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
99 | nrows = len(todisp)/ncols |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
100 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
101 | nrows = len(todisp) |
62
486a480d196b
finish some previous unfinished (!) refactoring
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
102 | ncols = 1 |
53
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
103 | res = "" |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
104 | for i in range(nrows): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
105 | res += "| ".join([fmt%todisp[j*nrows+i] for j in range(ncols)]) + "\n" |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
106 | return res |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
107 | |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
108 | def decode_datablock_header(data, header_struct, idx=0): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
109 | d = data |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
110 | if d[idx:].startswith('#'): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
111 | # we have a preliminary header here... |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
112 | typ = d[idx:idx+2] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
113 | assert typ == "#A" |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
114 | idx += 2 |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
115 | totlen = struct.unpack('>h', d[idx:idx+2])[0] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
116 | idx += 2 |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
117 | tt=0 |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
118 | header = {} |
62
486a480d196b
finish some previous unfinished (!) refactoring
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
119 | for i, (cmd, nam, dtype, fmt, nbytes) in enumerate(header_struct): |
53
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
120 | if dtype is None: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
121 | idx += nbytes |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
122 | continue |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
123 | elif dtype == str: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
124 | val = decode_string(d[idx:]) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
125 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
126 | if fmt: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
127 | v = struct.unpack('>'+fmt, d[idx: idx+nbytes])[0] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
128 | if isinstance(dtype, dict): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
129 | val = dtype.get(int(v), "N/A") |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
130 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
131 | val = dtype(v) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
132 | else: |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
133 | val = dtype(d[idx: idx+nbytes]) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
134 | header[nam] = val |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
135 | idx += nbytes |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
136 | return header, idx |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
137 | |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
138 | def read_datablock_trace(data, idx, nelts): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
139 | assert len(data[idx:]) >= (nelts*4), "data[idx:] is too small (%s for %s)"%(len(data[idx:]), (nelts*4)) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
140 | resu = [] |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
141 | for i in range(nelts): |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
142 | resu.append(decode_float(data[idx: idx+4])) |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
143 | idx += 4 |
8e32c806fcdd
Major refactoring in progress. Build the toolkit around a GPIB controller which have a communication thread with the devices. Every device is an instance of a class that describes the device model and registers itself to the controller.
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
144 | return numpy.array(resu, dtype=float) |