Mon, 04 Jun 2018 22:28:05 +0200
[plotter] add a --mockup option to the demo main function
63
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
1 | .. -*- coding: utf-8 -*- |
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
2 | |
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
3 | ============= |
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
4 | Description |
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
5 | ============= |
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
6 | |
73
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
7 | The code is organized in 2 layers; a low-level communication layer, |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
8 | and a highter level which allows to describe precisely a GPIB device, |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
9 | communicate asynchronously with it, etc. |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
10 | |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
11 | Low level |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
12 | ========= |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
13 | |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
14 | The low level communication process is managed by the module |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
15 | ``pygpibtoolkit.prologix``, in which there is a class names ``GPIB`` |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
16 | that knows how to initialize the GPIB device, send commands and |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
17 | receive data from the bus, perform GPIB polls, etc. |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
18 | |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
19 | Example:: |
63
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
20 | |
73
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
21 | from pygpibtoolkit.prologix import GPIB |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
22 | cnx = GPIB() # by default, it is the controller in charge |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
23 | idn = cnx.send_command("*IDN?", 12) # sends the idn command to device at GPIBaddress 12 |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
24 | print idn |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
25 | |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
26 | cnx.set_address(12) # we will talk to this device 12 for a while |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
27 | datablock = cnx.send_command('DDBN') |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
28 | |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
29 | if cnx.check_srq(): |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
30 | print "A Service Request has been sent" |
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
31 | |
74
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
32 | But that's basically it. You can send commands to devices, wait for an |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
33 | answer, check SRQ line. |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
34 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
35 | High level |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
36 | ========== |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
37 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
38 | The high level API is organized around a GPIB controller class |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
39 | (``pygpibtoolkit.gpibcontroller.GPIBController``) which is responsible |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
40 | for managing every connection stuff. It will run a thread responsible |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
41 | for communication processes, will regularly check SRQ line (and |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
42 | respond accordingly, with ability to register callbacks), etc. |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
43 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
44 | It will also provide a ``send_command`` method, but this latter will |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
45 | have a much higher means: the operation can be done synchronously or |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
46 | asynchronously (with a callback to call upon completion), etc. |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
47 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
48 | It will also hold device managers for found devices on the GPIB bus. |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
49 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
50 | Each device manager is a class responsible for communication |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
51 | specifically with a specified device. It will provide (if the device |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
52 | manager has been written) simple ways to send GPIB commands of the |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
53 | device; every GPIB command will be presented as a method of the |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
54 | manager. |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
55 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
56 | Talking with a device can then be as simple as:: |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
57 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
58 | from pygpibtoolkit.gpibcontroller import GPIBController |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
59 | c = GPIBController() |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
60 | devices = c.detect_devices() |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
61 | # devices is a dict which keys are the GPIB addresses |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
62 | # and values, the managers for each device |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
63 | hp3562 = devices[3] |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
64 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
65 | # ok, let's tell the HP3562 to put channel 1 in AC couplig mode, |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
66 | hp3562.C1AC("AC") |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
67 | # and put it in linear measure mode |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
68 | hp3562.LNRS() #EMEAS("LINEAR RES") |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
69 | # and Freq response mode |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
70 | hp3562.FRQR() |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
71 | # set span freq and center freq |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
72 | hp3562.FRS("10khz") |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
73 | hp3562.CF("7212hz") |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
74 | # then get the resulting trace data block |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
75 | trace = hp3562.DDBN() |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
76 | # which we can easily display |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
77 | header, data = hp3562.decode_trace(trace) |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
78 | import pylab |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
79 | pylab.plot(data) |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
80 | pylab.show() |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
81 | |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
82 | # ok, let's stop gracefully our cession |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
83 | c.stop() |
62d7957b3aa8
started developer doc
David Douard <david.douard@logilab.fr>
parents:
73
diff
changeset
|
84 | |
63
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
85 | |
1c0d92f95115
added doc (almost empty) files
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
86 | |
73
2645ef311424
small cleanups and doc update
David Douard <david.douard@logilab.fr>
parents:
63
diff
changeset
|
87 |