Running an external program from a HAL pin
- pgf
- Offline
- Senior Member
-
Less
More
- Posts: 74
- Thank you received: 10
11 Apr 2025 18:01 - 11 Apr 2025 19:36 #326094
by pgf
Running an external program from a HAL pin was created by pgf
[ Damn. I edited the post to clarify some wording, and now the code blocks are broken. I'm not going to try to fix them. :-/ ]
I'd like to run an external program after an e-stop event. I thought it was going to be easy.
I have the program (which goes into the background, so there's no delay) in M101. M101 works when I invoke it via MDI.
I have a g-code snippet which invokes M101:
[/code][/code][/code]
I'd like to run an external program after an e-stop event. I thought it was going to be easy.
I have the program (which goes into the background, so there's no delay) in M101. M101 works when I invoke it via MDI.
I have a g-code snippet which invokes M101:
(subroutine which just runs my spindle off script)
o<my_spindle_off> sub
(MSG, my_spindle_off)
M101
o<my_spindle_off> endsub
That, in turn, is run via MDI_COMMAND, just like my homing and touch-off routines:
[code][HALUI]
MDI_COMMAND = o<reset_g54> call
MDI_COMMAND = o<auto_x_minus> call
MDI_COMMAND = o<auto_x_plus> call
MDI_COMMAND = o<auto_y_minus> call
MDI_COMMAND = o<auto_y_plus> call
MDI_COMMAND = o<auto_z_minus> call
MDI_COMMAND = o<home_x> call
MDI_COMMAND = o<home_y> call
MDI_COMMAND = o<home_z> call
MDI_COMMAND = o<reset_g54_rot> call
MDI_COMMAND = o<my_spindle_off> call
In custom.hal:
[code]loadrt estop_latch
addf estop-latch.0 servo-thread
net estop-loopout \
iocontrol.0.emc-enable-in <= estop-latch.0.ok-out
net estop-loopin \
iocontrol.0.user-enable-out => estop-latch.0.ok-in
net estop-reset \
iocontrol.0.user-request-enable => estop-latch.0.reset
net remote-estop \
estop-latch.0.fault-in <= hm2_7i96.0.gpio.003.in_not
And in custom_postgui.hal:
[code]net external-estop-off \
estop-latch.0.fault-out => halui.mdi-command-10
With halshow, I can see net external-estop-off and pin estop-latch.0.fault-out change state when I go in and out of e-stop state, but my command never runs. Ideas?
paul
Last edit: 11 Apr 2025 19:36 by pgf. Reason: clarification
Please Log in or Create an account to join the conversation.
- Aciera
-
- Offline
- Administrator
-
Less
More
- Posts: 4277
- Thank you received: 1890
11 Apr 2025 19:46 #326102
by Aciera
Replied by Aciera on topic Running an external program from a HAL pin
You cannot run an MDI_COMMAND when the controller is in estop. Try a python hal component that invokes your external program instead:
www.linuxcnc.org/docs/stable/html/hal/halmodule.html
www.linuxcnc.org/docs/stable/html/hal/halmodule.html
Please Log in or Create an account to join the conversation.
- pgf
- Offline
- Senior Member
-
Less
More
- Posts: 74
- Thank you received: 10
11 Apr 2025 19:58 #326103
by pgf
Replied by pgf on topic Running an external program from a HAL pin
Thanks. Seems like that restriction is a little too restrictive sometimes. :-/
But surely there's some other, event driven, mechanism, which wouldn't involve polling the pin every second or more?
But surely there's some other, event driven, mechanism, which wouldn't involve polling the pin every second or more?
Please Log in or Create an account to join the conversation.
- PCW
-
- Away
- Moderator
-
Less
More
- Posts: 18434
- Thank you received: 5034
11 Apr 2025 20:26 #326108
by PCW
Replied by PCW on topic Running an external program from a HAL pin
It does seem a bit dangerous and contrary to the purpose of EStop
to do motion commands automatically after an EStop event.
What is the intended operation and with what kind of EStop is further motion
safe?
to do motion commands automatically after an EStop event.
What is the intended operation and with what kind of EStop is further motion
safe?
Please Log in or Create an account to join the conversation.
- pgf
- Offline
- Senior Member
-
Less
More
- Posts: 74
- Thank you received: 10
11 Apr 2025 20:31 #326110
by pgf
Replied by pgf on topic Running an external program from a HAL pin
I want to shut off my spindle. (A Makita router.) I certainly won't be turning it on this way. And it would be a lot safer to do this than what I have now, which is "nothing". (From the software side, that is. The hardware switch on the mill does cut power to the spindle.)
As a less dangerous sounding example -- I'd also like to control my shop vacuum dust collector automatically. That's less likely to involve e-stop, but it would certainly be nice to shut it down automatically in that case.
As a less dangerous sounding example -- I'd also like to control my shop vacuum dust collector automatically. That's less likely to involve e-stop, but it would certainly be nice to shut it down automatically in that case.
Please Log in or Create an account to join the conversation.
- pgf
- Offline
- Senior Member
-
Less
More
- Posts: 74
- Thank you received: 10
11 Apr 2025 21:12 #326114
by pgf
Replied by pgf on topic Running an external program from a HAL pin
Also, I'm not wedded to doing this with MDI -- I'd much rather use an interface that didn't require editing four different config files just to get it setup. 
It seems like what I want should be part of halui somehow, but as far as I can tell, it's not.

It seems like what I want should be part of halui somehow, but as far as I can tell, it's not.
Please Log in or Create an account to join the conversation.
- PCW
-
- Away
- Moderator
-
Less
More
- Posts: 18434
- Thank you received: 5034
11 Apr 2025 21:12 #326115
by PCW
Replied by PCW on topic Running an external program from a HAL pin
How is the spindle controlled?
The spindle should be disabled by EStop
The spindle should be disabled by EStop
Please Log in or Create an account to join the conversation.
- pgf
- Offline
- Senior Member
-
Less
More
- Posts: 74
- Thank you received: 10
11 Apr 2025 21:16 #326117
by pgf
Replied by pgf on topic Running an external program from a HAL pin
Right. that's exactly what I'm trying to accomplish -- disable the spindle with EStop. The spindle is a Makita router, with an on-off switch. I'd like to simply plug it into one of my zigbee-controlled smart switches, which are trivial to control from just about anywhere. Obviously a hard-wired relay would be better, but it's only a hobby mill, and that's not going to happen anytime soon.
Please Log in or Create an account to join the conversation.
- Grotius
-
- Offline
- Platinum Member
-
Less
More
- Posts: 2376
- Thank you received: 2295
11 Apr 2025 21:27 - 11 Apr 2025 21:29 #326118
by Grotius
Replied by Grotius on topic Running an external program from a HAL pin
Hi,
Maybe we can use the zigbee-api
Then we make a tiny connection to the nml channel, as a client.
Then the zigbee can follow the emergency status. on - off.
Maybe we can use the zigbee-api
Then we make a tiny connection to the nml channel, as a client.
Then the zigbee can follow the emergency status. on - off.
Last edit: 11 Apr 2025 21:29 by Grotius.
Please Log in or Create an account to join the conversation.
- pgf
- Offline
- Senior Member
-
Less
More
- Posts: 74
- Thank you received: 10
11 Apr 2025 21:39 - 11 Apr 2025 21:46 #326120
by pgf
Replied by pgf on topic Running an external program from a HAL pin
I run Home Assistant (open source, no cloud involved) which does a good job of managing the devices. It's not the interface to zigbee that's the issue -- it's the interface to HAL. 
Is the NML channel documented somewhere? [ Edit: Never mind, I found it. No, I won't be going there... ]

Is the NML channel documented somewhere? [ Edit: Never mind, I found it. No, I won't be going there... ]
Last edit: 11 Apr 2025 21:46 by pgf.
Please Log in or Create an account to join the conversation.
Time to create page: 0.171 seconds