plotter/gpib.py

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

mercurial