Why doesn't my button script work?
- djreiswig
- 4.5 Star Elite Contributing Member
- Posts: 2071
- Joined: Thu Nov 19, 2015 10:02 pm
- Location: SE Nebraska
Why doesn't my button script work?
I have the attached button script I want to use for referencing my Z. I have a button on my screen to switch between using my z switch and my ohmic for referencing. I have created a reference macro to use in sheetcam that looks at an LED that is turned on and off by the button and uses it to determine if it should reference using the switch or the ohmic.
The macro code is just a duplicate of what my post processor used to put in the gcode. Now it just calls the macro instead. It seems to work fine when I run it from gcode, but I wanted to make the Z REF button work similarly. I tried just calling the macro from the button, but I couldn't get it to work. It just kept giving me an error, so I attempted to duplicate the macro code in a button script. I had to make a couple of changes, but I think I have it figured out.
The G31 using the probe input works fine. The G28.1 with the switch seems to raise up a little more each time I click the button. It drops and touches, then over runs into the switch, then it backs up. The first time it stops on TOM, the next time it raises above the material. Each time I run it, it ends up higher. Something seems to be adding a little distance each time.
It won't work correctly again until I restart Mach. Then it goes back to TOM. It will work correctly if I step through the code from the button script editor. That's what has me confused.
The -.25 raise is used along with a block delete arrangement I have where I can turn on block delete and it ignores the torch firing and DTHC on settings and raises the torch .25 above the material and does a dry run. I commented that part out and it didn't make a difference.
I have attached the script. Any ideas on what might be wrong, or a better way to do this?
The macro code is just a duplicate of what my post processor used to put in the gcode. Now it just calls the macro instead. It seems to work fine when I run it from gcode, but I wanted to make the Z REF button work similarly. I tried just calling the macro from the button, but I couldn't get it to work. It just kept giving me an error, so I attempted to duplicate the macro code in a button script. I had to make a couple of changes, but I think I have it figured out.
The G31 using the probe input works fine. The G28.1 with the switch seems to raise up a little more each time I click the button. It drops and touches, then over runs into the switch, then it backs up. The first time it stops on TOM, the next time it raises above the material. Each time I run it, it ends up higher. Something seems to be adding a little distance each time.
It won't work correctly again until I restart Mach. Then it goes back to TOM. It will work correctly if I step through the code from the button script editor. That's what has me confused.
The -.25 raise is used along with a block delete arrangement I have where I can turn on block delete and it ignores the torch firing and DTHC on settings and raises the torch .25 above the material and does a dry run. I commented that part out and it didn't make a difference.
I have attached the script. Any ideas on what might be wrong, or a better way to do this?
- Attachments
-
- refscript.pdf
- (58.26 KiB) Downloaded 99 times
- refscript.pdf
- (58.26 KiB) Downloaded 99 times
2014 Bulltear (StarLab) 4x8
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
- acourtjester
- 6 Star Elite Contributing Member
- Posts: 8496
- Joined: Sat Jun 02, 2012 6:04 pm
- Location: Pensacola, Fla
Re: Why doesn't my button script work?
I do think the button script is in a different code language then G-code so a direct copy will not work.
attached is a button script I used to reposition the torch from a laser position
I needed to put the word code before the command and use parentheses at both ends which changes the code to red lettering.
I cannot write script just rearranged what another script did to work for me.
attached is a button script I used to reposition the torch from a laser position
I needed to put the word code before the command and use parentheses at both ends which changes the code to red lettering.
I cannot write script just rearranged what another script did to work for me.

DIY 4X4 Plasma/Router Table
Hypertherm PM65 Machine Torch
Drag Knife and Scribe
Miller Mig welder
13" metal lathe
Small Mill
Everlast PowerTig 255 EXT
Hypertherm PM65 Machine Torch
Drag Knife and Scribe
Miller Mig welder
13" metal lathe
Small Mill
Everlast PowerTig 255 EXT
- djreiswig
- 4.5 Star Elite Contributing Member
- Posts: 2071
- Joined: Thu Nov 19, 2015 10:02 pm
- Location: SE Nebraska
Re: Why doesn't my button script work?
Yes, scripts are in Cyprus Basic. Very much like Basic code. I'm baffled why it seems to work when I step through it. I thought maybe it was a timing thing so I added lots of Sleep lines, but it made no difference.
2014 Bulltear (StarLab) 4x8
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
- acourtjester
- 6 Star Elite Contributing Member
- Posts: 8496
- Joined: Sat Jun 02, 2012 6:04 pm
- Location: Pensacola, Fla
Re: Why doesn't my button script work?
I'm sure someone here will have your answer
DIY 4X4 Plasma/Router Table
Hypertherm PM65 Machine Torch
Drag Knife and Scribe
Miller Mig welder
13" metal lathe
Small Mill
Everlast PowerTig 255 EXT
Hypertherm PM65 Machine Torch
Drag Knife and Scribe
Miller Mig welder
13" metal lathe
Small Mill
Everlast PowerTig 255 EXT
-
- 4.5 Star Elite Contributing Member
- Posts: 1831
- Joined: Mon Jun 12, 2017 6:43 pm
Re: Why doesn't my button script work?
In the last few lines, why do you set g92 z0 and the move the axis up only to then reset g92 to the offset height again.
On your motion controller do you have a spare relay?
I ask because what I do with mine is I use g31 and then test if it is the ohmic or the floating input that is triggered and then set the offset accordingly.
You basically feed the omic probe input via a relay and the floating head input direct to the probe input. So that whichever is triggered will trigger the probe input ... Then you test and set accordingly all via macro.
I also have a similar bit of code to test for if the probe is active at the start of the probe and if the ohmic is already active I can drop the relay out, retest and the just use the floating head input
On your motion controller do you have a spare relay?
I ask because what I do with mine is I use g31 and then test if it is the ohmic or the floating input that is triggered and then set the offset accordingly.
You basically feed the omic probe input via a relay and the floating head input direct to the probe input. So that whichever is triggered will trigger the probe input ... Then you test and set accordingly all via macro.
I also have a similar bit of code to test for if the probe is active at the start of the probe and if the ohmic is already active I can drop the relay out, retest and the just use the floating head input
- djreiswig
- 4.5 Star Elite Contributing Member
- Posts: 2071
- Joined: Thu Nov 19, 2015 10:02 pm
- Location: SE Nebraska
Re: Why doesn't my button script work?
The reset is for if I am in block delete mode. If I'm not then I reset the z back to 0. Otherwise it stays at -0.25 so it will float higher above the material. My first thought was to use the same input and use a relay, but I thought I could save the hassle and just do it with code. I just can't figure out why it works fine when I step it, but not when I hit play or use the button.
2014 Bulltear (StarLab) 4x8
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
-
- 4.5 Star Elite Contributing Member
- Posts: 1831
- Joined: Mon Jun 12, 2017 6:43 pm
Re: Why doesn't my button script work?
I'm going through the code now (1st time in front of a laptop)
You have 1 syntax error on line 35
code "M00"
should be Code ("M00")
And another on line 8
code ("M00")
should be Code ("M00")
Why are you using block delete for switch offset???
You have 1 syntax error on line 35
code "M00"
should be Code ("M00")
And another on line 8
code ("M00")
should be Code ("M00")
Why are you using block delete for switch offset???
-
- 4.5 Star Elite Contributing Member
- Posts: 1831
- Joined: Mon Jun 12, 2017 6:43 pm
Re: Why doesn't my button script work?
It may be me here...
But where did you define DIGITIZE + ZHOME
DIGITIZE is OEMLED 825
Z HOME is OEMLED 836
The below code "MAY" work better......
This bit of your code did not make sense to me at all.....
First you zero'd the Z axis with G92 temporary offset
Then you told the machine to rapid move to switch offset
Then you told the machine to reset the temporary offset to Z-0.25.... (why)
but if block delete was NOT active.... set G92 Z to ZERO???
Have a look at my alternative code it may help you out....
NOTE: I am no longer a Mach3 user.... so my coding may be rusty (a little)... but as the responses seem slow I thought I'd try to help.
These are the Mach3 manuals I use to use:
http://www.machsupport.com/wp-content/u ... mmands.pdf
https://www.machsupport.com/wp-content/ ... og_Ref.pdf
https://www.machsupport.com/forum/index ... tach=27839
But where did you define DIGITIZE + ZHOME
DIGITIZE is OEMLED 825
Z HOME is OEMLED 836
The below code "MAY" work better......
Code: Select all
OhmicLED = 1503 ' LED that indicates OFF
TouchLED = 1504 ' LED that indicates ON
RefTypeRelay = 17 ' Output 8
If GetUserLED(OhmicLED) Then 'ohmic sensor touch off
If GetOEMLED(825) Then 'Probe Input (Digitize) Active
Response = MsgBox ("Ohmic sensor jammed. Clear and hit RUN to continue ", 4 ,
"Clear Z Jam")
Code("M0 (Program Stop)")
Else
ActivateSignal(RefTypeRelay) 'Turn on Ohmic
Sleep(200) 'allow relay time to toggle
Code("G00 Z" & GetUserDRO(1101) & " (Start probe touch-off)")
While (IsMoving())
'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code("G31 Z-3.937 F" & GetUserDRO(1100))
While (IsMoving())
'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
If GetOEMLED(66) Then 'trial Z offset
Code("G92 Z-0.25 (Trial Z offset)")
Else 'not trial Z offset
Code("G92 Z0.0")
End If
DeActivateSignal(RefTypeRelay) 'Turn OFF Ohmic
End If
Else
If GetUserLED(TouchLED) Then 'floating head touch off
If GetOEMLED(836) Then 'Z Home Active
Response = MsgBox ("Touch switch jammed. Clear and hit RUN to continue ", 4, "Clear Z Jam")
Code("M0 (Program Stop)")
Else
SwitchOffset = GetUserDRO(1045) 'switch offset
DeActivateSignal(RefTypeRelay) 'Turn on Touch
Sleep(200) 'allow relay time to toggle
Code("G28.1 Z" & GetUserDRO(1101) & " (Start touch-off)")
While (IsMoving())
'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
If GetOEMLED(66) Then 'trial Z offset
Code("G92 Z-" & SwitchOffset & " (Switch offset lift)")
Else 'not trial Z offset
Code("G92 Z0.0")
End If
End If
End If
This bit of your code did not make sense to me at all.....
Code: Select all
Code("G92 Z0.0")
Code("G00 Z" & SwitchOffset & " (Switch offset lift)")
While (IsMoving())
'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code("G92 Z -0.25 (Trial Z offset)")
While (IsMoving()) 'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
If Not GetOEMLED(66) Then 'not trial Z offset
Code("G92 Z0.0")
Then you told the machine to rapid move to switch offset
Then you told the machine to reset the temporary offset to Z-0.25.... (why)
but if block delete was NOT active.... set G92 Z to ZERO???
Have a look at my alternative code it may help you out....
NOTE: I am no longer a Mach3 user.... so my coding may be rusty (a little)... but as the responses seem slow I thought I'd try to help.
These are the Mach3 manuals I use to use:
http://www.machsupport.com/wp-content/u ... mmands.pdf
https://www.machsupport.com/wp-content/ ... og_Ref.pdf
https://www.machsupport.com/forum/index ... tach=27839
-
- 4.5 Star Elite Contributing Member
- Posts: 1831
- Joined: Mon Jun 12, 2017 6:43 pm
Re: Why doesn't my button script work?
Edited the code in previous post....
added in DeActivateSignal(RefTypeRelay) 'Turn OFF Ohmic
At the end of the 1st section
added in DeActivateSignal(RefTypeRelay) 'Turn OFF Ohmic
At the end of the 1st section
- djreiswig
- 4.5 Star Elite Contributing Member
- Posts: 2071
- Joined: Thu Nov 19, 2015 10:02 pm
- Location: SE Nebraska
Re: Why doesn't my button script work?
I think I figured it out. I was editing it from within mach, and for some reason it wasn't saving it. I used the screen editor and now it stays how I have it. I also added a couple of extra sleep loops after the G92 lines. It seems to be working as intended now.
To answer your questions...The parenthesis don't seem to be required, but I did add them back in. ZHOME and DIGITIZE are Mach output constants. You can use them like OUTPUT1, OUTPUT2, etc.
The last part of the code raises the Z an extra .25" if I have block delete active. I changed that around a little too. I originally had it in my post processor and that was the only way I could seem to get it to work. I got rid of the NOT and the double zeroing. I changed the DRO numbers as I must have had one that was already used somewhere because it wouldn't keep its value.
To answer your questions...The parenthesis don't seem to be required, but I did add them back in. ZHOME and DIGITIZE are Mach output constants. You can use them like OUTPUT1, OUTPUT2, etc.
The last part of the code raises the Z an extra .25" if I have block delete active. I changed that around a little too. I originally had it in my post processor and that was the only way I could seem to get it to work. I got rid of the NOT and the double zeroing. I changed the DRO numbers as I must have had one that was already used somewhere because it wouldn't keep its value.
Code: Select all
OhmicLED = 1503 ' LED that indicates OFF
TouchLED = 1504 ' LED that indicates ON
RefFeed = 1120 ' Ref Feed from Settings
PlungeSafety = 1121 ' Plunge Safety from Settings
TrialZ = 1122 ' Trial Z from Settings
RefTypeRelay =17 ' Output 8
SwitchOfset = 1045 ' Switch Offset from Settings
If GetUserLED(OhmicLED) Then
If IsActive(DIGITIZE) Then
Response = MsgBox ("Ohmic sensor jammed. Clear and hit RUN to continue ", 4 , "Clear Z Jam")
code ("M00")
Else
ActivateSignal(RefTypeRelay) 'Turn on Ohmic
Code("G00 Z" & GetUserDRO(PlungeSafety) & " (Start probe touch-off)")
While (IsMoving())
'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code("G31 Z -3.937 F" & GetUserDRO(RefFeed))
While (IsMoving())
'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code("G92 Z0.0")
While (IsMoving()) 'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
If GetOEMLED(66) Then 'trial Z offset
Code("G92 Z -" & GetUserDRO(TrialZ) & " (Trial Z offset)")
While (IsMoving()) 'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code ("G00 Z 0.0")
End If
End If
Else
If GetUserLED(TouchLED) Then 'touch
If IsActive(ZHOME) Then
Response = MsgBox ("Touch switch jammed. Clear and hit RUN to continue ", 4 , "Clear Z Jam")
code "M00"
Else
DeActivateSignal(RefTypeRelay) 'Turn on Touch
Code("G28.1 Z" & GetUserDRO(PlungeSafety) & " (Start touch-off)")
While (IsMoving())
'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code("G92 Z0.0")
While (IsMoving()) 'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code("G00 Z" & GetUserDRO(SwitchOffset) & " F" & GetUserDRO(RefFeed) & " (Switch offset lift)")
While (IsMoving())
'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code("G92 Z0.0")
While (IsMoving()) 'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
If GetOEMLED(66) Then 'trial Z offset
Code("G92 Z -" & GetUserDRO(TrialZ) & " (Trial Z offset)")
While (IsMoving()) 'Sleep, so other threads can run while we’re waiting
Sleep(100)
Wend
Code ("G00 Z 0.0")
End If
End If
End If
End If
2014 Bulltear (StarLab) 4x8
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
- djreiswig
- 4.5 Star Elite Contributing Member
- Posts: 2071
- Joined: Thu Nov 19, 2015 10:02 pm
- Location: SE Nebraska
Re: Why doesn't my button script work?
I appreciate your help. Its frustrating when you don't get any response. I was thinking my explanation wasn't clear.
I did add your last suggestion.
I did add your last suggestion.
Code: Select all
DeActivateSignal(RefTypeRelay) 'Turn OFF Ohmic
2014 Bulltear (StarLab) 4x8
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
-
- 4.5 Star Elite Contributing Member
- Posts: 1831
- Joined: Mon Jun 12, 2017 6:43 pm
Re: Why doesn't my button script work?
Documentation for mach3 has always been very poor.... No chance to fix it now though.....
It's sad that it was never finished off / developed further because it has such a following.
Cypress visual was so easy / logical....
Now using c# (uccnc) which is ok but syntax errors can be such a pain in the rear.
It's sad that it was never finished off / developed further because it has such a following.
Cypress visual was so easy / logical....
Now using c# (uccnc) which is ok but syntax errors can be such a pain in the rear.
- djreiswig
- 4.5 Star Elite Contributing Member
- Posts: 2071
- Joined: Thu Nov 19, 2015 10:02 pm
- Location: SE Nebraska
Re: Why doesn't my button script work?
I've done a little Arduino programming, which I believe is basically c#. It's pretty strange compared to the BASIC I'm used to.
2014 Bulltear (StarLab) 4x8
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)