News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Rookie LUA question

Started by fishnorling, December 18, 2020, 07:50:21 AM

Previous topic - Next topic

fishnorling

Good morning, brand newbie, first attempt at editing LUA for Mach 4.  I want to trigger a signal, open a pneumatic valve, delay, then turn off.  I have been able to find examples and come up with the following code.  I have tried to run in the edit/debugger, and the best I can get for a result is nil, however with that said, the best I can get for known code that does run is, nil.  So, stumped.  I am wondering if anyone out there is willing to comment on this code;

function m102 ()
   local inst = mc.mcGetInstance() --Get the instance of Mach4
local IOName = mc.OSIG_OUTPUT1 --Save the name of the Signal (as stored inside of Mach4)
local ActivateSignalTime = 5000 --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


Thanks
Dave

Kindred

I think that you are on the wrong site.  This is a support site for Simple Machines Forum software...   it sounds like you want to be on some other site (perhaps one that is using our software?)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Shambles

^ yep.

Here's where you need to be (although you are already a contributing member there anyway  ::))

https://www.machsupport.com/forum/

Herman's Mixen

looks like hes up to some audio stuff programming wich are used generally in vst plugins ;)
Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

Shambles


live627

QuoteHmmmm.....  doubt
press X?

Advertisement: