Hello Guest it is March 28, 2024, 08:56:02 AM

Author Topic: Macro start and wait signal for stop  (Read 806 times)

0 Members and 1 Guest are viewing this topic.

Macro start and wait signal for stop
« on: October 30, 2020, 06:07:38 AM »
Hi I'm Asis
I'm newbie use mach4.
I feel hard macro script for mach4 I ever use mach3.

Now I want for create  macro
Active Output1 for start motor ,
Then
Wait for Signal_Input2  for stop signal Output1

Please help me for explained step for create macro or example code .

Thank you.
Asis



function m100()

--active sigoutput1
--wait input2 time 10 second
--setstate sigoutput1 turn off

if (mc.mcInEditor() == 1) then
 m100()

end

Offline Bill_O

*
  •  562 562
    • View Profile
Re: Macro start and wait signal for stop
« Reply #1 on: October 30, 2020, 08:56:30 AM »
This might help.
The newest is the 3rd post from the bottom.

https://www.machsupport.com/forum/index.php?topic=43260.msg279695#msg279695


Bill
Re: Macro start and wait signal for stop
« Reply #2 on: October 31, 2020, 03:41:03 AM »
This might help.
The newest is the 3rd post from the bottom.

https://www.machsupport.com/forum/index.php?topic=43260.msg279695#msg279695


Bill

Thank you MR.Bill I read your PDF it's good for newbie.
Re: Macro start and wait signal for stop
« Reply #3 on: October 31, 2020, 03:44:32 AM »
Code: [Select]
function m100()

--local inst2 = mc.mcGetInstance()
--local hsig2 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT0)

local inst2, hSig2, rc2
inst2 = mc.mcGetInstance()



local inst = mc.mcGetInstance()
local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT0)
local spinstate = mc.mcSignalGetState(hsig)



hSig2, rc2 = mc.mcSignalGetHandle(inst2, mc.OSIG_OUTPUT23) -- Get handle for output 1
   rc2 = mc.mcSignalSetState(hSig2, 1) --turn on output 1
if (rc2~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "There was an error")
end





if (spinstate == 0 ) then
mc.mcCntlSetLastError(inst, "5555566")
 --mc.mcSignalSetState(hsig, 0)
else
  mc.mcCntlSetLastError(inst, "123")
  --mc.mcSignalSetState(hsig, 1)
end
end
 
if (mc.mcInEditor() == 1) then
    m100()
end

this is my code.
now I can
- use OutputSignal23 for active
- Use If (spinstate == 0 ) then....

it'sworking.
I want change If (spinstate == 0 ) then   to  while signal Input0 active then Stop signal output23   how to code for while loop ?
Thank you.