Hello Guest it is March 28, 2024, 05:43:44 PM

Author Topic: Question About Lua and Mach4  (Read 3749 times)

0 Members and 1 Guest are viewing this topic.

Question About Lua and Mach4
« on: March 02, 2015, 02:37:23 PM »
In my experience (26 years+) working with Fanuc and Siemens operators prefer the more tactile feel of rotary selector switches for feed, rapid, and spindle overrides. Most of the time these are binary. Simple enough. The logic to do this in Lua seems straight forward. But, once I have taken the binary and converted it to BCD how do I tell Mach4 the new value. I am creating an operator pendant with these 3 selector switches and need the code to make them function.

In Mach3 there were Brains and DRO's. Now I am a little confused. Looking through the LuaCalls.txt file I see: rc, percent = mc.mcCntlGetFRO(number mInst). Which I assume will gather the current value??? But, how do I PUT the value???

Am I missing something?

I would appreciate anyone offering some help.
Re: Question About Lua and Mach4
« Reply #1 on: March 02, 2015, 03:13:48 PM »
Nevermind. I found the way via this thread...

http://www.machsupport.com/forum/index.php/topic,27762.0.html

Next question.....

How do I limit the value from exceeding 250 or 0?

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Question About Lua and Mach4
« Reply #2 on: March 02, 2015, 07:53:49 PM »
How do I limit the value from exceeding 250 or 0?

------------------------------------------------------------------
local MyValue = 0;

MyValue = (where ever you getting the value from);

if MyValue < 0 then
    MyValue = 0;
end

if MyValue > 250 then
    MyValue = 250;
end

Scott
fun times
Re: Question About Lua and Mach4
« Reply #3 on: March 03, 2015, 12:20:12 PM »
Hello Scott and thank you. This is working.

May I burden you with some additional questions?
Re: Question About Lua and Mach4
« Reply #4 on: March 03, 2015, 12:27:01 PM »
I have read where there is a screen load script????

Where is this file located. I have searched the settings and the directory and have found nothing that screams here I am...

Is it the MachPlc.mcs file?

If so, is this where I would insert the code to run Brian's Sig file like this:

SigLib = {
    --Enable
    [mc.OSIG_MACHINE_ENABLED] = function (state)
        machEnabled = state;
    end,
    --HeadUp
    [mc.ISIG_INPUT1] = function (on_off)--mc.ISIG_INPUT1
        if( on_off==1 ) then
            -- On
        else
            -- Off
        end
    end,
    --HeadDn
    [mc.ISIG_INPUT2] = function (state)--mc.ISIG_INPUT2
        if( state == 1 ) then
            -- On
        else
            -- Off Call A function here if you wanted
        end
    end,
  [mc.ISIG_INPUT3] = function (state)--mc.ISIG_INPUT3 --Used as an enable button
        if( state == 1 ) then
            local inst= mc.mcGetInstance();
            local reg = mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_ENABLED)
            state = mc.mcSignalGetState(reg);
            if(state == 1)then
                state = 0
            else
                state = 1
            end
            mc.mcCntlEnable(inst, state);
        end
    end,
    [mc.ISIG_INPUT4] = function (state)--mc.ISIG_INPUT2 button to do feed hold
        if( state == 1 ) then
            local inst= mc.mcGetInstance();
            mc.mcCntlFeedHold(inst)
        end
    end,
    [mc.ISIG_INPUT5] = function (state)--mc.ISIG_INPUT2
        if( state == 1 ) then
            CycleStart() --Run my cycle start function
        end
    end
}

Re: Question About Lua and Mach4
« Reply #5 on: March 03, 2015, 12:30:49 PM »
Second, how do I determine what the Lua call is to say take a button input on Sig Input 1 and have it then choose a tab like the MDI tab?

I am trying to build a pendant and want buttons that can call these tabs without using keyboard or mouse functions.

Cycle Start nad FH are easy as they are listed in that handy file you posted. Thanks for that. Huge help. But, I cannot see how I can call the screen items from external sources nor what the syntax should or could be...

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Question About Lua and Mach4
« Reply #6 on: March 03, 2015, 08:02:28 PM »
screen designer, click on main root, then events.

see mach 4 tool box for examples and mcLua doc.

Scott
fun times