|
| 1 | +:lang: en |
| 2 | +:toc: |
| 3 | + |
| 4 | +[[cha:python-hal-interface]] |
| 5 | += The HAL Python module |
| 6 | + |
| 7 | +:ini: {basebackend@docbook:'':ini} |
| 8 | +:hal: {basebackend@docbook:'':hal} |
| 9 | +:ngc: {basebackend@docbook:'':ngc} |
| 10 | + |
| 11 | +This documentation describes the `hal` python module, which provides |
| 12 | +a Python API for creating and accessing HAL pins and signals. |
| 13 | + |
| 14 | + |
| 15 | +== Basic usage |
| 16 | + |
| 17 | + |
| 18 | +[source,python] |
| 19 | +---- |
| 20 | +#!/usr/bin/env python3 |
| 21 | +import hal, time |
| 22 | +h = hal.component("passthrough") |
| 23 | +h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN) |
| 24 | +h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT) |
| 25 | +h.ready() |
| 26 | +---- |
| 27 | + |
| 28 | +== Functions |
| 29 | + |
| 30 | + |
| 31 | +*component*:: + |
| 32 | +The component itself is created by a call to the constructor `hal.component`. |
| 33 | +The arguments are the HAL component name and (optionally) the |
| 34 | +prefix used for pin and parameter names. If the prefix is not |
| 35 | +specified, the component name is used. + |
| 36 | +.Example |
| 37 | +[source,python] |
| 38 | +---- |
| 39 | +h = hal.component("passthrough") |
| 40 | +---- |
| 41 | + |
| 42 | +*newpin*:: + |
| 43 | +Create new pin. + |
| 44 | +Arguments: pin name suffix, pin type, and pin direction. For |
| 45 | +parameters, the arguments are: parameter name suffix, parameter type, |
| 46 | +and parameter direction. + |
| 47 | +.Example: |
| 48 | +[source,python] |
| 49 | +---- |
| 50 | +h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN) |
| 51 | +---- |
| 52 | + |
| 53 | + |
| 54 | +*ready* :: |
| 55 | +Tells the HAL system the component is initialized. Locks out adding pins. |
| 56 | + |
| 57 | +*unready* :: |
| 58 | +Allows a component to add pins after 'ready()' has been called. |
| 59 | +One should call 'ready()' on the component after. |
| 60 | + |
| 61 | +*component_exists* :: |
| 62 | +Does the specified component exist at this time. |
| 63 | + |
| 64 | +.Example |
| 65 | +---- |
| 66 | +hal.component_exists("testpanel") |
| 67 | +---- |
| 68 | + |
| 69 | +*component_is_ready* :: |
| 70 | +Is the specified component ready at this time. |
| 71 | + |
| 72 | +.Example |
| 73 | +---- |
| 74 | +hal.component_is_ready("testpanel") |
| 75 | +---- |
| 76 | + |
| 77 | +*get_msg_level* :: |
| 78 | +Get the current Realtime msg level. |
| 79 | + |
| 80 | +*set_msg_level* :: |
| 81 | +Set the current Realtime msg level. |
| 82 | +used for debugging information. |
| 83 | + |
| 84 | +*connect* :: |
| 85 | +Connect a pin to a signal. |
| 86 | + |
| 87 | +.Example |
| 88 | +---- |
| 89 | +hal.connect("pinname","signal_name") |
| 90 | +---- |
| 91 | + |
| 92 | +*disconnect* :: |
| 93 | +Disconnect a pin from a signal. |
| 94 | + |
| 95 | +.Example |
| 96 | +---- |
| 97 | +hal.disconnect("pinname") |
| 98 | +---- |
| 99 | + |
| 100 | +*get_value* :: |
| 101 | +Read a pin, param, or signal directly. |
| 102 | + |
| 103 | +.Example |
| 104 | +[source,python] |
| 105 | +---- |
| 106 | +value = hal.get_value("iocontrol.0.emc-enable-in") |
| 107 | +---- |
| 108 | + |
| 109 | +*get_info_pins()* :: |
| 110 | +Returns a list of dicts of all system pins. |
| 111 | + |
| 112 | +[source,python] |
| 113 | +---- |
| 114 | +listOfDicts = hal.get_info_pins() |
| 115 | +pinName1 = listOfDicts[0].get('NAME') |
| 116 | +pinValue1 = listOfDicts[0].get('VALUE') |
| 117 | +pinType1 = listOfDicts[0].get('TYPE') |
| 118 | +pinDirection1 = listOfDicts[0].get('DIRECTION') |
| 119 | +---- |
| 120 | + |
| 121 | +*get_info_signals()* :: |
| 122 | +Returns a list of dicts of all system signals. |
| 123 | + |
| 124 | +[source,python] |
| 125 | +---- |
| 126 | +listOfDicts = hal.get_info_signals() |
| 127 | +signalName1 = listOfDicts[0].get('NAME') |
| 128 | +signalValue1 = listOfDicts[0].get('VALUE') |
| 129 | +driverPin1 = listOfDicts[0].get('DRIVER') |
| 130 | +---- |
| 131 | + |
| 132 | +*get_info_params()* :: |
| 133 | +Returns a list of dicts of all system parameters. |
| 134 | + |
| 135 | +[source,python] |
| 136 | +---- |
| 137 | +listOfDicts = hal.get_info_params() |
| 138 | +paramName1 = listOfDicts[0].get('NAME') |
| 139 | +paramValue1 = listOfDicts[0].get('VALUE') |
| 140 | +paramDirection1 = listOfDicts[0].get('DIRECTION') |
| 141 | +---- |
| 142 | + |
| 143 | +*new_sig* :: |
| 144 | +Create a new signal of the type specified. |
| 145 | + |
| 146 | +.Example |
| 147 | +[source,python] |
| 148 | +---- |
| 149 | +hal.new_sig("signalname",hal.HAL_BIT) |
| 150 | +---- |
| 151 | + |
| 152 | +*pin_has_writer* :: |
| 153 | +Does the specified pin have a driving pin connected. + |
| 154 | +Returns True or False. |
| 155 | + |
| 156 | +---- |
| 157 | +h.in.pin_has_writer() |
| 158 | +---- |
| 159 | + |
| 160 | +*get_name* :: |
| 161 | +Get the HAL object name. + |
| 162 | +Return a string. |
| 163 | + |
| 164 | +---- |
| 165 | +h.in.get_name() |
| 166 | +---- |
| 167 | + |
| 168 | +*get_type* :: |
| 169 | +Get the HAL object's type. + |
| 170 | +Returns an integer. |
| 171 | + |
| 172 | +---- |
| 173 | +h.in.get_type() |
| 174 | +---- |
| 175 | + |
| 176 | +*get_dir* :: |
| 177 | +Get the HAL object direction type. + |
| 178 | +Returns an integer. |
| 179 | + |
| 180 | +---- |
| 181 | +h.in.get_dir() |
| 182 | +---- |
| 183 | + |
| 184 | +*get* :: |
| 185 | +Get the HAL object value. |
| 186 | + |
| 187 | +---- |
| 188 | +h.in.get() |
| 189 | +---- |
| 190 | + |
| 191 | +*set* :: |
| 192 | +Set the HAL object value. |
| 193 | + |
| 194 | +---- |
| 195 | +h.out.set(10) |
| 196 | +---- |
| 197 | + |
| 198 | +*is_pin* :: |
| 199 | +Is the object a pin or parameter? + |
| 200 | +Returns True or False. |
| 201 | + |
| 202 | +---- |
| 203 | +h.in.is_pin() |
| 204 | +---- |
| 205 | + |
| 206 | +*sampler_base* :: |
| 207 | +TODO |
| 208 | + |
| 209 | +*stream_base* :: |
| 210 | +TODO |
| 211 | + |
| 212 | +*stream* :: |
| 213 | +TODO |
| 214 | + |
| 215 | +*set_p* :: |
| 216 | +Set a pin value of any pin in the HAL system. |
| 217 | + |
| 218 | +.Example |
| 219 | +---- |
| 220 | +hal.set_p("pinname","10") |
| 221 | +---- |
0 commit comments