521
Mach4 General Discussion / Re: Looking for help enabling and disabling output with M code
« on: September 04, 2015, 02:03:53 AM »
name needs changed
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
This looks great I'm just not sure where to put what value. In the variables section it looks like it's looking for an input To trigger this as opposed to M code. Then it says "local hReg = 0 " is that where I would put the output that I want to turn on?
Could someone modify that example to show where you would put the M code that would activate it and the output that you are triggering?
For example if this was triggered by m120 and turned on output number 5 for 3 seconds.
Thanks for the continued help KingKerf
dan
function m120() --Save the name of the Signal (as stored inside of Mach4)
local inst = mc.mcGetInstance() --Get the instance of Mach4
ActivateSignalTime = 5000 --Time in milliseconds that we want the signal to be active.
local hReg = mc.OSIG_OUTPUT0 --The handle to the signal OUTPUT0 = output 0 if you wonted output 5 you would have mc.OSIG_ OUTPUT5
-----------------------------
hReg = mc.mcIoGetHandle(inst, IOName)
if hReg == 0 then
wx.wxMessageBox("Could not locate signal!")
else
local rc = mc.mcIoGetState(hReg)
if rc == 1 then --If rc equals 1, then the signal is active.
wx.wxMessageBox("Signal is already active!")
else --If rc does not equal 1, then the signal is not active.
mc.mcIoSetState(hReg, true) --Activate a signal.
wx.wxMilliSleep(ActivateSignalTime) --Sleep for the commanded time (so that the output stays on as long as we want).
mc.mcIoSetState(hReg, false) --Set the state of the signal back to false.
end
end