Hello Guest it is March 28, 2024, 03:22:08 PM

Author Topic: Button config for manual toolchange  (Read 1746 times)

0 Members and 1 Guest are viewing this topic.

Button config for manual toolchange
« 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
Re: Button config for manual toolchange
« Reply #1 on: May 03, 2019, 06:29:19 PM »
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
Chad Byrd
Re: Button config for manual toolchange
« Reply #2 on: May 06, 2019, 05:17:48 PM »
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

Code: [Select]
---------------------------------------------------------------
-- 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
Re: Button config for manual toolchange
« Reply #3 on: May 11, 2019, 02:36:39 AM »
nobody a solution?

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Button config for manual toolchange
« Reply #4 on: May 13, 2019, 03:54:40 PM »
Try this. The wxMilliSleep really should be avoided all together.

Code: [Select]
---------------------------------------------------------------
-- 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,
;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: Button config for manual toolchange
« Reply #5 on: May 23, 2019, 06:21:35 AM »
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

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Button config for manual toolchange
« Reply #6 on: May 23, 2019, 03:07:07 PM »
 :)
;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: Button config for different funktions
« Reply #7 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.


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
« Last Edit: May 30, 2019, 04:06:49 AM by CITO »