@@ -48,23 +48,63 @@ Message level constants:
4848* `hal.MSG_DBG` - Additionally include debugging information
4949* `hal.MSG_ALL` - Print all messages encountered, disregarding level
5050
51+ Realtime type constants:
52+
53+ * `hal.REALTIME_TYPE_UNINITIALIZED` - Real time module not running
54+ * `hal.REALTIME_TYPE_NONE` - No realtime available
55+ * `hal.REALTIME_TYPE_UNKNOWN` - Only used when LINUXCNC_FORCE_REALTIME=1 is set. Unknown, no PREEMPT_DYNAMIC but SCHED_FIFO is available. Not recommended.
56+ * `hal.REALTIME_TYPE_PREEMPT_DYNAMIC` - Preempt dynamic: available in vanilla kernel. Only used when LINUXCNC_FORCE_REALTIME=1 is set. Not recommended.
57+ * `hal.REALTIME_TYPE_PREEMPT_RT` - Preempt RT
58+ * `hal.REALTIME_TYPE_RTAI` - RTAI kernel mode
59+ * `hal.REALTIME_TYPE_LXRT` - LXRT, userspace implementation for RTAI
60+ * `hal.REALTIME_TYPE_XENOMAI` - Xenomai 3
61+ * `hal.REALTIME_TYPE_XENOMAI_EVL` - Xenomai 4 aka Xenomai EVL
62+
5163System information:
5264
5365* `hal.is_kernelspace` - One (1) if RTAPI runs in the kernel, otherwise zero (0)
5466* `hal.is_userspace` - Inverted `hal.is_kernelspace`
5567* `hal.kernel_version` - A string specifying the real-time kernel version if `hal.is_kernelspace` is one.
5668 Otherwise it specifies `"Not Available"`.
57- * `hal.is_rt` - One (1) if the system runs in real-time, otherwise zero (0)
58- * `hal.is_sim` - Inverted `hal.is_rt`
69+ * `hal.is_rt` - One (1) if the system runs in real-time, otherwise zero (0) *DEPRECATED*: Use `lcnc_realtime.verify()`
70+ * `hal.is_sim` - Inverted `hal.is_rt` *DEPRECATED*: Use `lcnc_realtime.verify()`
5971
6072=== hal methods
6173
74+ hal.is_initialized()::
75+ Returns a boolean to indicate whether hal is initialized. The hal is initialized when there is
76+ at least one component. If this is not the case, many of the following functions will throw
77+ a `RuntimeError` exception: `Cannot call before creating component`
78+
79+ .Example:
80+ [source,python]
81+ ----
82+ #The hal must be initialized to use many of the hal functions
83+ #If it is not initialized, create a component which will initialize it
84+ #The component will be cleaned up after comp goes out of scope
85+ #Use pid as component identifier, so it is unlikely to collide
86+ #with existing components
87+ comp_name = f"halpy{os.getpid()}"
88+ if not hal.is_initialized():
89+ comp = hal.component(comp_name)
90+
91+ type = hal.get_realtime_type()
92+ ----
93+
94+ hal.get_realtime_type()::
95+ Returns the type of the running realtime system.
96+ Might return `hal.REALTIME_TYPE_UNINITIALIZED` if `rtapi_app` is not running.
97+ See xref:_hal_constants[realtime type constants]. +
98+ Throws a `RuntimeError` exception if HAL is not initialized.
99+
62100hal.component_exists(_name_:string)::
63- Returns a boolean to indicate whether or not the specified component exist at this time.
101+ Returns a boolean to indicate whether or not the specified component exist at this time. +
102+ Throws a `RuntimeError` exception if HAL is not initialized.
64103
65104hal.component_is_ready(_name_:string)::
66105Returns a boolean to indicate whether or not the specified component is in the ready state.
67- Also returns False if the component does not exist.
106+ Also returns False if the component does not exist. +
107+ Throws a `RuntimeError` exception if HAL is not initialized.
68108
69109.Example:
70110[source,python]
@@ -86,7 +126,8 @@ See 'hal.set_msg_level()' and xref:_hal_constants[message constants] for list of
86126hal.new_sig(_name_:string, _type_:enum)::
87127Create a new signal (net) called _name_.
88128The signal can carry information of _type_ content.
89- Returns `True` on success.
129+ Returns `True` on success. +
130+ Throws a `RuntimeError` exception if HAL is not initialized.
90131
91132.Example:
92133[source,python]
@@ -98,7 +139,8 @@ if not hal.new_sig("signalname", hal.HAL_BIT):
98139hal.connect(_pinname_:string, _signame_:string)::
99140Connect the pin _pinname_ to signal _signame_.
100141Both signal and pin must exist and both pin and signal must be of the same type.
101- Returns `True` on success.
142+ Returns `True` on success. +
143+ Throws a `RuntimeError` exception if HAL is not initialized.
102144
103145.Example:
104146[source,python]
@@ -110,7 +152,8 @@ if not hal.connect("mycomp.pinname", "signalname"):
110152hal.disconnect(_pinname_:string, _signame_:string)::
111153Disconnect the pin _pinname_ from signal _signame_.
112154Both signal and pin must exist.
113- Returns `True` on success.
155+ Returns `True` on success. +
156+ Throws a `RuntimeError` exception if HAL is not initialized.
114157
115158.Example:
116159[source,python]
@@ -121,7 +164,8 @@ if not hal.disconnect("mycomp.pinname"):
121164
122165hal.pin_has_writer(_pinname_:string)::
123166Returns `True` if pin with name _pinname_ is attached to a signal and there is at least one writer.
124- Otherwise, `False` is returned.
167+ Otherwise, `False` is returned. +
168+ Throws a `RuntimeError` exception if HAL is not initialized.
125169
126170.Example:
127171[source,python]
@@ -135,8 +179,9 @@ else:
135179hal.set_p(_name_:string, _value_:mixed)::
136180Sets the pin or param called _name_ to _value_.
137181The _name_ is the full name of the pin or param.
138- The search order is pin names first, then parameter names.
182+ The search order is pin names first, then parameter names. +
139183Throws a `RuntimeError` exception if the _name_ is not found. +
184+ Throws a `RuntimeError` exception if HAL is not initialized. +
140185The type of _value_ depends on the type of the pin or param.
141186Integer scalar types may use integers or a textual representation of an integer to set the value.
142187Floating point type may use both integer, floating point and textual representation thereof to set the value.
@@ -158,14 +203,16 @@ The same rules for _value_ apply to 'set_s()' as to 'set_p()'. +
158203 +
159204The 'set_s()' method has one special case when the signal is of type `hal.HAL_PORT` and it is fully connected.
160205In that case, the call uses the _value_ to set the port's queue size and it must be a positive integer.
161- See below xref:_hal_port_pipes[on configuring a port].
206+ See below xref:_hal_port_pipes[on configuring a port]. +
207+ Throws a `RuntimeError` exception if HAL is not initialized.
162208
163209hal.get_value(_name_:string)::
164210Returns the value of the pin, param or signal with _name_, searched in that order.
165211Boolean types return `True` or `False`.
166212Integer scalar types return an integer.
167213Floating point types return a float.
168- A `RuntimeError` exception is thrown if no pin, param or signal is found by that name.
214+ A `RuntimeError` exception is thrown if no pin, param or signal is found by that name. +
215+ Throws a `RuntimeError` exception if HAL is not initialized.
169216
170217.Example:
171218[source,python]
@@ -174,13 +221,16 @@ value = hal.get_value("iocontrol.0.emc-enable-in")
174221----
175222
176223hal.get_info_pins()::
177- Returns a list of dictionary tuples as in `{"NAME":"pinname", "VALUE":<bool|int|float>, "TYPE":<int>, "DIRECTION":<int>}`.
224+ Returns a list of dictionary tuples as in `{"NAME":"pinname", "VALUE":<bool|int|float>, "TYPE":<int>, "DIRECTION":<int>}`. +
225+ Throws a `RuntimeError` exception if HAL is not initialized.
178226
179227hal.get_info_params()::
180- Returns a list of dictionary tuples as in `{"NAME":"paramname", "VALUE":<bool|int|float>, "TYPE":<int>, "DIRECTION":<int>}`.
228+ Returns a list of dictionary tuples as in `{"NAME":"paramname", "VALUE":<bool|int|float>, "TYPE":<int>, "DIRECTION":<int>}`. +
229+ Throws a `RuntimeError` exception if HAL is not initialized.
181230
182231hal.get_info_signals()::
183- Returns a list of dictionary tuples as in `{"NAME":"signame", "VALUE":<bool|int|float>, "TYPE":<int>, "DRIVER":"name"|None}`.
232+ Returns a list of dictionary tuples as in `{"NAME":"signame", "VALUE":<bool|int|float>, "TYPE":<int>, "DRIVER":"name"|None}`. +
233+ Throws a `RuntimeError` exception if HAL is not initialized.
184234
185235.Example:
186236[source,python]
0 commit comments