Thu, 28 Feb 2008 18:16:52 +0100
Added commands for HP356X devices. Added STA, IS and AS as commands (instead of constants).
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
1 | """ |
14
07e2cbf140df
several improvements; add an internal state reader
David Douard <david.douard@logilab.fr>
parents:
13
diff
changeset
|
2 | prologix |
13
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 defining a communication object to talk to Prologix USB-GPIB controler. |
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 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
8 | import serial |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
9 | import time |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
10 | |
40
1bbea188a7e5
refactoring: moved everything of the library to a "pygpibtoolkit" module.
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
11 | from pygpibtoolkit import pygpib |
1bbea188a7e5
refactoring: moved everything of the library to a "pygpibtoolkit" module.
David Douard <david.douard@logilab.fr>
parents:
35
diff
changeset
|
12 | from pygpibtoolkit.pygpib import ConnectionError |
13
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 | GPIB_CONTROLLER = 1 |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
15 | GPIB_DEVICE = 0 |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
16 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
17 | class GPIB(object): |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
18 | _retries = 15 |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
19 | def __init__(self, device="/dev/ttyUSB0", baudrate=115200, timeout=0.1, |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
20 | address=0, mode=1): |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
21 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
22 | Create a new GPIB controller for the Prologix USB-GPIB device |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
23 | located on serial device 'device'. |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
24 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
25 | self._cnx = serial.Serial(port=device, baudrate=baudrate, timeout=timeout) |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
26 | self._timeout = timeout |
56
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
27 | |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
28 | try: |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
29 | res = self._cnx.readlines() |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
30 | if res: # empty evetual read buffer |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
31 | print "there where pending stuffs in buffer", repr(res) |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
32 | self.set_mode(mode) |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
33 | self.set_address(address) |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
34 | self._set_cmd('auto', 0) |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
35 | except Exception, e: |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
36 | print "Humm, something went wrong", e |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
37 | |
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:
40
diff
changeset
|
38 | def set_address(self, address, check=True): |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
39 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
40 | Set the address of the GPIB device: |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
41 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
42 | - if the device is the Controller In Charge, this is the |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
43 | address of the device commands are sent to, |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
44 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
45 | - if the device is in GPIB_DEVICE mode, this is its address. |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
46 | """ |
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:
40
diff
changeset
|
47 | self._set_cmd('addr', address, check) |
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:
40
diff
changeset
|
48 | self._address = address |
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:
40
diff
changeset
|
49 | #self._set_cmd('auto', 0) |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
50 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
51 | def set_mode(self, mode): |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
52 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
53 | Set GPIB device mode to 'mode': |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
54 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
55 | - GPIB_CONTROLLER: set the device as the Controller In Charge |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
56 | on the GPIB bus |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
57 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
58 | - GPIB_DEVICE: set the device as a standard GPIB device on the |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
59 | bus. |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
60 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
61 | self._set_cmd('mode', mode) |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
62 | self._mode = mode |
56
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
63 | if self._mode: |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
64 | self._cnx.write('++ifc\r') |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
65 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
66 | def set_controller(self): |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
67 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
68 | Set GPIB device the Controller In Charge on the GPIB bus. |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
69 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
70 | self.set_mode(1) |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
71 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
72 | def set_device(self): |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
73 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
74 | Set the GPIB device as a simple device on the GPIB bus. |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
75 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
76 | self.set_mode(0) |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
77 | |
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:
40
diff
changeset
|
78 | def send_command(self, cmd, address=None): |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
79 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
80 | Send the specified GPIB command on the bus (must be the CIC), |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
81 | and read the answer. |
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:
40
diff
changeset
|
82 | Eventually, set the addressed device first. |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
83 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
84 | assert self._mode == 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:
40
diff
changeset
|
85 | if address is not 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:
40
diff
changeset
|
86 | self.set_address(address) |
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:
40
diff
changeset
|
87 | self._cnx.write(cmd+';\r') |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
88 | time.sleep(self._timeout) # required? |
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:
40
diff
changeset
|
89 | return self.read_eoi() |
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:
40
diff
changeset
|
90 | |
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:
40
diff
changeset
|
91 | def read_eoi(self, address=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:
40
diff
changeset
|
92 | """ |
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:
40
diff
changeset
|
93 | Read the HPIB buffer from device, till EOI is performed, or timeout. |
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:
40
diff
changeset
|
94 | """ |
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:
40
diff
changeset
|
95 | if address is not 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:
40
diff
changeset
|
96 | self.set_address(address) |
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:
40
diff
changeset
|
97 | self._cnx.write('++read eoi\r') # idem |
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:
40
diff
changeset
|
98 | ret = "" |
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:
40
diff
changeset
|
99 | i = 0 |
56
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
100 | while not ret.endswith('\r\n') and i<3: |
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:
40
diff
changeset
|
101 | ret += ''.join(self._cnx.readlines()) |
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:
40
diff
changeset
|
102 | time.sleep(self._timeout) # required? |
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:
40
diff
changeset
|
103 | i += 1 |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
104 | return ''.join(ret) |
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:
40
diff
changeset
|
105 | |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
106 | def check_srq(self): |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
107 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
108 | Check the SRQ line |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
109 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
110 | assert self._mode == 1, "must be the Controller In Charge" |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
111 | self._cnx.write('++srq\r') |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
112 | ret = self._cnx.readline().strip() |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
113 | if ret: |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
114 | return bool(int(ret)) |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
115 | return None |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
116 | |
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:
40
diff
changeset
|
117 | def poll(self, addresses=None): |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
118 | """ |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
119 | Poll every address, and return a dictionnary |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
120 | {add: status, ...} |
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:
40
diff
changeset
|
121 | """ |
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:
40
diff
changeset
|
122 | assert self._mode == 1, "must be the Controller In Charge" |
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:
40
diff
changeset
|
123 | only_one = False |
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:
40
diff
changeset
|
124 | if addresses 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:
40
diff
changeset
|
125 | addresses = range(31) |
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:
40
diff
changeset
|
126 | if not isinstance(addresses, (list, tuple)): |
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:
40
diff
changeset
|
127 | addresses = [addresses] |
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:
40
diff
changeset
|
128 | only_one = True |
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:
40
diff
changeset
|
129 | if len(addresses)==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:
40
diff
changeset
|
130 | return 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:
40
diff
changeset
|
131 | |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
132 | dico = {} |
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:
40
diff
changeset
|
133 | for add in addresses: |
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:
40
diff
changeset
|
134 | self._cnx.write('++spoll %d\r'%add) |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
135 | ret = self._cnx.readline().strip() |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
136 | if ret: |
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:
40
diff
changeset
|
137 | dico[add] = int(ret) |
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:
40
diff
changeset
|
138 | time.sleep(0.3) # need to wait at least 150ms (not enough on prologix) |
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:
40
diff
changeset
|
139 | self.set_address(self._address) |
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:
40
diff
changeset
|
140 | if only_one: |
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:
40
diff
changeset
|
141 | return dico.values()[0] |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
142 | return dico |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
143 | |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
144 | def _read(self): |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
145 | for i in range(self._retries): |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
146 | rdata = self._cnx.readline() |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
147 | if rdata.strip() != "": |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
148 | break |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
149 | time.sleep(self._timeout) |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
150 | return rdata |
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
151 | |
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:
40
diff
changeset
|
152 | def _set_cmd(self, cmd, value, check=True): |
13
78e3e839658b
some forgotten added files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
153 | self._cnx.write('++%s %d\r'%(cmd, value)) |
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:
40
diff
changeset
|
154 | if check: |
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:
40
diff
changeset
|
155 | self._cnx.write('++%s\r'%(cmd)) |
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:
40
diff
changeset
|
156 | rval = self._read().strip() |
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:
40
diff
changeset
|
157 | if not rval.isdigit() or int(rval) != value: |
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:
40
diff
changeset
|
158 | raise ConnectionError("Can't set GPIB %s to %s [ret=%s]"%(cmd, value, repr(rval))) |
56
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
159 | |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
160 | def reset(self): |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
161 | """ |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
162 | Perform a reset of the USB device |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
163 | |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
164 | """ |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
165 | print "Resetting GPIB controller" |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
166 | self._cnx.write('++rst\r') |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
167 | print "Must wait for 5 seconds" |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
168 | time.sleep(5) |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
169 | |
9573558f9191
Try to be a little more robust when instanciating the GPIB class (serial connector)
David Douard <david.douard@logilab.fr>
parents:
53
diff
changeset
|
170 |