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

FieldTypeDescription
timestampint64Unix time in nanoseconds.
pinsHalPinInfo[]All HAL pins.
signalsHalSignalInfo[]All HAL signals.
paramsHalParamInfo[]All HAL parameters.
componentsHalComponentInfo[]Groups inferred from names, not HAL’s own component list; see QueryComponents.
message_levelMessageLevelThe server process’s RTAPI message level, or MSG_LEVEL_UNSPECIFIED if HAL does not say.
is_simboolHAL’s is_sim flag.
is_rtboolHAL’s is_rt flag.
is_userspaceboolHAL’s is_userspace flag.
kernel_versionstringHAL’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:

CodeCondition
INTERNALHAL could not be read, and the message names the error.
UNAVAILABLEThe 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.

Commandsuccesserror
component_existsTrue.Empty if the component exists, otherwise a message saying it does not.
component_readyTrue if the component exists.Empty if it is ready, otherwise a message.
pin_has_writerTrue.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, so axis.* matches axis.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:

FieldTypeDescription
successboolWhether the value was read.
errorstringThe cause when success is false.
valueHalValueThe value.
typeHalTypeThe 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

FieldTypeDescription
interval_msint32Milliseconds between updates; 0 or less means 100, and values above 60000 are treated as 60000.
filterstring[]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:

CodeCondition
INTERNALHAL could not be read five times in a row, and the message names the cause.
UNAVAILABLEThe server has found its LinuxCNC gone (reason linuxcnc-gone).
RESOURCE_EXHAUSTEDToo 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

FieldTypeDescription
namesstring[]The names to watch, at most 1000 different ones; duplicates are ignored.
interval_msint32Milliseconds 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:

FieldTypeDescription
namestringThe name that changed.
old_valueHalValueThe previous value.
new_valueHalValueThe new value.
timestampint64When 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:

CodeCondition
INVALID_ARGUMENTNo names, more than 1000 different names, or a name that cannot be read when the watch starts.
INTERNALHAL 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.
UNAVAILABLEThe server has found its LinuxCNC gone (reason linuxcnc-gone).
RESOURCE_EXHAUSTEDToo many streams and WaitComplete calls are in progress; see Thread pool.