{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Basic, Part B: Motor and Move\n", "\n", "From *APS Python Training for Bluesky Data Acquisition*.\n", "\n", "**Objective**\n", "\n", "Work with an EPICS positioning motor (for precise positioning) in [Bluesky](http://blueskyproject.io/bluesky/) and [related tools](http://blueskyproject.io/).\n", "\n", "First, we'll connect with an EPICS motor (using [ophyd](http://blueskyproject.io/ophyd/)), and then use the Bluesky software to scan the motor (with the scaler from [basic_scaler](_basic_a.ipynb)).\n", "\n", "Load `ophyd` device support for the `EpicsMotor` and connect with one EPICS motor channel. We have a synApps XXX-style IOC with the prefix `gp:`. It has a scaler, 16 soft channel motors, and some other support we'll ignore in this lesson.\n", "\n", "**note**: This tutorial expects to find an EPICS IOC on the local network configured as a synApps `xxx` [IOC](https://github.com/epics-modules/xxx) with prefix `gp:`.\n", "\n", "
\n", "A docker container is available to provide this IOC. See this URL for instructions: https://github.com/prjemian/epics-docker/tree/main/v1.1/n5_custom_synApps/README.md\n", "
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from ophyd import EpicsMotor\n", "m1 = EpicsMotor(\"gp:m1\", name=\"m1\")\n", "m1.wait_for_connection()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Show the current value of the motor (that's the `.RBV` field, in case you were interested)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "m1.position = 1.0\n" ] } ], "source": [ "print(f\"{m1.position = }\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Connect the scaler (as was done in the [basic_scaler](_basic_a.ipynb) lesson). Define some of the channel names and clear out others." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from ophyd.scaler import ScalerCH\n", "scaler = ScalerCH(\"gp:scaler1\", name=\"scaler\")\n", "scaler.wait_for_connection()\n", "\n", "# Since there are no detectors actually connected to this scaler,\n", "# we can change names at our choice. A real scaler will have\n", "# detectors connected to specific channels and we should not modify\n", "# these names without regard to how signals are physically connected.\n", "scaler.channels.chan01.chname.put(\"clock\")\n", "scaler.channels.chan02.chname.put(\"I0\")\n", "scaler.channels.chan03.chname.put(\"scint\")\n", "scaler.channels.chan04.chname.put(\"\")\n", "scaler.channels.chan05.chname.put(\"\")\n", "scaler.channels.chan06.chname.put(\"\")\n", "scaler.channels.chan07.chname.put(\"\")\n", "scaler.channels.chan08.chname.put(\"\")\n", "scaler.channels.chan09.chname.put(\"\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Use only the channels with EPICS names, those are the *interesting* channels." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('clock', {'value': 16000000.0, 'timestamp': 1684257260.223683}),\n", " ('I0', {'value': 7.0, 'timestamp': 1684257260.223683}),\n", " ('scint', {'value': 8.0, 'timestamp': 1684257260.223683}),\n", " ('scaler_time', {'value': 1.6, 'timestamp': 1684257260.223683})])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scaler.select_channels(None)\n", "scaler.read()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Create a RunEngine but do not connect it with a data collection strategy. That will come in the next lessons." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from bluesky import RunEngine\n", "import bluesky.plans as bp\n", "RE = RunEngine({})" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Run a step scan using the motor and the scaler." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('588b3330-2fc0-48db-8943-0383db1d22f0',)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RE(bp.scan([scaler], m1, -1, 1, 5))" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Ah, yes. Nothing to see here since we did not setup anything to receive the *documents* from the RunEngine. Here's the basic callback from the [basic_scaler](_basic_a.ipynb) lesson." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import pprint\n", "def myCallback(key, doc):\n", " print()\n", " print(key, len(doc))\n", " pprint.pprint(doc)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Repeat the same scan but handle the document stream with `myCallback()`." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "start 15\n", "{'detectors': ['scaler'],\n", " 'hints': {'dimensions': [(['m1'], 'primary')]},\n", " 'motors': ('m1',),\n", " 'num_intervals': 4,\n", " 'num_points': 5,\n", " 'plan_args': {'args': [\"EpicsMotor(prefix='gp:m1', name='m1', \"\n", " 'settle_time=0.0, timeout=None, '\n", " \"read_attrs=['user_readback', 'user_setpoint'], \"\n", " \"configuration_attrs=['user_offset', \"\n", " \"'user_offset_dir', 'velocity', 'acceleration', \"\n", " \"'motor_egu'])\",\n", " -1,\n", " 1],\n", " 'detectors': [\"ScalerCH(prefix='gp:scaler1', name='scaler', \"\n", " \"read_attrs=['channels', 'channels.chan01', \"\n", " \"'channels.chan01.s', 'channels.chan02', \"\n", " \"'channels.chan02.s', 'channels.chan03', \"\n", " \"'channels.chan03.s', 'time'], \"\n", " \"configuration_attrs=['channels', \"\n", " \"'channels.chan01', 'channels.chan01.chname', \"\n", " \"'channels.chan01.preset', \"\n", " \"'channels.chan01.gate', 'channels.chan02', \"\n", " \"'channels.chan02.chname', \"\n", " \"'channels.chan02.preset', \"\n", " \"'channels.chan02.gate', 'channels.chan03', \"\n", " \"'channels.chan03.chname', \"\n", " \"'channels.chan03.preset', \"\n", " \"'channels.chan03.gate', 'count_mode', 'delay', \"\n", " \"'auto_count_delay', 'freq', 'preset_time', \"\n", " \"'auto_count_time', 'egu'])\"],\n", " 'num': 5,\n", " 'per_step': 'None'},\n", " 'plan_name': 'scan',\n", " 'plan_pattern': 'inner_product',\n", " 'plan_pattern_args': {'args': [\"EpicsMotor(prefix='gp:m1', name='m1', \"\n", " 'settle_time=0.0, timeout=None, '\n", " \"read_attrs=['user_readback', \"\n", " \"'user_setpoint'], \"\n", " \"configuration_attrs=['user_offset', \"\n", " \"'user_offset_dir', 'velocity', \"\n", " \"'acceleration', 'motor_egu'])\",\n", " -1,\n", " 1],\n", " 'num': 5},\n", " 'plan_pattern_module': 'bluesky.plan_patterns',\n", " 'plan_type': 'generator',\n", " 'scan_id': 2,\n", " 'time': 1684257283.2970834,\n", " 'uid': '27c27453-9632-4f8c-b0a7-602c5db0a2e1',\n", " 'versions': {'bluesky': '1.10.0', 'ophyd': '1.7.0'}}\n", "\n", "descriptor 8\n", "{'configuration': {'m1': {'data': {'m1_acceleration': 0.2,\n", " 'm1_motor_egu': 'degrees',\n", " 'm1_user_offset': 0.0,\n", " 'm1_user_offset_dir': 0,\n", " 'm1_velocity': 1.0},\n", " 'data_keys': OrderedDict([('m1_user_offset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': -1e+300,\n", " 'precision': 4,\n", " 'shape': [],\n", " 'source': 'PV:gp:m1.OFF',\n", " 'units': 'degrees',\n", " 'upper_ctrl_limit': 1e+300}),\n", " ('m1_user_offset_dir',\n", " {'dtype': 'integer',\n", " 'enum_strs': ('Pos',\n", " 'Neg'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:m1.DIR',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('m1_velocity',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.1,\n", " 'precision': 4,\n", " 'shape': [],\n", " 'source': 'PV:gp:m1.VELO',\n", " 'units': 'degrees',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('m1_acceleration',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': -1e+300,\n", " 'precision': 4,\n", " 'shape': [],\n", " 'source': 'PV:gp:m1.ACCL',\n", " 'units': 'sec',\n", " 'upper_ctrl_limit': 1e+300}),\n", " ('m1_motor_egu',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:m1.EGU',\n", " 'units': None,\n", " 'upper_ctrl_limit': None})]),\n", " 'timestamps': {'m1_acceleration': 1684257260.388981,\n", " 'm1_motor_egu': 1684257260.388981,\n", " 'm1_user_offset': 1684257260.388981,\n", " 'm1_user_offset_dir': 1684257260.388981,\n", " 'm1_velocity': 1684257260.388981}},\n", " 'scaler': {'data': {'scaler_auto_count_delay': 0.0,\n", " 'scaler_auto_count_time': 1.0,\n", " 'scaler_channels_chan01_chname': 'clock',\n", " 'scaler_channels_chan01_gate': 'Y',\n", " 'scaler_channels_chan01_preset': 15000000.0,\n", " 'scaler_channels_chan02_chname': 'I0',\n", " 'scaler_channels_chan02_gate': 'N',\n", " 'scaler_channels_chan02_preset': 0.0,\n", " 'scaler_channels_chan03_chname': 'scint',\n", " 'scaler_channels_chan03_gate': 'N',\n", " 'scaler_channels_chan03_preset': 0.0,\n", " 'scaler_count_mode': 'OneShot',\n", " 'scaler_delay': 0.0,\n", " 'scaler_egu': '',\n", " 'scaler_freq': 10000000.0,\n", " 'scaler_preset_time': 1.5},\n", " 'data_keys': OrderedDict([('scaler_channels_chan01_chname',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.NM1',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan01_preset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.PR1',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_channels_chan01_gate',\n", " {'dtype': 'string',\n", " 'enum_strs': ('N',\n", " 'Y'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.G1',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan02_chname',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.NM2',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan02_preset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.PR2',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_channels_chan02_gate',\n", " {'dtype': 'string',\n", " 'enum_strs': ('N',\n", " 'Y'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.G2',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan03_chname',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.NM3',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan03_preset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.PR3',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_channels_chan03_gate',\n", " {'dtype': 'string',\n", " 'enum_strs': ('N',\n", " 'Y'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.G3',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_count_mode',\n", " {'dtype': 'string',\n", " 'enum_strs': ('OneShot',\n", " 'AutoCount'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.CONT',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_delay',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.DLY',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_auto_count_delay',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.DLY1',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_freq',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.FREQ',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_preset_time',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.TP',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_auto_count_time',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.TP1',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_egu',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.EGU',\n", " 'units': None,\n", " 'upper_ctrl_limit': None})]),\n", " 'timestamps': {'scaler_auto_count_delay': 1684257287.283159,\n", " 'scaler_auto_count_time': 1684257287.283159,\n", " 'scaler_channels_chan01_chname': 1684257287.283159,\n", " 'scaler_channels_chan01_gate': 1684257287.283159,\n", " 'scaler_channels_chan01_preset': 1684257287.283159,\n", " 'scaler_channels_chan02_chname': 1684257287.283159,\n", " 'scaler_channels_chan02_gate': 1684257287.283159,\n", " 'scaler_channels_chan02_preset': 1684257287.283159,\n", " 'scaler_channels_chan03_chname': 1684257287.283159,\n", " 'scaler_channels_chan03_gate': 1684257287.283159,\n", " 'scaler_channels_chan03_preset': 1684257287.283159,\n", " 'scaler_count_mode': 1684257287.283159,\n", " 'scaler_delay': 1684257287.283159,\n", " 'scaler_egu': 1684257287.283159,\n", " 'scaler_freq': 1684257287.283159,\n", " 'scaler_preset_time': 1684257287.283159}}},\n", " 'data_keys': {'I0': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.S2',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0},\n", " 'clock': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.S1',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0},\n", " 'm1': {'dtype': 'number',\n", " 'lower_ctrl_limit': -1000.0,\n", " 'object_name': 'm1',\n", " 'precision': 4,\n", " 'shape': [],\n", " 'source': 'PV:gp:m1.RBV',\n", " 'units': 'degrees',\n", " 'upper_ctrl_limit': 1000.0},\n", " 'm1_user_setpoint': {'dtype': 'number',\n", " 'lower_ctrl_limit': -1000.0,\n", " 'object_name': 'm1',\n", " 'precision': 4,\n", " 'shape': [],\n", " 'source': 'PV:gp:m1.VAL',\n", " 'units': 'degrees',\n", " 'upper_ctrl_limit': 1000.0},\n", " 'scaler_time': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.T',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0},\n", " 'scint': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:gp:scaler1.S3',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}},\n", " 'hints': {'m1': {'fields': ['m1']},\n", " 'scaler': {'fields': ['clock', 'I0', 'scint']}},\n", " 'name': 'primary',\n", " 'object_keys': {'m1': ['m1', 'm1_user_setpoint'],\n", " 'scaler': ['clock', 'I0', 'scint', 'scaler_time']},\n", " 'run_start': '27c27453-9632-4f8c-b0a7-602c5db0a2e1',\n", " 'time': 1684257287.3060765,\n", " 'uid': 'facadfef-8068-4c5b-b641-c9ebb91e1220'}\n", "\n", "event 7\n", "{'data': {'I0': 8.0,\n", " 'clock': 16000000.0,\n", " 'm1': -1.0,\n", " 'm1_user_setpoint': -1.0,\n", " 'scaler_time': 1.6,\n", " 'scint': 8.0},\n", " 'descriptor': 'facadfef-8068-4c5b-b641-c9ebb91e1220',\n", " 'filled': {},\n", " 'seq_num': 1,\n", " 'time': 1684257288.5562477,\n", " 'timestamps': {'I0': 1684257287.283159,\n", " 'clock': 1684257287.283159,\n", " 'm1': 1684257285.657212,\n", " 'm1_user_setpoint': 1684257283.400607,\n", " 'scaler_time': 1684257287.283159,\n", " 'scint': 1684257287.283159},\n", " 'uid': 'e3cadd5d-36aa-4d65-a86c-e5e3b40f38db'}\n", "\n", "event 7\n", "{'data': {'I0': 9.0,\n", " 'clock': 16000000.0,\n", " 'm1': -0.5,\n", " 'm1_user_setpoint': -0.5,\n", " 'scaler_time': 1.6,\n", " 'scint': 7.0},\n", " 'descriptor': 'facadfef-8068-4c5b-b641-c9ebb91e1220',\n", " 'filled': {},\n", " 'seq_num': 2,\n", " 'time': 1684257290.9914892,\n", " 'timestamps': {'I0': 1684257290.988253,\n", " 'clock': 1684257290.988253,\n", " 'm1': 1684257289.36312,\n", " 'm1_user_setpoint': 1684257288.603839,\n", " 'scaler_time': 1684257290.988253,\n", " 'scint': 1684257290.988253},\n", " 'uid': '3b448615-cfbf-4fa6-949b-bfc5f38669db'}\n", "\n", "event 7\n", "{'data': {'I0': 7.0,\n", " 'clock': 16000000.0,\n", " 'm1': 0.0,\n", " 'm1_user_setpoint': 0.0,\n", " 'scaler_time': 1.6,\n", " 'scint': 5.0},\n", " 'descriptor': 'facadfef-8068-4c5b-b641-c9ebb91e1220',\n", " 'filled': {},\n", " 'seq_num': 3,\n", " 'time': 1684257293.3976073,\n", " 'timestamps': {'I0': 1684257293.391206,\n", " 'clock': 1684257293.391206,\n", " 'm1': 1684257291.768174,\n", " 'm1_user_setpoint': 1684257291.056937,\n", " 'scaler_time': 1684257293.391206,\n", " 'scint': 1684257293.391206},\n", " 'uid': 'd170727a-038b-432a-9fa4-a14d9857e41d'}\n", "\n", "event 7\n", "{'data': {'I0': 7.0,\n", " 'clock': 16000000.0,\n", " 'm1': 0.5,\n", " 'm1_user_setpoint': 0.5,\n", " 'scaler_time': 1.6,\n", " 'scint': 8.0},\n", " 'descriptor': 'facadfef-8068-4c5b-b641-c9ebb91e1220',\n", " 'filled': {},\n", " 'seq_num': 4,\n", " 'time': 1684257295.9012296,\n", " 'timestamps': {'I0': 1684257295.898317,\n", " 'clock': 1684257295.898317,\n", " 'm1': 1684257294.272727,\n", " 'm1_user_setpoint': 1684257293.50185,\n", " 'scaler_time': 1684257295.898317,\n", " 'scint': 1684257295.898317},\n", " 'uid': '47180649-a9b0-4a10-b380-95541a096c24'}\n", "\n", "event 7\n", "{'data': {'I0': 9.0,\n", " 'clock': 16000000.0,\n", " 'm1': 1.0,\n", " 'm1_user_setpoint': 1.0,\n", " 'scaler_time': 1.6,\n", " 'scint': 7.0},\n", " 'descriptor': 'facadfef-8068-4c5b-b641-c9ebb91e1220',\n", " 'filled': {},\n", " 'seq_num': 5,\n", " 'time': 1684257298.4070554,\n", " 'timestamps': {'I0': 1684257298.403889,\n", " 'clock': 1684257298.403889,\n", " 'm1': 1684257296.778319,\n", " 'm1_user_setpoint': 1684257295.981387,\n", " 'scaler_time': 1684257298.403889,\n", " 'scint': 1684257298.403889},\n", " 'uid': '303a8aa8-8fdb-44c6-8366-1b1cc3000b08'}\n", "\n", "stop 6\n", "{'exit_status': 'success',\n", " 'num_events': {'primary': 5},\n", " 'reason': '',\n", " 'run_start': '27c27453-9632-4f8c-b0a7-602c5db0a2e1',\n", " 'time': 1684257298.5027833,\n", " 'uid': 'ed996294-1aaf-4052-b82b-c1b7d5bc9a3a'}\n" ] }, { "data": { "text/plain": [ "('27c27453-9632-4f8c-b0a7-602c5db0a2e1',)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RE(bp.scan([scaler], m1, -1, 1, 5), myCallback)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Summary\n", "\n", "We'll show this code as a python program:\n", "\n", "```\n", "#!/usr/bin/env python\n", "\n", "\"\"\"Basic : motor\"\"\"\n", "\n", "from ophyd import EpicsMotor\n", "from ophyd.scaler import ScalerCH\n", "from bluesky import RunEngine\n", "import bluesky.plans as bp\n", "\n", "\n", "def myCallback(key, doc):\n", " print()\n", " print(key, len(doc))\n", " pprint.pprint(doc)\n", "\n", "\n", "m1 = EpicsMotor(\"gp:m1\", name=\"m1\")\n", "m1.wait_for_connection()\n", "print(m1.position)\n", "\n", "scaler = ScalerCH(\"gp:scaler1\", name=\"scaler\")\n", "scaler.wait_for_connection()\n", "\n", "\n", "# Since there are no detectors actually connected to this scaler,\n", "# we can change names at our choice. A real scaler will have\n", "# detectors connected to specific channels and we should not modify\n", "# these names without regard to how signals are physically connected.\n", "scaler.channels.chan01.chname.put(\"clock\")\n", "scaler.channels.chan02.chname.put(\"I0\")\n", "scaler.channels.chan03.chname.put(\"scint\")\n", "scaler.channels.chan04.chname.put(\"\")\n", "scaler.channels.chan05.chname.put(\"\")\n", "scaler.channels.chan06.chname.put(\"\")\n", "scaler.channels.chan07.chname.put(\"\")\n", "scaler.channels.chan08.chname.put(\"\")\n", "scaler.channels.chan09.chname.put(\"\")\n", "\n", "\n", "scaler.match_names()\n", "scaler.select_channels()\n", "print(scaler.read())\n", "\n", "RE = RunEngine({})\n", "\n", "RE(bp.scan([scaler], m1, -1, 1, 5))\n", "\n", "RE(bp.scan([scaler], m1, -1, 1, 5), myCallback)\n", "```" ] } ], "metadata": { "interpreter": { "hash": "fa399ef8ed4fbc3b7fe63ebf4307839a170374bf77134d519fcb3b724ac0582b" }, "kernelspec": { "display_name": "Python 3.8.10 64-bit ('base': conda)", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 2 }