Hello Guest it is October 31, 2024, 07:49:25 PM

Author Topic: Output Control  (Read 8507 times)

0 Members and 1 Guest are viewing this topic.

Output Control
« on: May 05, 2015, 01:27:48 PM »
I have a script that I expected to trigger an output, but it doesn't.  Here is the script...

local inst = mc.mcGetInstance();
local osig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
local oState = mc.mcSignalGetState(osig)
if (oState == 0) then
    mc.SignalSetState(oSig, 1)
else
    mc.SignalSetState(oSig, 0)
end   

There is an LED that is mapped to OUTPUT1 and the outputs are enabled.  My expectation was that when the button is pressed, the LED for the output should come on.  This is on an un-licensed version.  Would that cause outputs not to trigger?  There is also no motion controller connected or installed.  The plan is to use ESS but for now, I'm just working on the screenset.  Would the lack of a motion controller be an issue?  I've also noticed that jog buttons are grayed out.

Thanks
Re: Output Control
« Reply #1 on: May 06, 2015, 01:17:01 PM »
I ran this in debug mode inside the IDE and I get the following.....

Lua: Error while running chunk.

What does that mean?
Re: Output Control
« Reply #2 on: May 06, 2015, 01:33:55 PM »
You said something about a button.  I don't know about a button.  But in a macro you can look at this thread.  "having trouble with Lua Script"  It'll show you how to turn on an output via macro.
Chad Byrd
Re: Output Control
« Reply #3 on: May 06, 2015, 01:37:46 PM »
A little bit more help.  This is what I'm using to give a start signal momentarily.  Turns on Output 2 for half a second then shuts it off.  I also show a message that it turns on and off.
Hope this helps.
-Chad

--TEST CODE OUTPUTS!!
function m1010()

local rc = 0;
local inst = 0; -- mc.mcGetInstance(mInst)

-- Turns on output 2.
hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2);  
mc.mcSignalSetState(hsig, 1); --sets OUTPUT_2 to True

--Messages are written like this.
mc.mcCntlSetLastError(inst, "Output2 ON");

wx.wxMilliSleep(500) --Same as sleep in Mach 3.

-- turns off output 2
hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2);  
mc.mcSignalSetState(hsig, 0); --sets OUTPUT_2 to False

--Messages are written like this.
mc.mcCntlSetLastError(inst, "Output2 OFF");

end --This is for the end of the function m1010()

--This next part does not have to be in here to run in Mach 4.
--It does need to be in here to step through and test.

if (mc.mcInEditor() == 1) then
   m1010()
end
Chad Byrd

Offline TimGS

*
  •  108 108
Re: Output Control
« Reply #4 on: May 06, 2015, 02:21:33 PM »
1)  I am not sure if LUA is CASE Sensitive but it is good practice anyways to name your variables the same way "osig" vs "oSig".
2) Did you put this script at the end of the Operator>Edit Screen>   "Screen Load" script/
3) Ensure that you map ("Mach Config" & "Your Controller Plugin Config") Output 1 to the physical port. 
4) Active Low vs Active High??

I am working on similar signal stuff... I have mapped an input to an output....
http://www.machsupport.com/forum/index.php/topic,29998.0.html
Re: Output Control
« Reply #5 on: May 06, 2015, 11:50:53 PM »
Thanks guys....

On the following line....

hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2); 

What is the significance of hsig, rc? I see examples that do not include the ,rc. 

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
Re: Output Control
« Reply #6 on: May 07, 2015, 07:48:10 AM »
hsig is the handle
rc is the return code (i.e. error return code from the function call, 0 = no error)

FYI  Lua IS case sensitive

Scott
fun times
Re: Output Control
« Reply #7 on: June 24, 2015, 10:17:37 PM »
Hi Cbyrdtopper

I've used and wrote scripts/macros for Mach3 and am updating to Mach 4. Trying to adapt my Mach 3 mods to Mach4 & LUA is giving me fits. The code you posted for turning on output 2 would really help me, I just need to know where to put it... I think I have to add it to the macro folder, but then do I have to a command to the LUA Script to call it? What I'm trying to do is get my dust collector (Output 2) to start when I do a cycle start and shut off at the end of the run. Any help would be appreciated. (using ESS if that matters). Thanks 
Hit the e-stop! Hit the e-stop!
Re: Output Control
« Reply #8 on: June 24, 2015, 11:22:55 PM »
Attached are 2 Mcodes. M200 at the beginning of the gcode file and M201 at the end. Put these Mcodes in your profile folder under the profile name you are using.
Andrew
MachMotion
Re: Output Control
« Reply #9 on: June 30, 2015, 04:05:32 AM »
Thanks Cbyrdtopper... got it working.
Hit the e-stop! Hit the e-stop!