halcmd − manipulate the Enhanced Machine Controller HAL from the command line |
halcmd [OPTIONS] [COMMAND [ARG]] halrun [-I] [HALCMD OPTIONS] halrun [-U] |
halcmd is used to manipulate the HAL (Hardware Abstraction Layer) from the command line. halcmd can optionally read commands from a file, allowing complex HAL configurations to be set up with a single command. halrun is a convenience script which sets up the realtime environment, executes halcmd with the given arguments, optionally runs an interactive halcmd -kf if -I is given, then tears down the realtime environment. If the readline library is available when emc is compiled, then halcmd offers commandline editing and completion when running interactively. Use the up arrow to recall previous commands, and press tab to complete the names of items such as pins and signals. |
-I |
Before tearing down the realtime environment, run an interactive halcmd. halrun only. -I must precede all other commandline arguments. |
−f [file] |
Ignore commands on command line, take input from file instead. If file is not specified, take input from stdin. |
-i inifile |
Use variables from inifile for substitutions. See SUBSTITUTION below. |
−k |
Keep going after failed command(s). The default is to stop and return failure if any command fails. |
||
−q |
display errors only (default) |
||
−Q |
display nothing, execute commands silently |
||
−s |
Script-friendly mode. In this mode, show will not output titles for the items shown. Also, module names will be printed instead of ID codes in pin, param, and funct listings. Threads are printed on a single line, with the thread period, FP usage and name first, followed by all of the functions in the thread, in execution order. Signals are printed on a single line, with the type, value, and signal name first, followed by a list of pins connected to the signal, showing both the direction and the pin name. No prompt will be printed if both -s and -f are specified. |
||
-R |
Release the HAL mutex. This is useful for recovering when a HAL component has crashed while holding the HAL mutex. |
||
-U |
Forcibly cause the realtime environment to exit. It releases the HAL mutex, requests that all HAL components unload, and stops the realtime system. halrun only. -U must be the only commandline argument. |
||
−v |
display results of each command |
||
−V |
display lots of debugging junk |
−h [command] |
display a help screen and exit, displays extended help on command if specified |
Commands tell halcmd what to do. Normally halcmd reads a single command from the command line and executes it. If the ’-f’ option is used to read commands from a file, halcmd reads each line of the file as a new command. Anything following ’#’ on a line is a comment. |
loadrt modname |
(load realtime module) Loads a realtime HAL module called modname. halcmd looks for the module in a directory specified at compile time. In systems with realtime, halcmd calls the emc_module_helper to load realtime modules. emc_module_helper is a setuid program and is compiled with a whitelist of modules it is allowed to load. This is currently just a list of EMC-related modules. The emc_module_helper execs insmod, so return codes and error messages are those from insmod. Administrators who wish to restrict which users can load these EMC-related kernel modules can do this by setting the permissions and group on emc_module_helper appropriately. In systems without realtime halcmd calls the rtapi_app which creates the simulated realtime environment if it did not yet exist, and then loads the requested component with a call to dlopen(3). |
unloadrt modname |
(unload realtime module) Unloads a realtime HAL module called modname. If modname is "all", it will unload all currently loaded realtime HAL modules. unloadrt also works by execing emc_module_helper or rtapi_app, just like loadrt. |
loadusr [flags] unix-command |
(load Userspace component) Executes the given unix-command, usually to load a userspace component. [flags] may be one or more of: |
• |
-W to wait for the component to become ready. The component is assumed to have the same name as the first argument of the command. |
||
• |
-Wn name to wait for the component, which will have the given name. |
||
• |
-w to wait for the program to exit |
||
• |
-i to ignore the program return value (with -w) |
waitusr name |
(wait for Userspace component) Waits for user space component name to disconnect from HAL (usually on exit). The component must already be loaded. Usefull near the end of a HAL file to wait until the user closes some user interface component before cleaning up and exiting. |
unloadusr compname |
(unload Userspace component) Unloads a userspace component called compname. If compname is "all", it will unload all userspace components. unloadusr works by sending SIGTERM to all userspace components. |
unload compname |
Unloads a userspace component or realtime module. If compname is "all", it will unload all userspace components and realtime modules. |
newsig signame type |
(new signal) Creates a new HAL signal called signame that may later be used to connect two or more HAL component pins. type is the data type of the new signal, and must be one of "bit", "s32", "u32", or "float". Fails if a signal of the same name already exists. |
delsig signame |
(delete signal) Deletes HAL signal signame. Any pins currently linked to the signal will be unlinked. Fails if signame does not exist. |
sets signame value |
(set signal) Sets the value of signal signame to value. Fails if signame does not exist, if it already has a writer, or if value is not a legal value. Legal values depend on the signals’s type. |
stype name |
(signal type) Gets the type of signal name. Fails if name does not exist as a signal. |
gets signame |
(get signal) Gets the value of signal signame. Fails if signame does not exist. |
linkps pinname [arrow] signame |
(link pin to signal) Establishs a link between a HAL component pin pinname and a HAL signal signame. Any previous link to pinname will be broken. arrow can be "=>", "<=", "<=>", or omitted. halcmd ignores arrows, but they can be useful in command files to document the direction of data flow. Arrows should not be used on the command line since the shell might try to interpret them. Fails if either pinname or signame does not exist, or if they are not the same type type. |
linksp signame [arrow] pinname |
(link signal to pin) Works like linkps but reverses the order of the arguments. halcmd treats both link commands exactly the same. Use whichever you prefer. |
linkpp pinname1 [arrow] pinname2 |
(OBSOLETE - use net instead) (link pin to pin) Shortcut for linkps that creates the signal (named like the first pin), then links them both to that signal. halcmd treats this just as if it were: halcmd newsig pinname1 halcmd linksp pinname1 pinname1 halcmd linksp pinname1 pinname2 |
net signame pinname ... |
Create signname to match the type of pinname if it does not yet exist. Then, link signame to each pinname in turn. Arrows may be used as in linkps. |
unlinkp pinname |
(unlink pin) Breaks any previous link to pinname. Fails if pinname does not exist. |
setp name value |
(set parameter or pin) Sets the value of parameter or pin name to value. Fails if name does not exist as a pin or parameter, if it is a parameter that is not writable, if it is a pin that is an output, if it is a pin that is already attached to a signal, or if value is not a legal value. Legal values depend on the type of the pin or parameter. If a pin and a parameter both exist with the given name, the parameter is acted on. |
paramname = value |
pinname = value |
Identical to setp. This alternate form of the command may be more convenient and readable when used in a file. |
ptype name |
(parameter or pin type) Gets the type of parameter or pin name. Fails if name does not exist as a pin or parameter. If a pin and a parameter both exist with the given name, the parameter is acted on. |
getp name |
(get parameter or pin) Gets the value of parameter or pin name. Fails if name does not exist as a pin or parameter. If a pin and a parameter both exist with the given name, the parameter is acted on. |
addf functname threadname |
(add function) Adds function functname to realtime thread threadname. functname will run after any functions that were previously added to the thread. Fails if either functname or threadname does not exist, or if they are incompatible. |
delf functname threadname |
(delete function) Removes function functname from realtime thread threadname. Fails if either functname or threadname does not exist, or if functname is not currently part of threadname. |
start |
Starts execution of realtime threads. Each thread periodically calls all of the functions that were added to it with the addf command, in the order in which they were added. |
||
stop |
Stops execution of realtime threads. The threads will no longer call their functions. |
show [item] |
Prints HAL items to stdout in human readable format. item can be one of "comp" (components), "pin", "sig" (signals), "param" (parameters), "funct" (functions), or "thread". The type "all" can be used to show matching items of all the preceeding types. If item is omitted, show will print everything. |
item |
This is equivalent to show all [item]. |
save [item] |
Prints HAL items to stdout in the form of HAL commands. These commands can be redirected to a file and later executed using halcmd -f to restore the saved configuration. item can be one of the following: "comp" generates a loadrt command for realtime component. "sig" generates a newsig command for each signal, and "sigu" generates a newsig command for each unlinked signal (for use with netl and netla). "link" and "linka" both generate linkps commands for each link. (linka includes arrows, while link does not.) "net" and "neta" both generate one newsig command for each signal, followed by linksp commands for each pin linked to that signal. (neta includes arrows.) "netl" generates one net command for each linked signal, and "netla" generates a similar command using arrows. "param" generates one setp command for each parameter. "thread" generates one addf command for each function in each realtime thread. If item is omitted, save does the equivalent of comp, sigu, link, param, and thread. |
source filename.hal |
Execute the commands from filename.hal. |
After a command is read but before it is executed, several types of variable substitution take place. |
Environment Variables |
Environment variables have the following formats: |
$ENVVAR followed by end-of-line or whitespace $(ENVVAR) |
Inifile Variables |
Inifile variables are available only when an inifile was specified with the halcmd -i flag. They have the following formats: |
[SECTION]VAR followed by end-of-line or whitespace [SECTION](VAR) |
None known at this time. |
Original version by John Kasunich, as part of the Enhanced Machine Controller (EMC) project. Now includes major contributions by several members of the project. |
Report bugs to the emc bug tracker. |
Copyright © 2003 John Kasunich. |