Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: CITO on May 01, 2019, 04:58:00 PM
-
Hello together,
my name is Oliver and I'm from Germany, my english is not so good please excuse ;)
I'm new in Mach4 and my skills in Mach4 are at the beginning.
I want to change a tool by pressing an external Button (it's an ATC-Spindel, air pressed for tool change).
I think the Input Signal from this button must be mapped to the Output signal for the magnetic valve for the spindle, but how can I do that.
In the future the tool change should be automatically, but step by step.
My Controller is a csmio/ip-s, the machine is a DIY-milling machine
Please, can anybody help me?
Greetings
Oliver
-
Hello Oliver,
Welcome to the forum.
You've got the right idea. Have an input trigger an output.
In Mach4, we do this by placing tasks like this in the signal library.
This is found in the screen editor, in the Screen Load Script.
This thread is a good thread to look at if you're just starting out. Craig (joeaverage) has a good PDF on the Signal Library and using Inputs for different tasks.
https://www.machsupport.com/forum/index.php?topic=39763.msg266911#msg266911
-
Hello and thank you for reply
I did it, but not 100%, while the screen is loading the output signal switched on (one time).
It should do that only if I press the external Button
Here is the Code
---------------------------------------------------------------
-- Tool IN / OUT
---------------------------------------------------------------
[mc.ISIG_INPUT3] = function (state)
if (state == 1) then
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
hSig, rc = mc.mcSignalGetHandle(inst, IOName)
if (rc ~= 0) then --There was error
mc.mcCntlSetLastError(inst, "There was an error")
else
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,
Please, can somebody help me to fix this problem?
Greetings
Oliver
-
nobody a solution?
-
Try this. The wxMilliSleep really should be avoided all together.
---------------------------------------------------------------
-- 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,
-
Hi Chaoticone,
thanks a lot, it works.
Only if I edit the screen and Mach4 reload it, the Output is shortly activ, but it's no problem
-
:)
-
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.
---------------------------------------------------------------
-- 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