Skip to content

Commit 7f6daef

Browse files
author
Kay Kasemir (ky9)
committed
python3, tweak
1 parent 8b8a38b commit 7f6daef

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

example/client1.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,55 @@
22
from scan import *
33

44
client = ScanClient('localhost')
5-
print client
5+
print(client)
66

7-
print client.serverInfo()
7+
print(client.serverInfo())
88

99
# Assemble commands for a scan
1010
# Much more on that later...
1111
cmds = [ Comment('Hello'), Set('motor_x', 10) ]
1212

1313
# Optionally, request a simulation that shows
1414
# how 'Include' and 'Loop' commands get expanded.
15-
simulation = client.simulate(cmds)
16-
print simulation
15+
info = client.simulate(cmds)
16+
print(info['simulation'])
1717

1818
# Submit scan for execution
1919
id = client.submit(cmds, 'My First Scan')
20-
print id
20+
print(id)
2121

2222
# Fetch information about scan
2323
info = client.scanInfo(id)
24-
print info
24+
print(info)
2525

2626
# Could poll scanInfo until info.isDone().
2727
# Shortcut:
2828
info = client.waitUntilDone(id)
29-
print info
29+
print(info)
3030

3131
# 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')
3333

3434
client.pause(id)
35-
print client.scanInfo(id)
35+
print(client.scanInfo(id))
3636

3737
client.resume(id)
38-
print client.scanInfo(id)
38+
print(client.scanInfo(id))
3939

4040
# .. or even aborted & deleted
4141
client.abort(id)
42-
print client.scanInfo(id)
42+
print(client.scanInfo(id))
4343

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)
4547
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)
4751

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
4954
id = client.submit([ Delay(5), Set('motor_x', 10) ], 'Changing...')
5055
client.pause(id)
5156
# Want to set 'motor_x' to 5 instead of 10
@@ -55,15 +60,15 @@
5560

5661
try:
5762
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)
6065

6166
try:
6267
# This scan will time out
6368
id = client.submit( [ Wait("motor_x", 60, timeout=1)], "Timeout Test")
6469
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)
6772

6873
# Log data during scan
6974
cmds = [ Loop('motor_x', 1, 10, 1,
@@ -79,21 +84,19 @@
7984
]
8085
id = client.submit(cmds, 'Data Demo')
8186
info = client.waitUntilDone(id)
82-
print "Number of log calls: %d" % client.lastSerial(id)
87+
print("Number of log calls: %d" % client.lastSerial(id))
8388

8489
# Fetch data
8590
data = client.getData(id)
8691

8792
# Create table for motor_x and neutrons
8893
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])
9196
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))
9398

9499
# Could plot this with numpy/scipy: plot(table[0], table[1]) etc.
95100

96-
# TODO get commands back from server
97-
98101
# Remove information for all completed scans
99102
client.clear()

example/opi/1_BeamLine.bob

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!--Saved on 2024-03-22 14:38:09 by ky9-->
2+
<!--Saved on 2024-03-26 11:44:53 by ky9-->
33
<display version="2.0.0">
44
<width>720</width>
55
<height>380</height>
@@ -415,4 +415,21 @@ $(pv_value)</tooltip>
415415
<limits_from_pv>false</limits_from_pv>
416416
<maximum>1.0</maximum>
417417
</widget>
418+
<widget type="label" version="2.0.0">
419+
<name>Label_6</name>
420+
<text>Detector</text>
421+
<x>408</x>
422+
<y>12</y>
423+
<width>72</width>
424+
<height>16</height>
425+
<horizontal_alignment>1</horizontal_alignment>
426+
<vertical_alignment>1</vertical_alignment>
427+
<auto_size>true</auto_size>
428+
<actions>
429+
</actions>
430+
<border_color>
431+
<color red="0" green="128" blue="255">
432+
</color>
433+
</border_color>
434+
</widget>
418435
</display>

0 commit comments

Comments
 (0)