conditional postgui.hal
25 Mar 2017 13:52 #90248
by vph
conditional postgui.hal was created by vph
Hi all,
I have an usb pendant which is not always plugged in.
Is it possible to include its hal-file depending on whether the pendant is plugged in or not.
Thanks,
vph
I have an usb pendant which is not always plugged in.
Is it possible to include its hal-file depending on whether the pendant is plugged in or not.
Thanks,
vph
Please Log in or Create an account to join the conversation.
25 Mar 2017 18:08 #90254
by cmorley
Replied by cmorley on topic conditional postgui.hal
Not built in to HAL but one could write a python HAL component that would check for the pendant pins and connect the pins accordingly.
I have often thought this would be a good feature to have but never got to the point of building it.
Chris M
I have often thought this would be a good feature to have but never got to the point of building it.
Chris M
Please Log in or Create an account to join the conversation.
25 Mar 2017 18:15 #90255
by vph
Replied by vph on topic conditional postgui.hal
Thank you Chris!
I already started making a hal component doing that but wanted to make sure it doesn't already exist and not wasting time.
Best Regards,
Filip A.
I already started making a hal component doing that but wanted to make sure it doesn't already exist and not wasting time.
Best Regards,
Filip A.
Please Log in or Create an account to join the conversation.
25 Mar 2017 23:17 #90269
by cmorley
Replied by cmorley on topic conditional postgui.hal
If you are using python and the hal module..
note there are undocumented functions that would help:
component_exists()
component_is_ready()
connect()
new_sig( signal_name,type )
set_p()
Chris M
note there are undocumented functions that would help:
component_exists()
component_is_ready()
connect()
new_sig( signal_name,type )
set_p()
Chris M
Please Log in or Create an account to join the conversation.
26 Mar 2017 05:07 - 26 Mar 2017 05:09 #90280
by cmorley
Replied by cmorley on topic conditional postgui.hal
So I went ahead and created a python program that optionally loads commands.
This is of course only one way it could be done.
Here is the program:
This I saved as try_loader and made it executable.
In my custom_postgui.hal file I added:
loadusr -w try_loader
I then added two other HAL file to my config:
try_options.hal
Which has the single command to load my USB joystick:
try_success.hal
Which connects the joystick to halui:
If I have a joystick connected it allows it to jog my X axis.
If I do not I will get a little bit of noise in the terminal (if it is showing):
No input devices could be opened. This usually indicates a misconfigured
system. Please read the section 'PERMISSIONS AND UDEV' in the hal_input
manpage
try_options.hal:1: waitpid failed hal_input hal_input
try_options.hal:1: hal_input exited without becoming ready
**** TRY LOADER Info: Optional equipment not connected ****
but the config continues to load with no problems.
The try_loader program tries to load the first HAL file and if it succeeds, it will load the second file.
If the second file has errors it will stop the config and display the errors.
If the first HAL file doesn't succeeded, then it doesn't try to load the second and just carried on.
Hope that helps someone.
Chris M
This is of course only one way it could be done.
Here is the program:
#!/usr/bin/python
import hal
import os
# load the HAL file 'try_optional.hal'
# This would have commands that if fail, will not stop the config from running.
# such as trying to load a USB joystick
res = os.spawnvp(os.P_WAIT, "halcmd", ['halcmd' , '-k', '-Q', '-f', 'try_options.hal'])
# If there was no error in loading the optional file
# then load the 'try_success.hal' file
# this would have commands to connect the optional pins to signals
# this will stop the config if there are errors
if not res:
res = os.spawnvp(os.P_WAIT, "halcmd", ['halcmd' ,"-f", "try_success.hal"])
if res:
print '**** TRY LOADER ERROR: try_sucess.hal file Error'
raise SystemExit, res
else:
print '**** TRY LOADER Info: Optional equipment not connected ****'
This I saved as try_loader and made it executable.
In my custom_postgui.hal file I added:
loadusr -w try_loader
I then added two other HAL file to my config:
try_options.hal
Which has the single command to load my USB joystick:
loadusr -W hal_input -KRAL Mega
try_success.hal
Which connects the joystick to halui:
net jog-x-pos halui.axis.x.plus input.0.abs-x-is-pos
net jog-x-neg halui.axis.x.minus input.0.abs-x-is-neg
setp halui.axis.jog-speed 10
If I have a joystick connected it allows it to jog my X axis.
If I do not I will get a little bit of noise in the terminal (if it is showing):
No input devices could be opened. This usually indicates a misconfigured
system. Please read the section 'PERMISSIONS AND UDEV' in the hal_input
manpage
try_options.hal:1: waitpid failed hal_input hal_input
try_options.hal:1: hal_input exited without becoming ready
**** TRY LOADER Info: Optional equipment not connected ****
but the config continues to load with no problems.
The try_loader program tries to load the first HAL file and if it succeeds, it will load the second file.
If the second file has errors it will stop the config and display the errors.
If the first HAL file doesn't succeeded, then it doesn't try to load the second and just carried on.
Hope that helps someone.
Chris M
Last edit: 26 Mar 2017 05:09 by cmorley.
Please Log in or Create an account to join the conversation.
26 Mar 2017 13:24 #90285
by vph
Replied by vph on topic conditional postgui.hal
Thanks a lot Chris! That was fast. For my purposes I was thinking to just check if the serial port is created and then load the rest. But your way is much better and more complete.
Regards,
Filip A.
Regards,
Filip A.
Please Log in or Create an account to join the conversation.
27 Mar 2017 10:40 #90344
by andypugh
You can (optionally) write HAL files in Tcl.
linuxcnc.org/docs/2.7/html/hal/haltcl.html
I think that this would allow you to quietly ignore the pendant when it was not present.
Replied by andypugh on topic conditional postgui.hal
Is it possible to include its hal-file depending on whether the pendant is plugged in or not.
You can (optionally) write HAL files in Tcl.
linuxcnc.org/docs/2.7/html/hal/haltcl.html
I think that this would allow you to quietly ignore the pendant when it was not present.
Please Log in or Create an account to join the conversation.
Time to create page: 0.069 seconds