HalService
Read-only access to LinuxCNC’s HAL: pins, signals, parameters and inferred components. It needs LinuxCNC 2.9 or newer (see Requirements).
Once the server has found its LinuxCNC gone, every HAL RPC fails with
UNAVAILABLE and the reason linuxcnc-gone, and open HAL streams end that
way; see Errors and reasons.
GetSystemStatus
Read every pin, signal and parameter, and HAL’s system flags.
rpc GetSystemStatus(GetSystemStatusRequest) returns (HalSystemStatus)Request: GetSystemStatusRequest, empty.
Response: HalSystemStatus
| Field | Type | Description |
|---|---|---|
timestamp | int64 | Unix time in nanoseconds. |
pins | HalPinInfo[] | All HAL pins. |
signals | HalSignalInfo[] | All HAL signals. |
params | HalParamInfo[] | All HAL parameters. |
components | HalComponentInfo[] | Groups inferred from names, not HAL’s own component list; see QueryComponents. |
message_level | MessageLevel | The server process’s RTAPI message level, or MSG_LEVEL_UNSPECIFIED if HAL does not say. |
is_sim | bool | HAL’s is_sim flag. |
is_rt | bool | HAL’s is_rt flag. |
is_userspace | bool | HAL’s is_userspace flag. |
kernel_version | string | HAL’s kernel_version, “Not Available” on uspace builds. |
The flags and the kernel version are what LinuxCNC’s hal Python module
reports on the server’s machine.
Error codes:
| Code | Condition |
|---|---|
INTERNAL | HAL could not be read, and the message names the error. |
UNAVAILABLE | The server has found its LinuxCNC gone (reason linuxcnc-gone). |
SendCommand (HAL)
Ask one of three yes-or-no questions about HAL.
rpc SendCommand(HalCommand) returns (HalCommandResponse)The response, HalCommandResponse, carries success, error and serial:
the request’s serial, or the server’s own counter when that is 0.
| Command | success | error |
|---|---|---|
component_exists | True. | Empty if the component exists, otherwise a message saying it does not. |
component_ready | True if the component exists. | Empty if it is ready, otherwise a message. |
pin_has_writer | True. | Empty if the pin’s signal has a writer, otherwise a message. |
If the HAL call raises, any of the three returns success = false with the
exception text in error.
get_value and the query_* commands return success = false with an
error naming the RPC to call instead: GetValue,
QueryPins, QuerySignals,
QueryParams or QueryComponents. Every
other command (create, set, connect) returns success = false, since the
service does not change HAL.
Queries
GetValue and the four Query* RPCs answer a failure (HAL could not be
read, or a name HAL does not know) with success = false and the cause in
error, not with a gRPC error. Every response has success, error,
serial (from the server’s own counter) and the results. The only gRPC
error is UNAVAILABLE with the reason linuxcnc-gone.
A query pattern is a glob matched against the whole name with Python’s
fnmatch:
- An empty pattern means
*. *also matches dots, soaxis.*matchesaxis.x.pos-cmd.- Matching is case-sensitive.
GetValue
Read the value of one pin, signal or parameter.
rpc GetValue(GetValueCommand) returns (GetValueResponse)The request has name, the full name, such as axis.x.pos-cmd. The
response, GetValueResponse:
| Field | Type | Description |
|---|---|---|
success | bool | Whether the value was read. |
error | string | The cause when success is false. |
value | HalValue | The value. |
type | HalType | The value’s type, such as HAL_BIT or HAL_FLOAT. |
Where HAL lists no type for a name, the type is worked out from the value; see HalType.
QueryPins
List the pins whose names match a pattern.
rpc QueryPins(QueryPinsCommand) returns (QueryPinsResponse)The request has pattern, such as axis.* or *speed*. The results are
in pins, a list of HalPinInfo, where signal is
always empty and has_writer is HAL’s own answer.
hal_stub is made as in the
client quickstart.
Example (Python):
request = hal_pb2.QueryPinsCommand(pattern="axis.x.*")
response = hal_stub.QueryPins(request)
for pin in response.pins:
print(f"{pin.name}: {pin.value}")QuerySignals
List the signals whose names match a pattern.
rpc QuerySignals(QuerySignalsCommand) returns (QuerySignalsResponse)The results are in signals (HalSignalInfo[]). driver names the pin that drives a signal. readers is always empty and
reader_count always 0, because LinuxCNC’s hal module does not say which
pins read a signal.
QueryParams
List the parameters whose names match a pattern.
rpc QueryParams(QueryParamsCommand) returns (QueryParamsResponse)The results are in params (HalParamInfo[]).
QueryComponents
List the components whose names match a pattern.
rpc QueryComponents(QueryComponentsCommand) returns (QueryComponentsResponse)The results are in components (HalComponentInfo[]). LinuxCNC’s hal
module has no component list, so the server infers
components from pin and parameter names. The part of a name before its last
dot is the component, and the pattern is matched against that. Such a group
is not always a real HAL component, and a component with no pins or
parameters is not listed. Only name, pins and params are filled in:
ready, type and pid are never set, and id is 0.
StreamStatus (HAL)
Receive the full HAL status at a fixed interval.
rpc StreamStatus(HalStreamStatusRequest) returns (stream HalSystemStatus)Request: HalStreamStatusRequest
| Field | Type | Description |
|---|---|---|
interval_ms | int32 | Milliseconds between updates; 0 or less means 100, and values above 60000 are treated as 60000. |
filter | string[] | Ignored: the stream always carries the full status. |
The stream carries HalSystemStatus, as in
GetSystemStatus, and ends as soon as the client cancels.
has_writer is refreshed every 2 seconds, not with every update.
Error codes:
| Code | Condition |
|---|---|
INTERNAL | HAL could not be read five times in a row, and the message names the cause. |
UNAVAILABLE | The server has found its LinuxCNC gone (reason linuxcnc-gone). |
RESOURCE_EXHAUSTED | Too many streams and WaitComplete calls are in progress; see Thread pool. |
WatchValues
Receive the changes of chosen pins, signals and parameters.
rpc WatchValues(WatchRequest) returns (stream ValueChangeBatch)Request: WatchRequest
| Field | Type | Description |
|---|---|---|
names | string[] | The names to watch, at most 1000 different ones; duplicates are ignored. |
interval_ms | int32 | Milliseconds between checks; 0 or less means 100, and values above 60000 are treated as 60000. |
Response: a stream of ValueChangeBatch, each with a timestamp and a
list of ValueChange:
| Field | Type | Description |
|---|---|---|
name | string | The name that changed. |
old_value | HalValue | The previous value. |
new_value | HalValue | The new value. |
timestamp | int64 | When the change was seen, in Unix nanoseconds. |
A batch is sent only when at least one value changed, so there is no first
batch with the current values. Two NaN readings in a row count as unchanged.
A poll that fails for some names still sends the changes of the others,
until five failed polls in a row end the stream with INTERNAL. The stream
ends as soon as the client cancels.
Error codes:
| Code | Condition |
|---|---|
INVALID_ARGUMENT | No names, more than 1000 different names, or a name that cannot be read when the watch starts. |
INTERNAL | HAL could not be read at the start, or five polls in a row each failed to read a watched name, and the message names the first failure of the last poll. |
UNAVAILABLE | The server has found its LinuxCNC gone (reason linuxcnc-gone). |
RESOURCE_EXHAUSTED | Too many streams and WaitComplete calls are in progress; see Thread pool. |