Skip to content

Commit

Permalink
DOC #940 convert the blocking call to st.wait()
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Mar 18, 2024
1 parent 7757f85 commit 7bacb1b
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions docs/source/examples/de_sscan.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -79,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -115,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -176,8 +176,13 @@
"background) reports when the scan has finished or times out. We define an inner\n",
"`watch_the_button()` function to detect when the button goes from `1` to `0`\n",
"(the scan stops). We setup a subscription (*after* we start the move) to\n",
"monitor the button value and respond immediately. We wait for the status object\n",
"to finish with `st.wait()`. Finally, we cancel the monitor of the button."
"monitor the button value and respond immediately. \n",
"\n",
"We wait for the status object to finish with `st.wait()`. In a bluesky plan,\n",
"we'll need to use `apstools.plans.run_blocking_function` with `st.wait()` since\n",
"it is a blocking function.\n",
"\n",
"Finally, we cancel the monitor of the button."
]
},
{
Expand All @@ -186,6 +191,7 @@
"metadata": {},
"outputs": [],
"source": [
"from apstools.plans import run_blocking_function\n",
"from ophyd.status import Status\n",
"\n",
"def run_sscan():\n",
Expand All @@ -194,11 +200,11 @@
" def watch_the_button(old_value, value, **kwargs):\n",
" if old_value == 1 and value == 0:\n",
" st.set_finished()\n",
" scan_button.clear_sub(watch_the_button)\n",
"\n",
" yield from bps.mv(scan_button, 1)\n",
" scan_button.subscribe(watch_the_button)\n",
" st.wait()\n",
" scan_button.unsubscribe_all()"
" yield from run_blocking_function(st.wait)"
]
},
{
Expand Down Expand Up @@ -234,7 +240,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -246,19 +252,19 @@
"def run_sscan():\n",
" st = Status(timeout=20)\n",
"\n",
" def watch_the_button(old_value, value, **kwargs):\n",
" def watch_execute_scan(old_value, value, **kwargs):\n",
" if old_value == 1 and value == 0:\n",
" st.set_finished()\n",
" scan1.execute_scan.clear_sub(watch_execute_scan)\n",
"\n",
" yield from bps.mv(scan1.execute_scan, 1)\n",
" scan1.execute_scan.subscribe(watch_the_button)\n",
" st.wait()\n",
" scan1.execute_scan.unsubscribe_all()"
" scan1.execute_scan.subscribe(watch_execute_scan)\n",
" yield from run_blocking_function(st.wait)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 28,
"metadata": {},
"outputs": [
{
Expand All @@ -267,7 +273,7 @@
"()"
]
},
"execution_count": 8,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -360,9 +366,12 @@
"We can supply the count time per point and scan range parameters as arguments to\n",
"the setup. After setting the counting time for the scaler, the next step in the\n",
"setup is to clear any existing configuration of `scan1` using its `reset()`\n",
"method. In a bluesky plan, we'll need to use\n",
"`apstools.plans.run_blocking_function` with that `reset()` method. Finally,\n",
"we'll setup `scan1` with the EPICS PV names to be used."
"method.\n",
"\n",
"In a bluesky plan, we'll need to use `apstools.plans.run_blocking_function` with\n",
"that `reset()` method.\n",
"\n",
"Finally, we'll setup `scan1` with the EPICS PV names to be used."
]
},
{
Expand All @@ -371,8 +380,6 @@
"metadata": {},
"outputs": [],
"source": [
"from apstools.plans import run_blocking_function\n",
"\n",
"def setup_scan1(start, finish, npts, ct=1):\n",
" yield from bps.mv(scaler1.preset_time, ct) # counting time/point\n",
" yield from run_blocking_function(scan1.reset)\n",
Expand Down

0 comments on commit 7bacb1b

Please sign in to comment.