# Is there a way to prevent Relay 2 from being turned off at the end of a program?

**URL:** <https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074>\
**Category:** General Chat\
**Created:** [October 27, 2022, 11:27pm UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074 "2022-10-27T23:27:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![DoodlerJeff](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@DoodlerJeff](https://forum.avidcnc.com/u/DoodlerJeff)\
**Post date:** [October 27, 2022, 11:27pm UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/1 "2022-10-27T23:27:29Z")

</div>

I use VCarve Desktop to generate MCode and Mach4 to control my 24x24 standard desktop machine using the Avid post processer. I recently purchased some vacuum pods to hold down work pieces. It works great, but I found that the end of the program turns off relay 2, which I used to turn on the vacuum pump. I made a custom processer removing the M09 code that turns off the relays. However it still turns off and I found the M30 at the end does the same thing. Is it possible to replace M30 with other gcodes to end the program to avoid turning off relay 2? I certainly can not use it for the vacuum pump, but it seemed convenient to use it for this purpose.

---

<div class="post-metadata">

**Author:** ![jjneeb](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.avidcnc.com/jjneeb/32/244_2.png) [@jjneeb](https://forum.avidcnc.com/u/jjneeb)\
**Post date:** [October 28, 2022, 12:22am UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/2 "2022-10-28T00:22:11Z")

</div>

Just to be clear, you just want a Mach4 button on the screen then to control the vacuum, not have Gcode to turn it on or off?

---

<div class="post-metadata">

**Author:** ![DoodlerJeff](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@DoodlerJeff](https://forum.avidcnc.com/u/DoodlerJeff)\
**Post date:** [October 28, 2022, 1:28am UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/3 "2022-10-28T01:28:15Z")

</div>

I was using the Relay 2 button to turn on and off the vacuum pump and I don’t want the program to turn it off when it’s done so I can change bits and run another program without moving the piece. If it can’t be done I’ll just turn the pump on and off manually, but I thought this way was convenient.

---

<div class="post-metadata">

**Author:** ![jjneeb](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.avidcnc.com/jjneeb/32/244_2.png) [@jjneeb](https://forum.avidcnc.com/u/jjneeb)\
**Post date:** [October 28, 2022, 4:47am UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/4 "2022-10-28T04:47:52Z")

</div>

Interesting, I never realized the M30 would turn off the relays, but it sure does. So the spare outputs on the ESS can be used (controlled with the M64/M65 codes) to run the relay instead, but I don’t know if those will also be affected by the M30. Are you interested in rewiring one of the relays and creating a button in your screen that uses the M64/65 commands? If so I can go do an experiment to see if that will work or not. I just want to make sure thats not beyond your threshold for work on this before I do the experiment 🙂

---

<div class="post-metadata">

**Author:** ![DoodlerJeff](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@DoodlerJeff](https://forum.avidcnc.com/u/DoodlerJeff)\
**Post date:** [October 28, 2022, 12:17pm UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/5 "2022-10-28T12:17:40Z")

</div>

Well it wouldn’t be beyond my threshold to do that, but I was hoping that there might be a setting I missed somewhere that might control this, or if I could avoid using M30 altogether. I’m going to experiment with that today.

---

<div class="post-metadata">

**Author:** ![jjneeb](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.avidcnc.com/jjneeb/32/244_2.png) [@jjneeb](https://forum.avidcnc.com/u/jjneeb)\
**Post date:** [October 28, 2022, 3:05pm UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/6 "2022-10-28T15:05:57Z")

</div>

I was just reading on the M30. It is a program end and reset. Its supposed to reset everything that was set in the program. There is an M02 that is just end without the reset. So try replacing the M30 with an M02 and see if that leaves your relay on. You will have to make sure that you have all the Gcode to turn off everything that you turned on since the M30 will no longer do cleanup.

---

<div class="post-metadata">

**Author:** ![subnoize](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.avidcnc.com/subnoize/32/2197_2.png) [@subnoize](https://forum.avidcnc.com/u/subnoize)\
**Post date:** [October 28, 2022, 3:07pm UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/7 "2022-10-28T15:07:31Z")

</div>

You can create your own m30 and do what you want with it. See this forum for more info; [Can i edit or add to a Predefined Macro?](https://www.machsupport.com/forum/index.php?topic=33831.0)

Find smurph’s response.

I would avoid using anything other than m30 at the end. The reason is Mach4 has two “included for free” functions that you MUST execute at the end. Not doing so leaves Mach4 in a bad state.

---

<div class="post-metadata">

**Author:** ![subnoize](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.avidcnc.com/subnoize/32/2197_2.png) [@subnoize](https://forum.avidcnc.com/u/subnoize)\
**Post date:** [October 28, 2022, 3:57pm UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/8 "2022-10-28T15:57:12Z")

</div>

Ok, “MUST” might be a bit strong but “cycle stop” is pretty important.

---

<div class="post-metadata">

**Author:** ![DoodlerJeff](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@DoodlerJeff](https://forum.avidcnc.com/u/DoodlerJeff)\
**Post date:** [October 28, 2022, 10:06pm UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/9 "2022-10-28T22:06:49Z")

</div>

After a bit further research I came upon this well done page describing the Program Stop functions: [PROGRAM STOP AND PROGRAM END (M00, M01, M02, AND M30)](https://tormach.com/program-stop-and-program-end-m00-m01-m02-and-m30)

Based on what it said I replaced the M30 with this code:

G17  
G90  
G94  
M48  
G40  
G01  
M00

…it doesn’t rewind to the start of the program, but I can just hit the rewind button for that.

Even though I seldom run the same program twice in a row I ran one using this code several times with no problems. And it never turned off my vacuum pump.

---

<div class="post-metadata">

**Author:** ![subnoize](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.avidcnc.com/subnoize/32/2197_2.png) [@subnoize](https://forum.avidcnc.com/u/subnoize)\
**Post date:** [October 29, 2022, 4:41am UTC](https://forum.avidcnc.com/t/is-there-a-way-to-prevent-relay-2-from-being-turned-off-at-the-end-of-a-program/1074/10 "2022-10-29T04:41:20Z")

</div>

Yay!

A lot of folks never realize just how much you can configure. I am sure if you keep playing with it you can figure out why it doesn’t rewind though. But, that is a nice to have and not required.
