Run script when exiting LinuxCNC
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 255
10 Aug 2020 12:53 - 20 Aug 2020 12:47 #177813
by anfänger
[solved] Run script when exiting LinuxCNC was created by anfänger
Hello,
I want to switch my compressor of when exiting LinuxCNC.
I need to rum my compressor when rumhingt my CNC but I sometimes forget to switch it of when leaving the shop.
So I want to use a wifi relay to switch it on and of by running a bash script. On start this is not a problem (RS274NGC_STARTUP_CODE does the trick).
Is there a way to use the shutdown.hal to trigger this bash script. Or is there another way to trigger scripts on shutdown.
Thanks Patrick
I want to switch my compressor of when exiting LinuxCNC.
I need to rum my compressor when rumhingt my CNC but I sometimes forget to switch it of when leaving the shop.
So I want to use a wifi relay to switch it on and of by running a bash script. On start this is not a problem (RS274NGC_STARTUP_CODE does the trick).
Is there a way to use the shutdown.hal to trigger this bash script. Or is there another way to trigger scripts on shutdown.
Thanks Patrick
Last edit: 20 Aug 2020 12:47 by anfänger.
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19466
- Thank you received: 6529
10 Aug 2020 14:06 #177815
by tommylight
Replied by tommylight on topic Run script when exiting LinuxCNC
Are you using a Mesa boars?
Please Log in or Create an account to join the conversation.
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 255
10 Aug 2020 14:31 - 10 Aug 2020 14:34 #177817
by anfänger
Replied by anfänger on topic Run script when exiting LinuxCNC
Yes,
But the compressor is switched with an wifi relay, so I can also use it without the CNC if needed.
If there is no way to use LinuxCNC ist self I will do this when shutting down Linux, but I would prefer to include it to LinuxCNC, it‘s already of even if I do some other work on the computer.
But the compressor is switched with an wifi relay, so I can also use it without the CNC if needed.
If there is no way to use LinuxCNC ist self I will do this when shutting down Linux, but I would prefer to include it to LinuxCNC, it‘s already of even if I do some other work on the computer.
Last edit: 10 Aug 2020 14:34 by anfänger.
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19466
- Thank you received: 6529
10 Aug 2020 14:47 #177818
by tommylight
Replied by tommylight on topic Run script when exiting LinuxCNC
Mesa resets the pins on lost connection, so you can use one of the outputs to control the compressor, most probably the
estop_out
pin
estop_out
pin
Please Log in or Create an account to join the conversation.
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 255
10 Aug 2020 14:54 - 10 Aug 2020 15:01 #177819
by anfänger
Replied by anfänger on topic Run script when exiting LinuxCNC
Then I would go for the Linux shutdown script. I don’t want to use the Mesa card it self cause then I also could just connect the compressor to machine power. But I want to be able to use the compressor without the machine.
Last edit: 10 Aug 2020 15:01 by anfänger.
Please Log in or Create an account to join the conversation.
- Grotius
- Offline
- Platinum Member
Less
More
- Posts: 2244
- Thank you received: 1984
10 Aug 2020 15:10 #177823
by Grotius
Replied by Grotius on topic Run script when exiting LinuxCNC
Hi,
For shutdown, you can add a hal file to disconnect what you want to.
linuxcnc.org/docs/devel/html/config/ini-config.html
SHUTDOWN = shutdown.hal - Execute the file shutdown.hal when LinuxCNC is exiting. Depending on the hardware drivers used, this may make it possible to set outputs to defined values when LinuxCNC is exited normally. However, because there is no guarantee this file will be executed (for instance, in the case of a computer crash) it is not a replacement for a proper physical e-stop chain or other protections against software failure.
For shutdown, you can add a hal file to disconnect what you want to.
linuxcnc.org/docs/devel/html/config/ini-config.html
SHUTDOWN = shutdown.hal - Execute the file shutdown.hal when LinuxCNC is exiting. Depending on the hardware drivers used, this may make it possible to set outputs to defined values when LinuxCNC is exited normally. However, because there is no guarantee this file will be executed (for instance, in the case of a computer crash) it is not a replacement for a proper physical e-stop chain or other protections against software failure.
Please Log in or Create an account to join the conversation.
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 255
10 Aug 2020 17:16 #177828
by anfänger
Replied by anfänger on topic Run script when exiting LinuxCNC
its not for Estop.
Would a setp halui.mdi-command-01 true work with shutdown.hal?
I think I'lll try it later
Would a setp halui.mdi-command-01 true work with shutdown.hal?
I think I'lll try it later
Please Log in or Create an account to join the conversation.
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 255
10 Aug 2020 19:39 #177835
by anfänger
Replied by anfänger on topic Run script when exiting LinuxCNC
does not work I think the command comes to late:
I'll keep searching or use linux shutdown
Shutting down and cleaning up LinuxCNC...
Running HAL shutdown script
hm2_eth: HostMot2 ethernet driver unloaded
hm2: unloading
Note: Using POSIX realtime
igor@igor:~/Schreibtisch$ halui: emcCommandSend: no echo from Task after 5.000 seconds
halui: sendMdiCommand: failed to send mdi command 20
I'll keep searching or use linux shutdown
Please Log in or Create an account to join the conversation.
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 255
20 Aug 2020 12:46 - 20 Aug 2020 18:34 #178821
by anfänger
Replied by anfänger on topic Run script when exiting LinuxCNC
I have started to take a look at python and wrote a python script with a hal connection. This did the trick:
This is loaded in my Postgui file and connected to a gui button which is on by default.
This is loaded in my Postgui file and connected to a gui button which is on by default.
#!/usr/bin/python
import time
import hal
import urllib3
import atexit
import time
delta_t = 1 # seconds poll interval, hold inputs at least this long
#hal
h = hal.component("compressor")
h.newpin("active",hal.HAL_BIT,hal.HAL_IN)
h.ready()
def finaloff():
r = http.request('GET', 'http://192.168.178.89/relay/1?turn=off')
atexit.register(finaloff)
old_start_pin_value = False
started = False
http = urllib3.PoolManager()
while True:
time.sleep(delta_t)
#print h["active"]
start_pin_value = h["active"]
if start_pin_value != old_start_pin_value:
#print("changed")
if started:
started = False
print("compressor off")
r = http.request('GET', 'http://192.168.178.89/relay/1?turn=off')
else:
started = True
print("compressor on")
r = http.request('GET', 'http://192.168.178.89/relay/1?turn=on')
old_start_pin_value = start_pin_value
Last edit: 20 Aug 2020 18:34 by anfänger.
Please Log in or Create an account to join the conversation.
- anfänger
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 626
- Thank you received: 255
20 Aug 2020 19:16 #178855
by anfänger
Replied by anfänger on topic Run script when exiting LinuxCNC
And here the proof
Thanks for the help
Thanks for the help
The following user(s) said Thank You: tommylight, Himarc3D
Please Log in or Create an account to join the conversation.
Time to create page: 0.071 seconds