Hello Guest it is April 18, 2024, 03:37:03 AM

Author Topic: Signal Scripts  (Read 13773 times)

0 Members and 1 Guest are viewing this topic.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Signal Scripts
« Reply #10 on: May 04, 2014, 02:08:50 PM »
don't see where you put this:

if(SigLib[THE_SIGNAL_NAME] ~= nil)then
SigLib[THE_SIGNAL_NAME](state);
end

in there
fun times

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Signal Scripts
« Reply #11 on: May 04, 2014, 02:18:36 PM »
Notice also that, in Brian's PLC he defines "MachState", but I don't see where/if he has passed "MachState" to the Function(state) param....  it may be there, if so, I am just missing it...

scott
fun times
Re: Signal Scripts
« Reply #12 on: May 04, 2014, 02:27:01 PM »
Quote
Brian had said put this script === Then in the signal script I do this:

ahh... based on that I need to pass the
sig = THE_SIGNAL_NAME_I_want_to_use;

I though sig was looking at all the inputs and just looking for the changing state
« Last Edit: May 04, 2014, 02:33:38 PM by Ya-Nvr-No »
Re: Signal Scripts
« Reply #13 on: May 04, 2014, 09:17:35 PM »
I will try to test the example tomorrow. This is running on a machine at the shop, but I could have missed something... It happens!
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: Signal Scripts
« Reply #14 on: May 10, 2014, 01:01:46 PM »
with the latest version of mach4 this signal script works now, thanks


mc.mcCntlSetLastError(0, 'sig1 = ' .. tostring(sig));
mc.mcCntlSetLastError(0, 'state1 = ' .. tostring(state));
if (SigLib[sig] ~= nil) then
   SigLib[sig](state);
        mc.mcCntlSetLastError(0, 'sig2 = ' .. tostring(sig));
        mc.mcCntlSetLastError(0, 'state2 = ' .. tostring(state));
end

you can see what button signal number
and 0 for off 1 for on

Still trying to get my head around it but at least it seems to be giving me something useful.
« Last Edit: May 10, 2014, 01:12:27 PM by Ya-Nvr-No »
Re: Signal Scripts
« Reply #15 on: May 10, 2014, 01:48:14 PM »
I take that back, it works kind of,
only after you rem that section restart mach4 then take the rems marks out
then it works till you restart
so im getting closer but its not fully functional.


how do you display two or more variables on one line?
mc.mcCntlSetLastError(0, 'state  &  signal = ' .. tostring(state) "  " .. tostring(sig));
Re: Signal Scripts
« Reply #16 on: May 10, 2014, 02:26:01 PM »
if I leave this one line in the signal script I can see what button number is being pushed,
just not sure what all the other numbers that get displayed with some button presses represent.

note: and only if a script is associated with that button.

 mc.mcCntlSetLastError(inst, 'signal = ' .. tostring(sig));
« Last Edit: May 10, 2014, 02:28:34 PM by Ya-Nvr-No »
Re: Signal Scripts
« Reply #17 on: May 10, 2014, 05:38:00 PM »
I did an update to the Sig Lib it now is tested to be working and I made it simulate a tool release button .

SigLib = {
    [mc.ISIG_INPUT1] = function (state)
       
    end,
    --Tool Release Button
    [mc.ISIG_INPUT2] = function (state)--mc.ISIG_INPUT1
        local inst = mc.mcGetInstance();
        local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1);
       
        if( state==1 ) then
            --Check to see if the spindle is stopped here
            --Turn On Tool Release (Unclam Tool)
            mc.mcSignalSetState(hsig, 1 );
           
       else
           --Turn Off Tool Release (Clamp Tool)
            mc.mcSignalSetState(hsig, 0 );
        end
    end
}


You also need to have a signals script with this code

if(SigLib[sig] ~= nil)then
SigLib[sig](state);
end


Thanks
Brian
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: Signal Scripts
« Reply #18 on: May 10, 2014, 11:40:28 PM »
With the help of Illya and Brian

As an update for all, the script does not go into the PLC Script, it goes in the Screen Load Script.
works sweet now.

thanks guys


Code: [Select]
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_INPUT5
        if( state == 1 ) then
            CycleStart() --Run my cycle start function
        end
    end,
    [mc.ISIG_INPUT6] = function (state)--mc.ISIG_INPUT6
        local inst = mc.mcGetInstance();--Tool Release Button
        local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7);
      
        if( state==1 ) then
            --Check to see if the spindle is stopped here
            --Turn On Tool Release (Unclam Tool)
            mc.mcSignalSetState(hsig, 1 );        
       else
           --Turn Off Tool Release (Clamp Tool)
            mc.mcSignalSetState(hsig, 0 );
        end
    end
}



this still goes in the signal script:
if(SigLib[sig] ~= nil)then
SigLib[sig](state);
end
« Last Edit: May 10, 2014, 11:44:30 PM by Ya-Nvr-No »
Re: Signal Scripts
« Reply #19 on: May 11, 2014, 07:50:11 AM »
Update to my question on combining (concant) variable to output on one line
I put this in the "Signal Script" and it displays the Key signal number and the button state.
more for informational use and testing then anything at this time.
Note; (to display one "&" you have to use two)
the ".." is the concant function
several button spew out several lines, view in history

mc.mcCntlSetLastError(inst, 'Signal && State = ' .. tostring(sig) .. ' && ' .. tostring(state));