11'''
22This is an example how to use PyScanClient library to perform a 2D scan using table scan, and take multiple samples
33at each point.
4- It needs an example EPICS database, simulation.db, which could be found at:
5- https://github.com/ControlSystemStudio/cs-studio/blob/master/applications/plugins/org.csstudio.scan/examples/
6- And it assumes the server running on localhost at port 4810.
7-
84
95It does the following:
10- - set pv 'motor_x' to 1, which means to open a shutter, and wait until finish.
116 - loop pv 'motor_x' from 1 to 5 with stepping size = 1 and wait until finish. at each step:
127 - loop pv 'motor_y' from 1 to 3 with stepping size = 1, and wait until finish. at each step:
138 - wait for 1 second
149 - log pv 'motor_x', 'motor_y' and 'neutrons'
15- - set pv 'motor_x' to original place
16- - set pv 'motor_y' to original place
17- - get logged data back
18- - create a table for the results
19- - clear scan server
2010
21- It does not demo:
22- - read back and its tolerance to ensure
11+ It uses the table's pre and post options
12+ - set pv 'motor_x' to 1 to simulate openint a shutter, and wait until finish.
2313
24- Created on Apr 17, 2015
25-
26- @author: shen
14+ - set pv 'motor_x' to original place
15+ - set pv 'motor_y' to original place
16+
17+ @author: shen, Kay Kasemir
2718'''
2819
2920from scan .client .scanclient import ScanClient
3324from scan .client .logdata import createTable
3425
3526from scan .util .scan_settings import ScanSettings , setScanSettings
36- # Note how we replace the original Set() and Wait() commands with those that utilize ScanSettings
27+ # Note how we replace the original Set() with one that utilizes ScanSettings
3728from scan .util .scan_settings import SettingsBasedSet as Set
3829
3930class LocalScanSettings (ScanSettings ):
@@ -50,72 +41,66 @@ def __init__(self):
5041# return device_name + ".RBV"
5142# return device_name
5243
53- if __name__ == '__main__' :
54- orig_motor_x = 0
55- orig_motor_y = 0
56-
57- # Custom settings configure the TableScan
58- setScanSettings (LocalScanSettings ())
59- # Create table scan command
60- # list all scan parameters
61- table = TableScan (['motor_x' , 'motor_y' , 'loc://i(0)' , "Wait For" , "Value" ],
62- [ [ 1 , 1 , 1 , 'Seconds' , 1 ],
63- [ '' , '' , 2 , 'Seconds' , 1 ],
64- [ '' , 2 , 1 , 'Seconds' , 1 ],
65- [ '' , '' , 2 , 'Seconds' , 1 ],
66- [ '' , 3 , 1 , 'Seconds' , 1 ],
67- [ '' , '' , 2 , 'Seconds' , 1 ],
68- [ 2 , 1 , 1 , 'Seconds' , 1 ],
69- [ '' , '' , 2 , 'Seconds' , 1 ],
70- [ '' , 2 , 1 , 'Seconds' , 1 ],
71- [ '' , '' , 2 , 'Seconds' , 1 ],
72- [ '' , 3 , 1 , 'Seconds' , 1 ],
73- [ '' , '' , 2 , 'Seconds' , 1 ],
74- [ 3 , 1 , 1 , 'Seconds' , 1 ],
75- [ '' , '' , 2 , 'Seconds' , 1 ],
76- [ '' , 2 , 1 , 'Seconds' , 1 ],
77- [ '' , '' , 2 , 'Seconds' , 1 ],
78- [ '' , 3 , 1 , 'Seconds' , 1 ],
79- [ '' , '' , 2 , 'Seconds' , 1 ],
80- [ 4 , 1 , 1 , 'Seconds' , 1 ],
81- [ '' , '' , 2 , 'Seconds' , 1 ],
82- [ '' , 2 , 1 , 'Seconds' , 1 ],
83- [ '' , '' , 2 , 'Seconds' , 1 ],
84- [ '' , 3 , 1 , 'Seconds' , 1 ],
85- [ '' , '' , 2 , 'Seconds' , 1 ],
86- [ 5 , 1 , 1 , 'Seconds' , 1 ],
87- [ '' , '' , 2 , 'Seconds' , 1 ],
88- [ '' , 2 , 1 , 'Seconds' , 1 ],
89- [ '' , '' , 2 , 'Seconds' , 1 ],
90- [ '' , 3 , 1 , 'Seconds' , 1 ],
91- [ '' , '' , 2 , 'Seconds' , 1 ],],
92- pre = Set ('motor_x' , 1 , completion = True ),
93- post = [Set ('motor_x' , orig_motor_x , completion = True ),
94- Set ('motor_y' , orig_motor_y , completion = True ),],
95- log_always = ['neutrons' , 'setpoint' ]
96- )
97- cmds = table .createScan ()
44+ orig_motor_x = 0
45+ orig_motor_y = 0
46+
47+ # Custom settings configure the TableScan
48+ setScanSettings (LocalScanSettings ())
49+ # Create table scan command
50+ # list all scan parameters
51+ table = TableScan (['motor_x' , 'motor_y' , 'loc://i(0)' , "Wait For" , "Value" ],
52+ [ [ 1 , 1 , 1 , 'Seconds' , 1 ],
53+ [ '' , '' , 2 , 'Seconds' , 1 ],
54+ [ '' , 2 , 1 , 'Seconds' , 1 ],
55+ [ '' , '' , 2 , 'Seconds' , 1 ],
56+ [ '' , 3 , 1 , 'Seconds' , 1 ],
57+ [ '' , '' , 2 , 'Seconds' , 1 ],
58+ [ 2 , 1 , 1 , 'Seconds' , 1 ],
59+ [ '' , '' , 2 , 'Seconds' , 1 ],
60+ [ '' , 2 , 1 , 'Seconds' , 1 ],
61+ [ '' , '' , 2 , 'Seconds' , 1 ],
62+ [ '' , 3 , 1 , 'Seconds' , 1 ],
63+ [ '' , '' , 2 , 'Seconds' , 1 ],
64+ [ 3 , 1 , 1 , 'Seconds' , 1 ],
65+ [ '' , '' , 2 , 'Seconds' , 1 ],
66+ [ '' , 2 , 1 , 'Seconds' , 1 ],
67+ [ '' , '' , 2 , 'Seconds' , 1 ],
68+ [ '' , 3 , 1 , 'Seconds' , 1 ],
69+ [ '' , '' , 2 , 'Seconds' , 1 ],
70+ [ 4 , 1 , 1 , 'Seconds' , 1 ],
71+ [ '' , '' , 2 , 'Seconds' , 1 ],
72+ [ '' , 2 , 1 , 'Seconds' , 1 ],
73+ [ '' , '' , 2 , 'Seconds' , 1 ],
74+ [ '' , 3 , 1 , 'Seconds' , 1 ],
75+ [ '' , '' , 2 , 'Seconds' , 1 ],
76+ [ 5 , 1 , 1 , 'Seconds' , 1 ],
77+ [ '' , '' , 2 , 'Seconds' , 1 ],
78+ [ '' , 2 , 1 , 'Seconds' , 1 ],
79+ [ '' , '' , 2 , 'Seconds' , 1 ],
80+ [ '' , 3 , 1 , 'Seconds' , 1 ],
81+ [ '' , '' , 2 , 'Seconds' , 1 ],],
82+ pre = Set ('motor_x' , 1 , completion = True ),
83+ post = [Set ('motor_x' , orig_motor_x , completion = True ),
84+ Set ('motor_y' , orig_motor_y , completion = True ),],
85+ log_always = ['neutrons' , 'setpoint' ]
86+ )
87+ cmds = table .createScan ()
9888
99- try :
100- client = ScanClient ('localhost' , 4810 )
101- scid = client .submit (cmds , name = "2D table scan example" )
102- client .waitUntilDone (scid )
103- print "Number of log calls: %d" % client .lastSerial (scid )
104-
105- # get raw data back as a Python dict
106- data = client .getData (scid )
107- print data
108-
109- # Create table for motor_x, motor_y and neutrons
110- table = createTable (data , 'motor_x' , 'motor_y' , 'neutrons' , 'setpoint' )
111- print "Position X: " , table [0 ]
112- print "Position Y: " , table [1 ]
113- print "Counts : " , table [2 ]
114- print "Setpoint : " , table [3 ]
115-
116- # Remove specific scan task
117- client .delete (scid )
118- # or Remove information for all completed scans
119- client .clear ()
120- except :
121- raise
89+ client = ScanClient ('localhost' , 4810 )
90+ scid = client .submit (cmds , name = "2D table scan example" )
91+ client .waitUntilDone (scid )
92+
93+ # get raw data back as a Python dict
94+ data = client .getData (scid )
95+
96+ # Create table for motor_x, motor_y and neutrons
97+ table = createTable (data , 'motor_x' , 'motor_y' , 'neutrons' , 'setpoint' )
98+ print ("Position X: " , table [0 ])
99+ print ("Position Y: " , table [1 ])
100+ print ("Counts : " , table [2 ])
101+ print ("Setpoint : " , table [3 ])
102+
103+ # Remove specific scan task
104+ #client.delete(scid)
105+ # or Remove information for all completed scans
106+ #client.clear()
0 commit comments