Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: coyotegd on September 13, 2007, 02:55:46 PM
-
I'm in Screen4, I've created a new button. However, after reviewing Wiki, I still do not have a clue as to how to attach a VB macro to the button's press event.
Can someone list code that will toggle "Enable 1" on and off when the button is pressed?
Given that I now have "toggle Enable 1" VB code in a macro, how do I attach it to the button's press event?
I need specific instructions as I can't find the answers in Wiki. Too confused I guess.
-
In screen 4 you click on the button. You can choose system function, oem code, g code, or VB script function edited in Mach 3, Choose the VB script function. Once you have mach open with the edited screen, look at the top tabs, operator, edit button script. The button you added should now be blinking with the others that are VB buttons. Click on it and insert your code, close and save. That should do it.
Brett
-
Yes. I follow you completely. Thanks. I just didn't understand the procedure.
Regarding the actual button macro, is there a toggle function?
If not, how do you test for "Enable 1" on or off?
I found this at Wiki:
ActivateSignal(Enable1) and DeActivateSignal(Enable1)
However, when the button is pressed, "Enable 1" needs to toggle from one to the other. Will the following work?
AuxPwr = GetParam("Enable1")
If NOT AuxPwr Then
ActivateSignal(Enable1)
Else
DeActivateSignal(Enable1)
End If
I tried this in the diagnostics page, but the Enable 1 LED did not blink. Do I need to turn the Enable 1 LED on and off or will the fact that the signal is turning on and off affect the LED?
Am I using the correct functions? The correct syntax?
Help!
-
Enable 1 LED is OEM code 846. Place and led on your screen and assign it oem code 846
Get OEMLed (846)
If OemLed(846,1) Then
DeActivateSignal(Enable1)
Else
ActivateSignal(Enable1)
EndIf
Tyr this, I'm no VB guru so be careful. I havent had time to try it.
-
very rusty with VB, in fact I dont think it could even be classed as rust because the little VB I did know would hardly be enough to turn to rust :D
Anyway what you might want to do is use the macro pump to switch your enables. Put a User LED on the screen and a button to toggle it. You tell the macropump to look at the user LED then you can toggle the LED by putting VB in the button something like
If GetUserLED (***) Then
SetUserLED ***, 0
Else
SetUserLED ***, 1
End If
Hope this helps cause I dont have a clue what I have just written :D
Hood
-
Nope, my version doesn't work. :( I will try to play with it later if someone else doesn't get you sorted soon.
Brett
-
I think I need to clarify what I am trying to do. I have created a screen (just the diagnostics screen with an additional button) that includes an "Aux Pwr Toggle" button. I want to make the Enable 1 output active, which will then trigger a relay that supplies 120VAC to an outlet on the back of my Mill's driver box.
I would like to create a macro for the "Aux Pwr Toggle" button that does two things: (1) it makes Enable 1 output active and toggles it on and off; and (2) when Enable 1 is active Enable 1 LED on the diagnostics screen blinks. I don't know if blinking is automatic or not. I hope it is.
I can't get a my button's macro to do this. Can someone please supply the necessary code.
Thanks you
-
OK, Got some help from the Guru himself. This works, just make sure tah enable 1 is enabled in ports and pins. I tested it hear and it works a treat. :)
test = GetOEMLed (846)
If (test = true) Then
DeActivateSignal(Enable1)
Else
ActivateSignal(Enable1)
End If
Brett
-
Bingo. Thank you. I've got it working, but I changed from "Enable 1" output to "Output 6". When I start Mach3, "Enable 1" begins active, and although I know I could use a start-up macro to turn "Enable 1" off by placing the start-up macro's name in the "Initialization String" textbox on the "General Config..." page, I decided to use the following code, and it works great:
Option Explicit
Dim Test As Boolean
Test = GetOEMLED (79)
If (Test = True) Then
DeActivateSignal(Output6)
Else
ActivateSignal(Output6)
End If
I need to work on my understanding of Mach3's functions, OEM codes, and user created stuff. Once I know those, my VB is pretty good, and I'll pick up on how to implement macros. I found the following to work exactly like the code above:
If GetOEMLED (79) Then
DeActivateSignal(Output6)
Else
ActivateSignal(Output6)
End If
It's interesting to me and seems a bit unorthodox to check the LED rather than the signal itself to see if the signal is active or not, but as long as it works, it's fine with me. I see that by activating the output, the LED turns on automatically. That is, I'm not required to activate the output and turn on the LED too.
-
Glad you got it. :)
Brett
-
This will also work:
If GetOEMLed (846) Then
DeActivateSignal(ENABLE1)
Else
ActivateSignal(ENABLE1)
End If
Further: Open sceen designer (like screen 3 or 4), open the screen in it, goto page 5 the diag page, double click the Enable 1 Led, when the window opens, look up top, and click the button that says "blink" the led. hit OK, and save the screen set. and reopen in mach, but the above VB in your button.
scott
-
I didn't realize you could do that with the LED. I like the blinking LED better than solid, and if I implement Enable 1 through 6 in another way, I'll have them blink. However, whether I made "Enable 1" output active high or low, Mach3 makes the output active when Mach3 starts up. I need the output to start deactivated, so I will continue to use Output 6, which starts deactivated.
-
Your Enable Outputs are special outputs, they turn on with mach comming up to enable things once mach is up. Like spindle enables etc.
there are OUTPUTS 1-20
-
That gives me an idea. I struggled with my microchip programming and the charge pump 12.5kHz signal output to my breakout board. The charge pump, for me anyway, is not a clean signal, and my microchip could not count the frequency properly. Now, however, I can just use "Enable 1" to activate when Mach3 starts up. The active signal on "Enable 1" will be a clear low signal for my microchip to read and thereby enable my stepper drivers. Cool.
Now I can forget the charge pump and it's "watchdog timer" function. Whatever purpose that serves. The Mach3 manual states that the charge pump is the signal to show when Mach3 is up and running, but if the Enable outputs are active when Mach3 starts up, they can serve the same purpose.
-
Well I must be doing something simple wrong. Everthing worls as described to attach code to a button, except that the button still contains "None" after the save. Did I save to the wrong location? I am using Mach Turn, where should the .m1s file be saved to?
Getting close but no cigars yet
-
Download and open up screen3, then open up your button, there is a window that has your vb in it, to the left of that window are 3 radio buttons, make sure you have the Run VB button checked.
-
okay, not sure why I cant do that in screen4, but it worked in screen3 and the code shows up in Mach3.
Dim Len, SD, FD, SR, FR, TD, ClearZ, I
SD = GetOEMDRO(1111)
SR = SD / 2
FD = GetOEMDRO(1112)
FR = FD / 2
TD = GetOEMDRO(1113)
Len = GetOEMDRO(1110)
ClearZ = SR + .1
Code "G18 G40 G49 G90 G94 G50 M48 G80"
Code "G0 Z" & ClearZ
Code "G0 X0"
Code "M3"
for I = SR To FR Step -0.01
Code "G1 Z" & I
Code "G1 X" & Len - TD & "F6"
Code "G0 Z" & ClearZ
Code "G0 X0"
Next I
Code "G1 Z" & FR
Code "G1 X" & Len - TD
Code "G0 Z" & ClearZ
Code "G0 X0"
Code "M30"
however nothing goes into the code window on the screen, now what am I doing wrong?
-
copy and paste all that script into the "Window" once you open up the dialog window in screen 3, tick the button execute vb script,
hit ok, Then goto the file menu and hit Save.......... Then load your screen and test.
scott
-
Been following this thread and want to do something similar. Would like to activate output 4 whenever the enable 1 led is active or whenever Mach is online and not in reset.
Enabled Output 4 in Config/Ports & Pins/Outputs and tried both active high and active low.
Saved the following code as test.m1s under macros\mach3 mill, restarted Mach3 mill with no compile errors but Output 4 does not change when the Reset button is toggled.
Any one have any ideas as to what I am missing?
Thanks,
Claude
If GetOEMLed (846 = true) Then
ActivateSignal(OUTPUT4)
Else
DeActivateSignal(OUTPUT4)
End If
-
Try this,
If GetOEMLed (846,1) Then
ActivateSignal (OUTPUT4)
Else
DeActivateSignal (OUTPUT4)
End If
-
If GetOEMLed (846 = true) Then
ActivateSignal(OUTPUT4)
Else
DeActivateSignal(OUTPUT4)
End If
your code should be:
If GetOEMLed (846) Then
You probably meant
If GetOEMLed (846) = true Then
But there's no need to test against true - that's what 'if' does anyway.
-
Here use this brain, it does what you want.
scott
-
Stirling,
Re wrote the macro as you suggested and when stepping through it using the VB script editor it functions perfectly. However after I save, close Mach3 and reopen it doesn't activate the Output 4 led on the diagnostics page. I have Output 4 enabled and set to Port 1, pin 17.
Any ideas?
Poppabear,
Your brain download indicates it is a zip file but when I download it shows as a .efw file which I have no idea what that is and if I try to open, nothing happens.
Downloaded and installed the latest lockdown version of Mach3 and tried writing a simple brain myself but when I try and enable it I get and ArtCode 9991 and it shuts Mach down.
The brains look to be much easier that the VB scripting and really cool.
Any suggestions here?
Thanks guys,
Claude
-
claude,
I downloaded my own zip and it is correct the file in it called "enable.brn", is the brain file you need to put that file in your Brian folder under machs main directory. Then you need to goto operator and enable the brain called enable, then test it.
scott
-
here is a screen shot of your brian working in mach. unzip the file and put the file "enable.brn" into the Brains folder under mach3, then open up mach3, goto operator and brain control, hit reload all brains, highlight ebable.bran , and hit the tick box enable. Then you can hit the View brain and see everything being green meaning it is working. You can also view the leds on the diag page.
scott
-
However after I save, close Mach3 and reopen it doesn't activate the Output 4 led on the diagnostics page.
just writing and saving a macro doesn't mean you've told Mach to run it.
But take a step back a moment - why are you trying to do this? if output pin enable1 has the state pattern you want then why not just use it? - why copy it to another output pin? - they're all just pins after all.
-
Scott,
Tried downloading both the original file you posted and also the one with the screen shot post and in both cases Windows download popup showed the file as "enable.1.321CO2.efw". No mention of a .zip file.
After playing "Brains" all yesterday I finally came up with the same as you show in your screen shot and it is working fine. Think most of my difficulty stems from not fully understanding how the Brains function as well as the specific conventions used in Mach. Things are looking up now and the capabilities of Brains is very exciting.
Stirling,
That particular brain was just an example for my own learning experience. I did however "and" it with another input to turn on a hydraulic pump and now have that Brain working as well. The logic tells the pump to turn on whenever Mach is online (reset green) "and" the offline button is not active. Still need to wire in the relay for the pump.
Thanks guys for all your help. I am sure I will be back with other questions.
Claude