1
Mach4 General Discussion / Re: Button config for different funktions
« on: May 30, 2019, 04:04:06 AM »
Hello,
I don't know what it is, but the problem is back, I changed nothing
and there is a second problem, I configured the Mist funktion and the Single Block funktion also on external buttons and it works to begin perfectly,
but now the Mist and Single Block turned on when the Mach4 screen is loading, I have to turn them off. After this procedure all funktions are still working.
Here is the code I use.
Thanks for Help
Greetings
Oliver
I don't know what it is, but the problem is back, I changed nothing
and there is a second problem, I configured the Mist funktion and the Single Block funktion also on external buttons and it works to begin perfectly,
but now the Mist and Single Block turned on when the Mach4 screen is loading, I have to turn them off. After this procedure all funktions are still working.
Here is the code I use.
Code: [Select]
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
---------------------------------------------------------------
-- Tool IN / OUT
---------------------------------------------------------------
[mc.ISIG_INPUT3] = function (state)
local inst = mc.mcGetInstance();
local IOName = mc.OSIG_OUTPUT5 --Save the name of the Signal (as stored inside of Mach4)
local ActivateSignalTime = 1000 --Time in milliseconds that we want the signal to be active.
local hReg = 0 --The handle to the signal
local rc = 0
local hSig, rc = mc.mcSignalGetHandle(inst, IOName)
if (rc ~= 0) then --There was error
mc.mcCntlSetLastError(inst, "There was an error")
else
if (state == 1) then
rc = mc.mcSignalSetState(hSig, 1) --Turn the output on
if (rc ~= 0) then --There was error
mc.mcCntlSetLastError(inst, "There was an error")
else
wx.wxMilliSleep(ActivateSignalTime) --Sleep for the commanded time (so that the output stays on as long as we want).
rc = mc.mcSignalSetState(hSig, 0) --Turn the output off
if (rc ~= 0) then --There was error
mc.mcCntlSetLastError(inst, "There was an error")
end
end
end
end
end,
[mc.ISIG_INPUT20] = function (state)
if (state == 1) then
Mist()
else
--do nothing
end
end,
[mc.ISIG_INPUT21] = function (state)
if (state == 1) then
SingleBlock()
else
--do nothing
end
end,
---------------------------------------------------------------
-- Mist function.
---------------------------------------------------------------
function Mist()
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 0) then
local OSigMist = mc.mcSignalGetHandle (inst, mc.OSIG_MISTON)
mc.mcSignalSetState(OSigMist, 1)
mc.mcCntlSetLastError(inst, "Mist On")
else
local OSigMist = mc.mcSignalGetHandle (inst, mc.OSIG_MISTON)
mc.mcSignalSetState(OSigMist, 0)
mc.mcCntlSetLastError(inst, "Mist Off")
end
end
end
---------------------------------------------------------------
-- Single Block function.
---------------------------------------------------------------
function SingleBlock()
local sigh = mc.mcSignalGetHandle(inst, 0);
local sigState = mc.mcSignalGetState(sigh)
if (sigState == 1)then
mc.mcCntlSetSingleBlock(inst, 0)
else
mc.mcCntlSetSingleBlock(inst, 1)
end
end
Thanks for Help
Greetings
Oliver