plotter/gpib.py

Fri, 25 Jan 2008 21:00:34 +0100

author
David Douard <david.douard@logilab.fr>
date
Fri, 25 Jan 2008 21:00:34 +0100
changeset 32
59da528bc470
parent 12
gpib.py@a04bea92c509
permissions
-rw-r--r--

refactoring: created a 'plotter' subdirectory and put everything related to GPIB/HPGL plotting under it

2
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 """
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 gpib: create serial connection to GPIB-USB device (ProLogix is the
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 only supported device for now).
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 """
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5 import serial
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 from serial.serialutil import SerialException
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 import time
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 class ConnectionError(Exception):
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 pass
cd9efa64f6da added a gpib module (handle gpib connection)
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11
12
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
12 class Constants(object):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
13 def __init__(self):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
14 self.constants = {}
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
15 self.descriptions = {}
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
16 self.rev_constants = {}
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
17 for v, k, m in self._constants:
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
18 self.k = v
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
19 self.constants[v] = k
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
20 self.rev_constants[k] = v
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
21 self.descriptions[v] = m
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
22
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
23 def __getitem__(self, k):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
24 if isinstance(k, basestring):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
25 return self.rev_constants[k]
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
26 else:
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
27 return self.constants[k]
9
3b50c46fca56 several updates to the gpib module
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
28
12
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
29 def get_description(self, k):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
30 if isinstance(k, basestring):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
31 k = self.rev_constants[k]
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
32 return self.descriptions[k]
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
33
9
3b50c46fca56 several updates to the gpib module
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
34
12
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
35 class MODE(Constants):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
36 _constants = [(1, "CONTROLLER", "Set device as Controller in Charge"),
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
37 (0, "DEVICE", "Set device as simple listener"),
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
38 ]
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
39 # TODO
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
40 # class STATUS_BYTE(Constants):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
41 # # IEEE 488.2 Status Byte constants
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
42 # MAV = 0x10 # Message AVailable: bit 4 of the Status Byte
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
43 # ESB = 0x20 # Event Status Bit: bit 5 of the Status Byte
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
44 # MSS = 0x40 # Master Summary Status bit: bit 6 of the Status Byte (NOT
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
45 # # sent in response to a serial poll)
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
46 # RQS = 0x40 # Request Service: bit 6 of the Status Byte (when sent in
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
47 # # response to a serial poll)
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
48 # class SESR(Constants):
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
49 # # SESR constants (Standard Event Status Register)
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
50 # PON = 0x80 # Power On: Power has been turned On since last register
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
51 # # read access
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
52 # URQ = 0x40 # User Request: the user has activated some device control
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
53 # # (whatever the Remote Local state is)
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
54 # CME = 0x20 # Command Error
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
55 # EXE = 0x10 # Execution Error
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
56 # DDE = 0x08 # Device Dependant Error
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
57 # QYE = 0x04 # QuerY Error (attempt to read data while Output Queue is
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
58 # # empty, or data in the OQ was lost)
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
59 # RQC = 0x02 # Request Control: tell the CiC that the device wants to
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
60 # # become the CiC
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
61 # OPC = 0x01 # Operation Complete: device has completed any pending
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
62 # # operation (ready to accept new commands). This bit is
a04bea92c509 some code refactoring and several improvements in gpib_plotter (should be more robust & quicker)
David Douard <david.douard@logilab.fr>
parents: 9
diff changeset
63 # # generated in response to a OPC command.
9
3b50c46fca56 several updates to the gpib module
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
64

mercurial