Work with Device
This note demonstrates how to get work with the device, the device
usually can be reached by accessing the abstracted Python object,
specifically, the instance of CaElement
, in which
fundamental APIs are created to make the device operation easy and
functional.
Assuming the following MachinePortal
instance mp
has already been created, otherwise please see Work with MachinePortal.
The generic device operation procedure is:
Locate the interested device(s) or element(s);
Control the device(s) by calling methods or accessing attributes;
Post-processing the for other consumers.
Locate Device
Just as the name implies, mp is the entry to all the configurations of
the loaded machine, the following snippet shows how can we locate the
interested device(s). All valid device types can be known by
get_all_types()
:
In [1]: from phantasy import MachinePortal
In [2]: mp = MachinePortal(machine="FRIB", segment="LEBT")
In [3]: mp.get_all_types()
Out[3]:
['ATT',
'SOL',
'SEXT',
'VCOR',
'HCOR',
'BEND',
'EQUAD',
'FC',
'EMS',
'VD',
'SLT',
'PM',
'CHP',
'AP',
'EBEND',
'CAV',
'BCM']
The method get_elements()
is created for
the general purpose of element searching, e.g. all the solenoid could be
located by passing the type
parameter with the value of SOL
(
which is one member of the list returned from get_all_types() method),
the returned result is a list, so if the first one is wanted, simply
referring by [0]
.
In [4]: all_sols = mp.get_elements(type='SOL')
In [5]: all_sols
Out[5]:
[FE_SRC2:SOLS_D0659 [SOL] @ sb=65.939153,
FE_SRC2:SOLS_D0662 [SOL] @ sb=66.189153,
FE_SRC2:SOLS_D0664 [SOL] @ sb=66.439153,
FE_SRC2:SOLR_D0669 [SOL] @ sb=66.784745,
FE_SCS2:SOLR_D0683 [SOL] @ sb=68.106995,
FE_SCS1:SOLR_D0704 [SOL] @ sb=70.206995,
FE_LEBT:SOLR_D0787 [SOL] @ sb=78.481995,
FE_LEBT:SOLR_D0802 [SOL] @ sb=79.957145,
FE_LEBT:SOLR_D0818 [SOL] @ sb=81.597295,
FE_LEBT:SOLR_D0951 [SOL] @ sb=94.894800,
FE_LEBT:SOLR_D0967 [SOL] @ sb=96.534950,
FE_LEBT:SOLR_D0982 [SOL] @ sb=98.010100,
FE_LEBT:SOLR_D0995 [SOL] @ sb=99.320100]
In [6]: first_sol = all_sols[0]
In [7]: first_sol
Out[7]: FE_SRC2:SOLS_D0659 [SOL] @ sb=65.939153
Inspect Device
Each one within the list returned from
get_elements()
is the instance of
CaElement
, which is bundled of various information,
represented as attributes of the Python object [1], simply by
hitting <TAB>
button after dot (.), list of possible methods,
attributes will be pop out, select any of them to get the execution
results.
Footnotes