|
2 | 2 | from scan import * |
3 | 3 |
|
4 | 4 | client = ScanClient('localhost') |
5 | | -print client |
| 5 | +print(client) |
6 | 6 |
|
7 | | -print client.serverInfo() |
| 7 | +print(client.serverInfo()) |
8 | 8 |
|
9 | 9 | # Assemble commands for a scan |
10 | 10 | # Much more on that later... |
11 | 11 | cmds = [ Comment('Hello'), Set('motor_x', 10) ] |
12 | 12 |
|
13 | 13 | # Optionally, request a simulation that shows |
14 | 14 | # how 'Include' and 'Loop' commands get expanded. |
15 | | -simulation = client.simulate(cmds) |
16 | | -print simulation |
| 15 | +info = client.simulate(cmds) |
| 16 | +print(info['simulation']) |
17 | 17 |
|
18 | 18 | # Submit scan for execution |
19 | 19 | id = client.submit(cmds, 'My First Scan') |
20 | | -print id |
| 20 | +print(id) |
21 | 21 |
|
22 | 22 | # Fetch information about scan |
23 | 23 | info = client.scanInfo(id) |
24 | | -print info |
| 24 | +print(info) |
25 | 25 |
|
26 | 26 | # Could poll scanInfo until info.isDone(). |
27 | 27 | # Shortcut: |
28 | 28 | info = client.waitUntilDone(id) |
29 | | -print info |
| 29 | +print(info) |
30 | 30 |
|
31 | 31 | # A submitted scan can be paused.. |
32 | | -id = client.submit(cmds, 'Not sure about this one') |
| 32 | +id = client.submit([ Delay(5) ], 'Not sure about this one') |
33 | 33 |
|
34 | 34 | client.pause(id) |
35 | | -print client.scanInfo(id) |
| 35 | +print(client.scanInfo(id)) |
36 | 36 |
|
37 | 37 | client.resume(id) |
38 | | -print client.scanInfo(id) |
| 38 | +print(client.scanInfo(id)) |
39 | 39 |
|
40 | 40 | # .. or even aborted & deleted |
41 | 41 | client.abort(id) |
42 | | -print client.scanInfo(id) |
| 42 | +print(client.scanInfo(id)) |
43 | 43 |
|
44 | | -print "Before deleting scan %d:" % id, [ str(info) for info in client.scanInfos() ] |
| 44 | +print("Before deleting scan %d:" % id) |
| 45 | +for info in client.scanInfos(): |
| 46 | + print(info) |
45 | 47 | client.delete(id) |
46 | | -print "After deleting scan %d:" % id, [ str(info) for info in client.scanInfos() ] |
| 48 | +print("After deleting scan %d:" % id) |
| 49 | +for info in client.scanInfos(): |
| 50 | + print(info) |
47 | 51 |
|
48 | | -# In extreme cases, it is possible to change a running scan |
| 52 | +# To a limited extend, it is possible to change a running scan: |
| 53 | +# Parameters of commands that have not been executed can be adjusted |
49 | 54 | id = client.submit([ Delay(5), Set('motor_x', 10) ], 'Changing...') |
50 | 55 | client.pause(id) |
51 | 56 | # Want to set 'motor_x' to 5 instead of 10 |
|
55 | 60 |
|
56 | 61 | try: |
57 | 62 | client.waitUntilDone(id) |
58 | | -except Exception, e: |
59 | | - print "Waiting for an aborted scan will result in an exception: ", e |
| 63 | +except Exception as e: |
| 64 | + print("Waiting for an aborted scan will result in an exception: ", e) |
60 | 65 |
|
61 | 66 | try: |
62 | 67 | # This scan will time out |
63 | 68 | id = client.submit( [ Wait("motor_x", 60, timeout=1)], "Timeout Test") |
64 | 69 | client.waitUntilDone(id) |
65 | | -except Exception, e: |
66 | | - print "Waiting for a failed scan will result in an exception: ", e |
| 70 | +except Exception as e: |
| 71 | + print("Waiting for a failed scan will result in an exception: ", e) |
67 | 72 |
|
68 | 73 | # Log data during scan |
69 | 74 | cmds = [ Loop('motor_x', 1, 10, 1, |
|
79 | 84 | ] |
80 | 85 | id = client.submit(cmds, 'Data Demo') |
81 | 86 | info = client.waitUntilDone(id) |
82 | | -print "Number of log calls: %d" % client.lastSerial(id) |
| 87 | +print("Number of log calls: %d" % client.lastSerial(id)) |
83 | 88 |
|
84 | 89 | # Fetch data |
85 | 90 | data = client.getData(id) |
86 | 91 |
|
87 | 92 | # Create table for motor_x and neutrons |
88 | 93 | table = createTable(data, 'motor_x', 'neutrons') |
89 | | -print "Positions: ", table[0] |
90 | | -print "Counts : ", table[1] |
| 94 | +print("Positions: ", table[0]) |
| 95 | +print("Counts : ", table[1]) |
91 | 96 | for (pos, count) in zip(*table): |
92 | | - print "Counts at motor position %g: %g" % (pos, count) |
| 97 | + print("Counts at motor position %g: %g" % (pos, count)) |
93 | 98 |
|
94 | 99 | # Could plot this with numpy/scipy: plot(table[0], table[1]) etc. |
95 | 100 |
|
96 | | -# TODO get commands back from server |
97 | | - |
98 | 101 | # Remove information for all completed scans |
99 | 102 | client.clear() |
0 commit comments