Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: JeffMach3 on August 06, 2019, 03:14:47 PM
-
Hi I am putting together a machine that requires a number of outputs, I have figured out how to turn them on and off using buttons on the screen, but I cannot turn them on in the program. I tried learning how to create an M-code in Mach4 Scripting Manual but it is not helpful for someone of my caliber. If you can help me make one that will work I can copy and make the changes for the additional outputs. I attached my feeble attempt, but it did not work (See attached) I noticed that there were M-codes that turned on/off outputs (M200-M228) but that did not seem to work. Any help would be appreciated. I am using Mach4 and Pokeys 57E
Jeff
-
Hi,
have a look at this thread.....they are sort of related:
https://www.machsupport.com/forum/index.php?topic=41580.0 (https://www.machsupport.com/forum/index.php?topic=41580.0)
So the question is whether you want to be able to turn the outputs on or off using m codes which are embedded
in your Gcode program or whether, like the other guy, use a GUI button to turn them on or off.
Note you could do both but would require macros in the macros folder that will be used by Gcode and a basically
indentical function in the screen load script that can be used by the GUI thread. Another way of 'skinning the same cat' is to
have a module.....but start simply and work up to that.
Craig
-
Hi Craig,
Thanks for your response. That is more complex than what I am looking for all I want to do is create an M-code that will turn on/off outputs. But I am not understanding how to create them. If I could be given an example of one then I could learn from what they did.
-
Hi,
That is more complex than what I am looking for all I want to do is create an M-code that will turn on/off outputs
Then you need to answer the question....do you want to be able to turn off from a button OR do you want to turn them on or
off as part of a Gcode job?
Craig
-
As part of the Goode
-
Hi,
OK thats easy.
Open the script editor and enter:
function m101()
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
local current=mc.mcSignalGetState(inst,hsig)
if current ==1 then
mc.mcSignalSetSate(inst,hsig,0)
else
mc.mcSignalSetState(inst,hsig,1)
end
end
if (mc.mcInEditor()==1)then
m101()
end
Save in the macros folder of your profile as m101.mcs
If in your Gcode file you code m101 then output#1 will turn on, code it a second time and it will turn off.
You will have to use your PoKeys plugin to assign a pin to the output.
Note I am at work and cannot run this through the debugger...may do so when I get home.
Craig
-
Hi Craig, thank you very much. It looks Greek to me. So if I copy that and just change OSIG_OUTPUT1 to OSIG_OUTPUT2 and the m101's to m102's I can control 2 outputs and so on?
-
Hi,
So if I copy that and just change OSIG_OUTPUT1 to OSIG_OUTPUT2 and the m101's to m102's I can control 2 outputs and so on?
Yes, up to output#63
Craig
-
Think you could do them all with a single macro and just set the output number using a p var. Something like M201P1, M201P2, etc. Will have to look. I know I did it before.
-
Hi,
whoops, made a mistake, the mc.mcSignalSetState and mc.mcSignalGetState don't need instance parameters:
function m101()
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
local current=mc.mcSignalGetState(hsig)
if current ==1 then
mc.mcSignalSetSate(hsig,0)
else
mc.mcSignalSetState(hsig,1)
end
end
if (mc.mcInEditor()==1)then
m101()
end
Craig
-
this might help
https://www.machsupport.com/forum/index.php?topic=39763.msg266718#msg266718
bill
-
I tried running it and the M code did not do anything. I opened it up in the editor and hit (start debugging) and it said C:\Machhobby\ZeroBraneStudio\bin\lua53. exe: error loading module 'machip' from file 'C:\Mach4hobby\Modules/machip. dll' : the specified module could not be found.
-
Hi,
well that a mystery to me, I ran this macro last night through the debugger and MDI and it worked in both instances.
Sounds like some part of the Mach installation is missing.
Craig
-
Oh fun, do I try re install it
-
Hi,
h'mmmm....I might wait until smurph, Chaoticone or Daz read this post....I'd guess they know abit more about it.
What build Mach are you using?
Craig
-
Version 4.2.0.4162
Build 4162
-
Hi,
that's the same build as I'm using.
Have a look in Mach4Hobby/Modules for the file machip.dll Is it there?
Craig
-
Hi,
I notice the file is machipc.dll not machip.dll........just the sort of typo that can catch you out.
Craig
-
I checked and the file is there.
-
If all you want to do is to turn on and off an output from G Code, you should try using M64 and M65
Look on page 60 of the Mach4 G Code programming manual for mill and router style machines.
M64 P2 this will turn on output 2
M65 P2 this will turn off output 2
-
Awesome... It works Thank you
-
If all you want to do is to turn on and off an output from G Code, you should try using M64 and M65
Look on page 60 of the Mach4 G Code programming manual for mill and router style machines.
M64 P2 this will turn on output 2
M65 P2 this will turn off output 2
Yup, that is what I was talking about earlier. Forgot they ended up being rolled into Mcodes though.