Hello Guest it is December 08, 2019, 11:22:55 PM

Author Topic: Mach4 Lua Script examples  (Read 4620 times)

0 Members and 1 Guest are viewing this topic.

Offline Illya

*
  •  11 11
    • View Profile
Mach4 Lua Script examples
« on: May 08, 2014, 10:24:07 PM »
This is my attempt at an output button toggle script (hopefully it is safe enough) for eg. output 2.
Works for me. :)
 
  See later post for corrected code.
« Last Edit: May 10, 2014, 11:34:54 AM by ART »
Re: Mach4 Lua Script examples
« Reply #1 on: May 09, 2014, 09:12:28 PM »
Oh I got ya now, thanks again
I was toggling the led but not the modbus output


edit:
that did not make any difference, led toggle but I am not seeing the outputs at the simulator change states.


« Last Edit: May 09, 2014, 09:22:13 PM by Ya-Nvr-No »

Offline Illya

*
  •  11 11
    • View Profile
Re: Mach4 Lua Script examples
« Reply #2 on: May 09, 2014, 09:20:58 PM »
Oh I got ya now, thanks again
I was toggling the led but not the modbus output



yes it takes time to get your head around it I still have a lot of scripts to try to figure out to get the machine running the way I would like .... But it can be done (allot of trial and error mostly error for me ;) )

actual script from buttons on my screen set ...this does work!!

--OUTPUT 5
--Get the instance of the controller
local inst= mc.mcGetInstance();
--Get the out5 handle
local out5= mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5);
--Output TOGGLE
 local outstate = mc.mcSignalGetState(out5);
 if (outstate == 1) then
   mc.mcSignalSetState(out5, false);
 else
   mc.mcSignalSetState(out5, true);
 end



--OUTPUT 8
--Get the instance of the controller
local inst= mc.mcGetInstance();
--Get the out8 handle
local out8= mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8);
--Output TOGGLE
 local outstate = mc.mcSignalGetState(out8);
 if (outstate == 1) then
   mc.mcSignalSetState(out8, false);
 else
   mc.mcSignalSetState(out8, true);
 end
« Last Edit: May 09, 2014, 09:34:25 PM by Illya »
Re: Mach4 Lua Script examples
« Reply #3 on: May 09, 2014, 09:28:29 PM »
Damn simulator was offline, works fine now thanks