Hello Guest it is March 28, 2024, 04:44:03 PM

Author Topic: Creating M-Code to activate Outputs  (Read 3216 times)

0 Members and 1 Guest are viewing this topic.

Creating M-Code to activate Outputs
« 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
Re: Creating M-Code to activate Outputs
« Reply #1 on: August 06, 2019, 08:59:00 PM »
Hi,
have a look at this thread.....they are sort of related:

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
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Creating M-Code to activate Outputs
« Reply #2 on: August 06, 2019, 09:13:14 PM »
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.
Re: Creating M-Code to activate Outputs
« Reply #3 on: August 06, 2019, 10:00:56 PM »
Hi,

Quote
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
« Last Edit: August 06, 2019, 10:15:13 PM by joeaverage »
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Creating M-Code to activate Outputs
« Reply #4 on: August 06, 2019, 10:44:29 PM »
As part of the Goode
Re: Creating M-Code to activate Outputs
« Reply #5 on: August 06, 2019, 11:50:25 PM »
Hi,
OK thats easy.

Open the script editor and enter:

Code: [Select]
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
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Creating M-Code to activate Outputs
« Reply #6 on: August 07, 2019, 12:02:03 AM »
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?
Re: Creating M-Code to activate Outputs
« Reply #7 on: August 07, 2019, 12:32:49 AM »
Hi,

Quote
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
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Creating M-Code to activate Outputs
« Reply #8 on: August 07, 2019, 01:38:40 AM »
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.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Creating M-Code to activate Outputs
« Reply #9 on: August 07, 2019, 05:10:44 AM »
Hi,
whoops, made a mistake, the mc.mcSignalSetState and mc.mcSignalGetState don't need instance parameters:

Code: [Select]
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
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'