Macro mach4

john123
Nouveau
18 Mars 2014
26
  • Auteur de la discussion
  • #1
Bonjours a tous,

J’essaye d'écrire une macro pour contrôler la tourelle d'un tour emco 5 compact cnc, sa a l'air de bien fonctionner mais la macro s’exécute 2 fois de suite,je rentre t0100m6 dans le mdi, lance la commande, toute la macro s’exécute et repart depuis le début, c'est pas forcement gênant car si l'outil sélectionner est le même que celui en place sa se stop.
Si l'outil sélectionner est celui en place la macro se relance aussi.
J'ai essayé un truc tout bête a la place, genre affiche 1, attend 1sec, affiche 2, attend 1 sec, et la aussi sa se répète 2 fois !

Comme si le bouton qui lance l’exécution du mdi cliquait 2 fois
J'utilise le pokeys57cnc, et le screen lathe par defau
La macro en question


Code:
function m6()

    local inst = mc.mcGetInstance()
    
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    
    local signalinv = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2) --deverouillage, contacte relais pour inversion moteur
    local signalfait = mc.ISIG_INPUT2
    
    if (mc.mcInEditor() == 1)then
        m6()
    end
    --
    function GetpokReg(regname) -- fonction pour lire le registre du pokeys
        local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_42447/%s", regname))
        return mc.mcRegGetValueString(hreg)
        
    end
    --regval = GetpokReg("PWM 18 duty")
    
    
    function WritepokReg(regname, regvalue) -- fonction pour ecrire sur registre pokeys
        local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_42447/%s", regname))
         mc.mcRegSetValueString(hreg, tostring(regvalue))
        
    end
    --WritepokReg("PWM 18 duty", 25)

    
    
    mc.mcCntlSetLastError(inst, "Changement demandé "..tostring(currenttool).."a"..tostring(selectedtool))
    wx.wxMilliSleep(1000)
    
    
    
    if (selectedtool == currenttool)then
    
        mc.mcCntlSetLastError(inst, "inutile")
        wx.wxMilliSleep(1000)
        
        --regval = GetpokReg("PWM 18 duty")
        --mc.mcCntlSetLastError(inst, regval)
        --wx.wxMilliSleep(1000)
    
    else                                                                       
    
        mc.mcCntlSetLastError(inst, "changement en cour")                          -- debut du changement
        mc.mcCntlGcodeExecute(inst, "G00 Z-5.0")
    
        mc.mcSignalSetState(signalinv, 1)
        WritepokReg("PWM 18 duty", 0.9)
    
    
        local switchH = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2)
        local switchstate = mc.mcSignalGetState(switchH)
    
    
        if (switchstate == 1)then                                                 --controle de l'état du capteur position tourelle'
        
            mc.mcCntlSetLastError(inst, "degagement capteur")
            wx.wxMilliSleep(1000)
            local check2 = mc.mcSignalWait(inst,signalfait, mc.WAIT_MODE_LOW,10) --on attend 5 sec max que le capteur soi degagé
        
                if (check2 ~= 0)then                                             --controle degagement capteur arrivé tourelle
                
                    mc.mcCntlCycleStop(inst)
                    mc.mcCntlSetLastError(inst, "Annulé capteur bloqué")
                    wx.wxMilliSleep(1000)
                    mc.mcCntlCycleStop(inst)
                
                end
        end   
        
        mc.mcCntlSetLastError(inst, "capteur degagé")
        wx.wxMilliSleep(1000)
    
    
    

        mc.mcCntlSetLastError(inst, "en cours attente capteur tourelle")
        local check = mc.mcSignalWait(inst,signalfait, mc.WAIT_MODE_HIGH,15)            --on attend 15 seconde que le capteur passe a 1
        
        if (check ~= 0)then                                                         --controle arrivé en position tourelle
            WritepokReg("PWM 18 duty", 0)                                            --le capteur n'est pas passé a 1 pwm et relais au repos/vérouillage
            mc.mcSignalSetState(signalinv, 0)
            mc.mcCntlSetLastError(inst, "Annulé probleme tourelle")
            wx.wxMilliSleep(1000)
            mc.mcCntlCycleStop(inst)
        
            
        else                                                                    --le capteur est passé a 1 on coupe tout puis repasse le pwm a 30
            WritepokReg("PWM 18 duty", 0)                                        -- pour maintenir la tourelle
            mc.mcSignalSetState(signalinv, 0)
            WritepokReg("PWM 18 duty", 0.3)
            mc.mcCntlSetLastError(inst, "changement ok !")
            mc.mcToolSetCurrent(inst, selectedtool)
            wx.wxMilliSleep(1000)
        end
    end   
end

et le screen script

Code:
-- For ZeroBrane debugging.
package.path = package.path .. ";./ZeroBraneStudio/lualibs/mobdebug/?.lua"

-- For installed profile modules support.
package.path = package.path .. ";./Profiles/emco2/Modules/?.lua"
package.path = package.path .. ";./Profiles/emco2/Modules/?.luac"
package.path = package.path .. ";./Profiles/emco2/Modules/?.mcs"
package.path = package.path .. ";./Profiles/emco2/Modules/?.mcc"
package.cpath = package.cpath .. ";./Profiles/emco2/Modules/?.dll"

-- For installed global modules support.
package.path = package.path .. ";./Modules/?.lua"
package.path = package.path .. ";./Modules/?.luac"
package.path = package.path .. ";./Modules/?.mcs"
package.path = package.path .. ";./Modules/?.mcc"
package.cpath = package.cpath .. ";./Modules/?.dll"

-- PMC genearated module load code.
package.path = package.path .. ";./Pmc/?.lua"
package.path = package.path .. ";./Pmc/?.luac"


-- PMC genearated module load code.
function Mach_Cycle_Pmc()
end

-- Screen load script (Global)
pageId = 0
screenId = 0
testcount = 0
machState = 0
machStateOld = -1
machEnabled = 0
machWasEnabled = 0
inst = mc.mcGetInstance()

---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    scr.SetProperty('btnRefAll', 'Enabled', tostring(state));
    scr.SetProperty('btnRefAll2', 'Enabled', tostring(state));
    scr.SetProperty('btnGotoZero', 'Enabled', tostring(state));
    scr.SetProperty('tabJogging', 'Enabled', tostring(state));
    if (state == 1) then
        ButtonEnable()
    end
end,
[mc.ISIG_INPUT0] = function (state)
    
end,
[mc.ISIG_INPUT1] = function (state)
   -- if (state == 1) then   
--        CycleStart()
--    --else
--        --mc.mcCntlFeedHold (0)
--    end

end,

[mc.OSIG_JOG_CONT] = function (state)
    if( state == 1) then
       scr.SetProperty('labJogMode', 'Label', 'Continuous');
       scr.SetProperty('txtJogInc', 'Bg Color', '#C0C0C0');--Light Grey
       scr.SetProperty('txtJogInc', 'Fg Color', '#808080');--Dark Grey
    end
end,

[mc.OSIG_JOG_INC] = function (state)
    if( state == 1) then
        scr.SetProperty('labJogMode', 'Label', 'Incremental');
        scr.SetProperty('txtJogInc', 'Bg Color', '#FFFFFF');--White   
        scr.SetProperty('txtJogInc', 'Fg Color', '#000000');--Black
   end
end,

[mc.OSIG_JOG_MPG] = function (state)
    if( state == 1) then
        scr.SetProperty('labJogMode', 'Label', '');
        scr.SetProperty('txtJogInc', 'Bg Color', '#C0C0C0');--Light Grey
        scr.SetProperty('txtJogInc', 'Fg Color', '#808080');--Dark Grey
        --add the bits to grey jog buttons becasue buttons can't be MPGs
    end
end


----M6 messagebox
--[mc.OSIG_TOOL_CHANGE] = function (state)
--    local selectedtool = mc.mcToolGetSelected(inst)
--    local currenttool = mc.mcToolGetCurrent(inst)
--   
--    if (selectedtool ~= currenttool) then
--        if( state == 1) then
--            mm.ToolChangeMsg("A tool change has been requested via M6. Change your tool then press Cycle Start to continue!", "Tool Change Active!")
--        end
--    end
--end,
}

---------------------------------------------------------------
-- Keyboard Inputs Toggle() function. Updated 5-16-16
---------------------------------------------------------------
function KeyboardInputsToggle()
    local iReg = mc.mcIoGetHandle (inst, "Keyboard/Enable")
    local iReg2 = mc.mcIoGetHandle (inst, "Keyboard/EnableKeyboardJog")
    
    if (iReg ~= nil) and (iReg2 ~= nil) then
        local val = mc.mcIoGetState(iReg);
        if (val == 1) then
            mc.mcIoSetState(iReg, 0);
            mc.mcIoSetState(iReg2, 0);
            scr.SetProperty('btnKeyboardJog', 'Bg Color', '');
            scr.SetProperty('btnKeyboardJog', 'Label', 'Keyboard\nInputs Enable');
        else
            mc.mcIoSetState(iReg, 1);
            mc.mcIoSetState(iReg2, 1);
            scr.SetProperty('btnKeyboardJog', 'Bg Color', '#00FF00');
            scr.SetProperty('btnKeyboardJog', 'Label', 'Keyboard\nInputs Disable');
        end
    end
end

---------------------------------------------------------------
-- Remember Position function.
---------------------------------------------------------------
function RememberPosition()
    local pos = mc.mcAxisGetMachinePos(inst, 0) -- Get current X (0) Machine Coordinates
    mc.mcProfileWriteString(inst, "RememberPos", "X", string.format (pos)) --Create a register and write the machine coordinates to it
    local pos = mc.mcAxisGetMachinePos(inst, 1) -- Get current Y (1) Machine Coordinates
    mc.mcProfileWriteString(inst, "RememberPos", "Y", string.format (pos)) --Create a register and write the machine coordinates to it
    local pos = mc.mcAxisGetMachinePos(inst, 2) -- Get current Z (2) Machine Coordinates
    mc.mcProfileWriteString(inst, "RememberPos", "Z", string.format (pos)) --Create a register and write the machine coordinates to it
end

---------------------------------------------------------------
-- Return to Position function.
---------------------------------------------------------------
function ReturnToPosition()
    local xval = mc.mcProfileGetString(inst, "RememberPos", "X", "NotFound") -- Get the register Value
    local yval = mc.mcProfileGetString(inst, "RememberPos", "Y", "NotFound") -- Get the register Value
    local zval = mc.mcProfileGetString(inst, "RememberPos", "Z", "NotFound") -- Get the register Value
    
    if(xval == "NotFound")then -- check to see if the register is found
        wx.wxMessageBox('Register xval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box
    elseif (yval == "NotFound")then -- check to see if the register is found
        wx.wxMessageBox('Register yval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box
    elseif (zval == "NotFound")then -- check to see if the register is found
        wx.wxMessageBox('Register zval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box
    else
        mc.mcCntlMdiExecute(inst, "G00 G53 Z0.0000 \n G00 G53 X" .. xval .. "\n G00 G53 Y" .. yval .. "\n G00 G53 Z" .. zval)
    end
end

---------------------------------------------------------------
-- Spin CW function.
---------------------------------------------------------------
function SpinCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
    
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, 1);
    end
end

---------------------------------------------------------------
-- Spin CCW function.
---------------------------------------------------------------
function SpinCCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
    
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, -1);
    end
end

------------------------------------------------------------
-- Open Docs function.
---------------------------------------------------------------
function OpenDocs()
    local major, minor = wx.wxGetOsVersion()
    local dir = mc.mcCntlGetMachDir(inst);
    local cmd = "explorer.exe /open," .. dir .. "\\Docs\\"
    if(minor <= 5) then -- Xp we don't need the /open
        cmd = "explorer.exe ," .. dir .. "\\Docs\\"
    end
    os.execute(cmd) -- another way to execute a program.
    --wx.wxExecute(cmd);
    scr.RefreshScreen(250); -- Windows 7 and 8 seem to require the screen to be refreshed. 
end

---------------------------------------------------------------
-- Cycle Stop function.
---------------------------------------------------------------
function CycleStop()
    mc.mcCntlCycleStop(inst);
    mc.mcSpindleSetDirection(inst, 0);
    mc.mcCntlSetLastError(inst, "Cycle Stopped");
end
---------------------------------------------------------------
-- Button Jog Mode Toggle() function.
---------------------------------------------------------------
function ButtonJogModeToggle()
    local cont = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT);
    local jogcont = mc.mcSignalGetState(cont)
    local inc = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_INC);
    local joginc = mc.mcSignalGetState(inc)
    local mpg = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_MPG);
    local jogmpg = mc.mcSignalGetState(mpg)
    
    if (jogcont == 1) then
        mc.mcSignalSetState(cont, 0)
        mc.mcSignalSetState(inc, 1)
        mc.mcSignalSetState(mpg, 0)       
    else
        mc.mcSignalSetState(cont, 1)
        mc.mcSignalSetState(inc, 0)
        mc.mcSignalSetState(mpg, 0)
    end

end

---------------------------------------------------------------
-- Ref All Home() function.
---------------------------------------------------------------
function RefAllHome()
    mc.mcAxisDerefAll(inst)  --Just to turn off all ref leds
    mc.mcAxisHomeAll(inst)
    coroutine.yield() --yield coroutine so we can do the following after motion stops
    ----See ref all home button and plc script for coroutine.create and coroutine.resume
    wx.wxMessageBox('Referencing is complete')
end

---------------------------------------------------------------
-- Go To Work Zero() function.
---------------------------------------------------------------
function GoToWorkZero()
    mc.mcCntlMdiExecute(inst, "G00 X0 Y0 A0")--Without Z moves
    --mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG00 X0 Y0 A0\nG00 Z0")--With Z moves
end

---------------------------------------------------------------
-- Cycle Start() function.
---------------------------------------------------------------
function CycleStart()
    local rc;
    local tab, rc = scr.GetProperty("MainTabs", "Current Tab")
    local tabG_Mdione, rc = scr.GetProperty("nbGCodeMDI1", "Current Tab")
    --local tabG_Mditwo, rc = scr.GetProperty("nbGCodeMDI2", "Current Tab")
    --wx.wxMessageBox("tab == " .. tostring(tab) )
    --See if we have to do an MDI command
    
    if ((tonumber(tab) == 0 and tonumber(tabG_Mdione) == 1)) then --or (tonumber(tab) == 2 and tonumber(tabG_Mditwo) == 1 )) then
        local state = mc.mcCntlGetState(inst);
        if (state == mc.MC_STATE_MRUN_MACROH) then
            mc.mcCntlCycleStart(inst);
            --mc.mcCntlSetLastError(inst, "Do Cycle Start");
        else
            if (tonumber(tab) == 0) then 
                scr.ExecMdi('mdi1');
                --mc.mcCntlSetLastError(inst, "Do MDI 1");
            end
        end
    else
        --Do CycleStart
        --mc.mcCntlSetLastError(inst, "Do Cycle Start");
        mc.mcCntlCycleStart(inst);
        --wx.wxMessageBox("Do Cycle Start")       
    end
end

-------------------------------------------------------
--  Seconds to time Added 5-9-16
-------------------------------------------------------
--Converts decimal seconds to an HH:MM:SS.xx format
function SecondsToTime(seconds)
    if seconds == 0 then
        return "00:00:00.00"
    else
        local hours = string.format("%02.f", math.floor(seconds/3600))
        local mins = string.format("%02.f", math.floor((seconds/60) - (hours*60)))
        local secs = string.format("%04.2f",(seconds - (hours*3600) - (mins*60)))
        return hours .. ":" .. mins .. ":" .. secs
    end
end

---------------------------------------------------------------
-- Set Button Jog Mode to Cont.
---------------------------------------------------------------
local cont = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT);
local jogcont = mc.mcSignalGetState(cont)
mc.mcSignalSetState(cont, 1)

---------------------------------------------------------------
--Timer panel example
---------------------------------------------------------------
TimerPanel = wx.wxPanel (wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxSize( 0,0 ) )
timer = wx.wxTimer(TimerPanel)
TimerPanel:Connect(wx.wxEVT_TIMER,
function (event)
    wx.wxMessageBox("Hello")
    timer:Stop()
end)
    
---------------------------------------------------------------
-- Load modules
---------------------------------------------------------------
----local inst = mc.mcGetInstance()
--local profile = mc.mcProfileGetName(inst)
--local machDir = mc.mcCntlGetMachDir(inst)
--local paths = machDir .. "/Profiles/" .. profile .. "/Modules/?.lua" --Default location to look for modules with lua extensions
--local cpaths = machDir .. "/Profiles/" .. profile .. "/Modules/?.dll" --Default location to look for modules with dll extensions
--
----Add additional paths locations to look in here
--paths = paths .. ";" .. machDir .. "/Profiles/" .. profile .. "/Modules/?.mcs" --Lets also look here for modules with mcs extensions
--paths = paths .. ";" .. machDir .. "/Modules/?.lua" --Lets add a location to look for modules with lua extensions
--paths = paths .. ";" .. machDir .. "/Modules/?.mcs" --Lets add a location to look for modules with mcs extensions
--
----Check package.path to see if we need to add a ;
--local MyS = package.path
--local s = string.find(MyS, "%;") --Find the first ;
--
--if (s ~=1) then --package.path does not begin with a ;
--    paths = paths .. ";" --Add a ;
--end
--
--package.path = paths .. package.path --Do this only after you have built the string including all locations to look in
--
----Add additional cpaths locations to look in here
--cpaths = cpaths ..  ";" .. machDir .. "/Modules/?.dll" --Lets add a location to look for modules with dll extensions
--
----Check package.cpath to see if we need to add a ;
--MyS = package.cpath
--s = string.find(MyS, "%;") --Find the first ;
--
--if (s ~=1) then --package.path does not begin with a ;
--    cpaths = cpaths .. ";" --Add a ;
--end
--
--package.cpath = cpaths .. package.cpath --Do this only after you have built the string including all locations to look in

--Master module
package.loaded.mcMasterModule = nil
mm = require "mcMasterModule"

--Probing module
package.loaded.Probing = nil
prb = require "mcProbing"
--mc.mcCntlSetLastError(inst, "Probe Version " .. prb.Version());

--ErrorCheck module Added 11-4-16
package.loaded.mcErrorCheck = nil
mcErrorCheck = require "mcErrorCheck"

---------------------------------------------------------------
-- Get fixtue offset pound variables function Updated 5-16-16
---------------------------------------------------------------
function GetFixOffsetVars()
    local FixOffset = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_14)
    local Pval = mc.mcCntlGetPoundVar(inst, mc.SV_BUFP)
    local FixNum, whole, frac

    if (FixOffset ~= 54.1) then --G54 through G59
        whole, frac = math.modf (FixOffset)
        FixNum = (whole - 53)
        PoundVarX = ((mc.SV_FIXTURES_START - mc.SV_FIXTURES_INC) + (FixNum * mc.SV_FIXTURES_INC))
        CurrentFixture = string.format('G' .. tostring(FixOffset))
    else --G54.1 P1 through G54.1 P100
        FixNum = (Pval + 6)
        CurrentFixture = string.format('G54.1 P' .. tostring(Pval))
        if (Pval > 0) and (Pval < 51) then -- G54.1 P1 through G54.1 P50
            PoundVarX = ((mc.SV_FIXTURE_EXPAND - mc.SV_FIXTURES_INC) + (Pval * mc.SV_FIXTURES_INC))
        elseif (Pval > 50) and (Pval < 101) then -- G54.1 P51 through G54.1 P100
            PoundVarX = ((mc.SV_FIXTURE_EXPAND2 - mc.SV_FIXTURES_INC) + (Pval * mc.SV_FIXTURES_INC))   
        end
    end
PoundVarY = (PoundVarX + 1)
PoundVarZ = (PoundVarX + 2)
return PoundVarX, PoundVarY, PoundVarZ, FixNum, CurrentFixture
--PoundVar(Axis) returns the pound variable for the current fixture for that axis (not the pound variables value).
--CurretnFixture returned as a string (examples G54, G59, G54.1 P12).
--FixNum returns a simple number (1-106) for current fixture (examples G54 = 1, G59 = 6, G54.1 P1 = 7, etc).
end

---------------------------------------------------------------
-- Button Enable function
---------------------------------------------------------------
-- Edited 11-8-2015
function ButtonEnable() --This function enables or disables buttons associated with an axis if the axis is enabled or disabled.

    AxisTable = {
        [0] = 'X',
        [1] = 'Y',
        [2] = 'Z',
        [3] = 'A',
        [4] = 'B',
        [5] = 'C'}
        
    for Num, Axis in pairs (AxisTable) do -- for each paired Num (key) and Axis (value) in the Axis table
        local rc = mc.mcAxisIsEnabled(inst,(Num)) -- find out if the axis is enabled, returns a 1 or 0
        scr.SetProperty((string.format ('btnPos' .. Axis)), 'Enabled', tostring(rc)); --Turn the button on or off
        scr.SetProperty((string.format ('btnNeg' .. Axis)), 'Enabled', tostring(rc)); --Turn the button on or off
        scr.SetProperty((string.format ('btnZero' .. Axis)), 'Enabled', tostring(rc)); --Turn the button on or off
        scr.SetProperty((string.format ('btnRef' .. Axis)), 'Enabled', tostring(rc)); --Turn the button on or off
    end
    
end

ButtonEnable() 

-- PLC script
function Mach_PLC_Script()
    local inst = mc.mcGetInstance()
    local rc = 0;
    testcount = testcount + 1
    machState, rc = mc.mcCntlGetState(inst);
    local inCycle = mc.mcCntlIsInCycle(inst);
    
    -------------------------------------------------------
    --  Calculate CSS
    -------------------------------------------------------
    local NativeUnits, rc = mc.mcCntlGetUnitsDefault(inst)
    local units, rc = mc.mcCntlGetUnitsCurrent(inst)
    local xDia = mc.mcAxisGetPos(inst, 0)
    local dia, rc = mc.mcCntlGetDiaMode(inst)
    
    if (dia == 0) then
     xDia = (xDia * 2)
    end
    
    if (NativeUnits == 200) and (units == 210) then
     xDia = (xDia * 25.4)
    elseif (NativeUnits == 210) and (units == 200) then
     xDia = (xDia / 25.4)
    end
    
    if (units == 200) then --Gcode is in inch mode (G20)
        mc.mcSpindleCalcCSSToRPM(inst, xDia, true)
    elseif (units == 210) then --Gcode is in mm mode (G21)
        mc.mcSpindleCalcCSSToRPM(inst, xDia, false)
    end
    
    -------------------------------------------------------
    --  CSS DRO
    -------------------------------------------------------
    local FeedRate, SpinRPM, CurrentCSS
    FeedRate = scr.GetProperty ("droFeedRate", "Value")
    FeedRate = tonumber(FeedRate)
    SpinRPM = scr.GetProperty("droSpinRPM", "Value")
    SpinRPM = tonumber(SpinRPM)
    CurrentCSS = (FeedRate / SpinRPM)
    if CurrentCSS ~= LastCSS then --We need to update our user DRO
        LastCSS = CurrentCSS --So we only update DRO when needed. Stops blinking DRO
        if (FeedRate > 0) and (SpinRPM > 0) then
            scr.SetProperty("droConstantSurfaceSpeed", "Value", tostring(CurrentCSS))
        else
            scr.SetProperty("droConstantSurfaceSpeed", "Value", "0.0000")
        end
    end
    
    -------------------------------------------------------
    --  Coroutine resume
    -------------------------------------------------------
    if (wait ~= nil) and (machState == 0) then --wait exist and state == idle
        local state = coroutine.status(wait)
        if state == "suspended" then --wait is suspended
            coroutine.resume(wait)
        end
    end
    
    -------------------------------------------------------
    --Set current offset x wear
    -------------------------------------------------------
    
    local m_currentOffset, XWear, XTT
    
    XWear = scr.GetProperty("droXWearOffset", "Value")
    XWear = tonumber(XWear)
    m_currentOffset = mc.mcCntlGetPoundVar(inst, mc.SV_CUR_LENGTH_INDEX)
    XTT, rc = mc.mcToolGetData(inst, mc.MTOOL_LATHE_X_W, m_currentOffset)
    if (XWear ~= XTT) then
        scr.SetProperty("droXWearOffset", "Value", tostring(XTT))
    end
    
    -------------------------------------------------------
    --  Cycle time label update
    -------------------------------------------------------
    --Requires a static text box named "CycleTime" on the screen
    if (machEnabled == 1) then
        local cycletime = mc.mcCntlGetRunTime(inst, time)
        scr.SetProperty("CycleTime", "Label", SecondsToTime(cycletime))
    end
    
    -------------------------------------------------------
    --Tool Offset Active
    -------------------------------------------------------
    
    local offset = scr.GetProperty('currenttool offset','Value');
    
    if (offset == nil) then
    
        scr.SetProperty('tool offset active', 'Fg Color', '#8B8B8B');--Black
        scr.SetProperty('tool offset active', 'Bg Color', '#C0C0C0');--Light Grey
    
     -- elseif (offset ~= 'droToolNumber') then
    
        
        scr.SetProperty('tool offset active', 'Fg Color', '#8B8B8B');--Black
        scr.SetProperty('tool offset active', 'Bg Color', '#C0C0C0');--RED
    
        
       elseif (offset =='droToolNumber') then
    
        scr.SetProperty('tool offset active', 'Fg Color', '#8B8B8B');--Black
        scr.SetProperty('tool offset active', 'Bg Color', '#FFFF00');--YELLOW
    end
    
    -------------------------------------------------------
    --  Set Spindle Ratio DRO
    -------------------------------------------------------
    local spinmotormax = scr.GetProperty('droSpinMotorMax', 'Value');   
    local rangemax = scr.GetProperty('droRangeMax', 'Value');   
    local ratio = (rangemax / spinmotormax);   
    scr.SetProperty('droRatio', 'Value', tostring(ratio));
    ------------------------------------------------------
    
    -------------------------------------------------------
    --  Set Feedback Ratio DRO Updated 5-30-16
    -------------------------------------------------------
    local range, rc = mc.mcSpindleGetCurrentRange(inst)
    local fbratio, rc = mc.mcSpindleGetFeedbackRatio(inst, range)
    scr.SetProperty('droFeedbackRatio', 'Value', tostring(fbratio))
    
    -------------------------------------------------------
    --  PLC First Run
    -------------------------------------------------------
    --if (testcount == 1) then
    if (testcount == 1) then --Set Keyboard input startup state
        local iReg = mc.mcIoGetHandle (inst, "Keyboard/Enable")
        mc.mcIoSetState(iReg, 1) --Set register to 1 to ensure KeyboardInputsToggle function will do a disable.
        KeyboardInputsToggle()
    
        prb.LoadSettings()
    
        ---------------------------------------------------------------
        -- Set Persistent DROs.
        ---------------------------------------------------------------
    
        DROTable = {
        [1000] = "droJogRate",
        [1001] = "droSurfXPos",
        [1002] = "droSurfYPos",
        [1003] = "droSurfZPos",
        [1004] = "droInCornerX",
        [1005] = "droInCornerY",
        [1006] = "droInCornerSpaceX",
        [1007] = "droInCornerSpaceY",
        [1008] = "droOutCornerX",
        [1009] = "droOutCornerY",
        [1010] = "droOutCornerSpaceX",
        [1011] = "droOutCornerSpaceY",
        [1012] = "droInCenterWidth",
        [1013] = "droOutCenterWidth",
        [1014] = "droOutCenterAppr",
        [1015] = "droOutCenterZ",
        [1016] = "droBoreDiam",
        [1017] = "droBossDiam",
        [1018] = "droBossApproach",
        [1019] = "droBossZ",
        [1020] = "droAngleXpos",
        [1021] = "droAngleYInc",
        [1022] = "droAngleXCenterX",
        [1023] = "droAngleXCenterY",
        [1024] = "droAngleYpos",
        [1025] = "droAngleXInc",
        [1026] = "droAngleYCenterX",
        [1027] = "droAngleYCenterY",
        [1028] = "droCalZ",
        [1029] = "droGageX",
        [1030] = "droGageY",
        [1031] = "droGageZ",
        [1032] = "droGageSafeZ",
        [1033] = "droGageDiameter",
        [1034] = "droEdgeFinder",
        [1035] = "droGageBlock",
        [1036] = "droGageBlockT"
    --    [1036] = "droGageBlockT",
    --    [1037] = "droProbeTravel",
    --    [1038] = "droProbeRate"
    
        }
        
        -- ******************************************************************************************* --
        --  _   _   _  __          __             _____    _   _   _____   _   _    _____   _   _   _  --
        -- | | | | | | \ \        / /     /\     |  __ \  | \ | | |_   _| | \ | |  / ____| | | | | | | --
        -- | | | | | |  \ \  /\  / /     /  \    | |__) | |  \| |   | |   |  \| | | |  __  | | | | | | --
        -- | | | | | |   \ \/  \/ /     / /\ \   |  _  /  | . ` |   | |   | . ` | | | |_ | | | | | | | --
        -- |_| |_| |_|    \  /\  /     / ____ \  | | \ \  | |\  |  _| |_  | |\  | | |__| | |_| |_| |_| --
        -- (_) (_) (_)     \/  \/     /_/    \_\ |_|  \_\ |_| \_| |_____| |_| \_|  \_____| (_) (_) (_) --
        --                                                                                             --
        -- The following is a loop. As a rule of thumb loops should be avoided in the PLC Script.      --
        -- However, this loop only runs during the first run of the PLC script so it is acceptable.    --
        -- ******************************************************************************************* --                                                         
    
        for name,number in pairs (DROTable) do -- for each paired name (key) and number (value) in the DRO table
            local droName = (DROTable[name]) -- make the variable named droName equal the name from the table above
            --wx.wxMessageBox (droName)
            local val = mc.mcProfileGetString(inst, "PersistentDROs", (droName), "NotFound") -- Get the Value from the profile ini
            if(val ~= "NotFound")then -- If the value is not equal to NotFound
                scr.SetProperty((droName), "Value", val) -- Set the dros value to the value from the profile ini
            end -- End the If statement
        end -- End the For loop
        ---------------------------------------------------
    
    end
    -------------------------------------------------------
    
    --This is the last thing we do.  So keep it at the end of the script!
    machStateOld = machState;
    machWasEnabled = machEnabled;
    
end

-- Signal script
function Mach_Signal_Script(sig, state)
    if SigLib[sig] ~= nil then
        SigLib[sig](state);
    end
end

-- Timer script
-- 'timer' contains the timer number that fired the                                                             script.
function Mach_Timer_Script(timer)
    
end

-- Screen unload script
function Mach_Screen_Unload_Script()
    
end

function btnCycleStart_Left_Up_Script(...)
    CycleStart()
end
function btnStop_Left_Up_Script(...)
    CycleStop()
    --local inst = mc.mcGetInstance();
    --mc.mcCntlCycleStop(inst);
    --mc.mcSpindleSetDirection(inst, 0);
    --mc.mcCntlSetLastError("Cycle Stopped");
    
    --if not idle loop
    --mc.mcCntlMdiExecute ("G01 G53 Z0.000");
    
    --local inst = mc.mcGetInstance()
    --mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG00 X0 Y0 A0\nG00 Z0")
    
end
function btnReset_Left_Up_Script(...)
    local inst = mc.mcGetInstance()
    mc.mcCntlReset(inst)
    mc.mcSpindleSetDirection(inst, 0)
    mc.mcCntlSetLastError(inst, '')
end
function btnHelpDocs_Left_Up_Script(...)
    OpenDocs()
    --local inst = mc.mcGetInstance()
    --local dir = mc.mcCntlGetMachDir(inst);
    --wx.wxExecute("explorer.exe /open," .. dir .. "\\Docs\\");
    
end
function btnNewestAddition_Clicked_Script(...)
    wx.wxMessageBox("As new additions are added clicking the Newest Additions button will do potentially different things. It may open a document, launch a Wizard, etc. What it does may not change with each new release but it would be a good idea to check it after each update.")
end
function btnDispLeft_Left_Up_Script(...)
    -- Left
    local inst = mc.mcGetInstance();
    local rc = scr.SetProperty("toolpath1", "View", "2")
    local rc = scr.SetProperty("toolpath2", "View", "2")
    local rc = scr.SetProperty("toolpath3", "View", "2")
    local rc = scr.SetProperty("toolpath4", "View", "2")
    local rc = scr.SetProperty("toolpath5", "View", "2")
    
end
function btnDispISO_Left_Up_Script(...)
    -- ISO
    local inst = mc.mcGetInstance();
    local rc = scr.SetProperty("toolpath1", "View", "4")
    local rc = scr.SetProperty("toolpath2", "View", "4")
    local rc = scr.SetProperty("toolpath3", "View", "4")
    local rc = scr.SetProperty("toolpath4", "View", "4")
    local rc = scr.SetProperty("toolpath5", "View", "4")
end
function btnDispTop_Left_Up_Script(...)
    --Top
    local inst = mc.mcGetInstance();
    local rc = scr.SetProperty("toolpath1", "View", "5")
    local rc = scr.SetProperty("toolpath2", "View", "5")
    local rc = scr.SetProperty("toolpath3", "View", "5")
    local rc = scr.SetProperty("toolpath4", "View", "5")
    local rc = scr.SetProperty("toolpath5", "View", "5")
end
function btnDispBottom_Left_Up_Script(...)
    -- Bottom
    local inst = mc.mcGetInstance();
    local rc = scr.SetProperty("toolpath1", "View", "1")
    local rc = scr.SetProperty("toolpath2", "View", "1")
    local rc = scr.SetProperty("toolpath3", "View", "1")
    local rc = scr.SetProperty("toolpath4", "View", "1")
    local rc = scr.SetProperty("toolpath5", "View", "1")
end
function btnDispRight_Left_Up_Script(...)
    -- Right
    local inst = mc.mcGetInstance();
    local rc = scr.SetProperty("toolpath1", "View", "3")
    local rc = scr.SetProperty("toolpath2", "View", "3")
    local rc = scr.SetProperty("toolpath3", "View", "3")
    local rc = scr.SetProperty("toolpath4", "View", "3")
    local rc = scr.SetProperty("toolpath5", "View", "3")
end
function btnNegX_Clicked_Script(...)
    --local inst = mc.mcGetInstance();
    
    --local dir = mc.mcJogVelocityStart(mInst, axis, dir);
    --if (dir == -1) then
      --  scr.SetProperty('btnNegX', 'Bg Color', '#DBAD24');--Amber
    --end
    
    
end
function btnToggleJogMode_Left_Up_Script(...)
    ButtonJogModeToggle()
end
function btnKeyboardJog_Left_Up_Script(...)
    --KeyboardDisable()
    KeyboardInputsToggle()
end
function droJogRate_On_Modify_Script(...)
    local inst = mc.mcGetInstance()
    local val = scr.GetProperty("droJogRate", "Value")
    mc.mcProfileWriteString(inst, "PersistentDROs", "droJogRate", string.format (val)) --Create a register and write the machine coordinates to it
end
function tabPositionsExtens_On_Enter_Script(...)
    local rc;
    local tabG_Mdi, rc = scr.GetProperty("nbGCodeMDI1", "Current Tab")
    
    --See if we have to do an MDI command
    if (tonumber(tabG_Mdi) == 1 ) then
        scr.SetProperty('btnCycleStart', 'Label', 'Cycle Start\nMDI');
    else
        scr.SetProperty('btnCycleStart', 'Label', 'Cycle Start\nGcode');
    end
end
function btnRefAll_Left_Up_Script(...)
    --RefAllHome()
    wait = coroutine.create (RefAllHome) --Run the RefAllHome function as a coroutine named wait.
    --See RefAllHome function in screen load script for coroutine.yield and PLC script for coroutine.resume
end
function btnGotoZero_Left_Up_Script(...)
    GoToWorkZero()
    --local inst = mc.mcGetInstance()
    --mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG00 X0 Y0 A0\nG00 Z0")
    
end
function btnDerefAll_Left_Up_Script(...)
    local inst = mc.mcGetInstance();
    mc.mcAxisDerefAll(inst);
end
function droXWearOffset_On_Update_Script(...)
    --Set current offset x wear
    
    local m_inst, m_currentOffset, XWear
    
    XWear = scr.GetProperty("droXWearOffset", "Value")
    XWear = tonumber(XWear)
    m_inst = mc.mcGetInstance()
    m_currentOffset = mc.mcCntlGetPoundVar(m_inst, mc.SV_CUR_LENGTH_INDEX)
    mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_X_W, m_currentOffset, XWear) --set the wear offset
end
function droXWearOffset_On_Modify_Script(...)
    --Set current offset x wear
    
    local m_inst, m_currentOffset, XWear
    
    XWear = scr.GetProperty("droXWearOffset", "Value")
    XWear = tonumber(XWear)
    m_inst = mc.mcGetInstance()
    m_currentOffset = mc.mcCntlGetPoundVar(m_inst, mc.SV_CUR_LENGTH_INDEX)
    mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_X_W, m_currentOffset, XWear) --set the wear offset
end
function nbGCodeInput1_On_Enter_Script(...)
     scr.SetProperty('btnCycleStart', 'Label', 'Cycle Start\nGcode');
end
function nbMDIInput1_On_Enter_Script(...)
    scr.SetProperty('btnCycleStart', 'Label', 'Cycle Start\nMDI');
end
function CannedCyclesPanel_Script(...)
    local inst = mc.mcGetInstance()
    local MachDirectory = mc.mcCntlGetMachDir(inst)
    local MachProfileName = mc.mcProfileGetName(inst)
    ------------------------- Wiz Panel -------------------------
    --package.path =  MachDirectory .. "//Wizards//?.lua;" .. MachDirectory .. "//Wizards//?.mcc;" .. MachDirectory .. "//Wizards//?.mcs;"
    local ScriptPath = MachDirectory .. "/Wizards//?.lua;" .. MachDirectory .. "/Wizards//?.mcc;" .. MachDirectory .. "//Wizards//?.mcs;"
    local spos = string.find(package.path, ScriptPath)
    if (spos == nil) then
        package.path = package.path .. ";" .. ScriptPath
    end   
    package.loaded.wizpanel = nil
    wizpanel = require "Lathe Canned Cycles"
    ------------------------- END Modules -------------------------
end
function SET_X_Clicked_Script(...)
    --SetToolXOffset
    local m_inst, m_currentOffset, m_dia, m_diaMode, m_currentTool, m_side, m_machinePos, m_dir, offset
    
    m_inst = mc.mcGetInstance()
    m_currentOffset = mc.mcCntlGetPoundVar(m_inst, mc.SV_CUR_LENGTH_INDEX)
    
    if (m_currentOffset > 0) and (m_currentOffset < 100) then --A valid tool number is active
        m_dia = scr.GetProperty('droSetX', 'Value')
        m_diaMode = mc.mcCntlGetDiaMode(m_inst)
        m_currentTool = mc.mcCntlGetPoundVar(m_inst, mc.SV_CUR_TOOL_NUMBER)
        m_side = mc.mcToolGetData(m_inst, mc.MTOOL_LATHE_TOOLSLIDE, m_currentOffset)
        m_machinePos = mc.mcAxisGetMachinePos(m_inst, mc.X_AXIS)
        m_dir = 1
        
        if (tonumber(m_side) <= 0) then--If this is negitive we need to flip the tool
            m_dir = -1
        end
        
        if (m_diaMode) then
            m_dia = m_dia/2
        end
        offset = m_machinePos - (m_dia  * m_dir)
        
        mc.mcCntlSetPoundVar(m_inst, 10000, 0.0000) --Zero X wear offset
        mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_X, m_currentOffset, offset) --Set the Offset
        mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_X_W, m_currentOffset, 0) --Clear the wear offset
    else
        wx.wxMessageBox("!!! A valid tool offset must be active to set it !!!\n\nPlease activate a valid tool offset and try again.")
    end
    
end
function SET_Z_Clicked_Script(...)
    --SetToolZOffset
    local m_inst, FixOffset, Pval, FixNum, whole, frac, PoundVarX, PoundVarY, PoundVarZ, CurrentFixture, m_dist, m_currentTool, m_currentOffset, m_ZMachine, CurFixZ, offset
    
    m_inst = mc.mcGetInstance();
    
    FixOffset = mc.mcCntlGetPoundVar(m_inst, mc.SV_MOD_GROUP_14)
    Pval = mc.mcCntlGetPoundVar(m_inst, mc.SV_BUFP)
    
    if (FixOffset ~= 54.1) then --G54 through G59
        whole, frac = math.modf (FixOffset)
        FixNum = (whole - 53)
        PoundVarX = ((mc.SV_FIXTURES_START - mc.SV_FIXTURES_INC) + (FixNum * mc.SV_FIXTURES_INC))
        CurrentFixture = string.format('G' .. tostring(FixOffset))
    else --G54.1 P1 through G54.1 P100
        FixNum = (Pval + 6)
        CurrentFixture = string.format('G54.1 P' .. tostring(Pval))
        if (Pval > 0) and (Pval < 51) then -- G54.1 P1 through G54.1 P50
            PoundVarX = ((mc.SV_FIXTURE_EXPAND - mc.SV_FIXTURES_INC) + (Pval * mc.SV_FIXTURES_INC))
        elseif (Pval > 50) and (Pval < 101) then -- G54.1 P51 through G54.1 P100
            PoundVarX = ((mc.SV_FIXTURE_EXPAND2 - mc.SV_FIXTURES_INC) + (Pval * mc.SV_FIXTURES_INC))   
        end
    end
    PoundVarY = (PoundVarX + 1)
    PoundVarZ = (PoundVarX + 2)
    
    m_dist = scr.GetProperty('droSetZ', 'Value')
    m_dist = tonumber (m_dist)-- * -1)
    m_currentTool = mc.mcCntlGetPoundVar(m_inst, mc.SV_CUR_TOOL_NUMBER);
    m_currentOffset = mc.mcCntlGetPoundVar(m_inst, mc.SV_CUR_LENGTH_INDEX);
    m_ZMachine = mc.mcAxisGetMachinePos(m_inst, mc.Z_AXIS)
    CurFixZ = mc.mcCntlGetPoundVar(inst, PoundVarZ)
    --offset = ((CurFixZ * -1) + (m_dist * -1))
    offset = ((m_ZMachine * -1) - (CurFixZ * -1) - (m_dist * -1))
    offset = (offset * -1)
    
    if (m_currentTool == 1) then --We are attempting to set tool 1's offset, pop up the message box
    
        UI = {}
        
        
        -- create MyDialog1
        UI.MyDialog1 = wx.wxDialog (wx.NULL, wx.wxID_ANY, "Message", wx.wxDefaultPosition, wx.wxSize( 542,342 ), wx.wxDEFAULT_DIALOG_STYLE )
            UI.MyDialog1:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize )
            UI.MyDialog1 :SetForegroundColour( wx.wxSystemSettings.GetColour( wx.wxSYS_COLOUR_WINDOW ) )
            UI.MyDialog1 :SetBackgroundColour( wx.wxColour( 255, 255, 255 ) )
            
            UI.bSizer1 = wx.wxBoxSizer( wx.wxVERTICAL )
            
            UI.bSizer2 = wx.wxBoxSizer( wx.wxHORIZONTAL )
            
            UI.gSizer1 = wx.wxGridSizer( 3, 1, 0, 0 )
            
            UI.m_staticText2 = wx.wxStaticText( UI.MyDialog1, wx.wxID_ANY, "!!! Warning !!!\nSetting the tool offset for tool 1 has the potential to corrupt your entire tool table.\n\n", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxALIGN_CENTRE )
            --UI.m_staticText2:Wrap( -1 )
            UI.m_staticText2:Wrap( 300 )
            UI.m_staticText2:SetFont( wx.wxFont( 12, 70, 90, 92, False, "" ) )
            UI.m_staticText2:SetForegroundColour( wx.wxColour( 255, 0, 0 ) )
            
            UI.gSizer1:Add( UI.m_staticText2, 0, wx.wxALIGN_CENTER + wx.wxALL, 5 )
            
            UI.m_staticText1 = wx.wxStaticText( UI.MyDialog1, wx.wxID_ANY, "You are attempting to set the Z offset for tool #1 (Master Tool). The Z offset for tool #1 (Master Tool) should be 0 and should be set with 0 Z fixture offset. Proceed with caution!\n\nIf you are unsure what you should do play it safe and press the cancel button.\n\nIf you want to clear the offset for tool #1 press the clear button.\n\nIf you want to set tool #1's offset to the value you have in your Set Z Offset DRO press the Continue button.", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxALIGN_CENTRE )
            UI.m_staticText1:Wrap( 500 )
            UI.m_staticText1:SetForegroundColour( wx.wxColour( 0, 0, 0 ) )
            UI.m_staticText1:SetBackgroundColour( wx.wxColour( 255, 255, 255 ) )
            
            UI.gSizer1:Add( UI.m_staticText1, 0, wx.wxALIGN_CENTER + wx.wxALL, 5 )
            
            UI.gSizer2 = wx.wxGridSizer( 0, 3, 0, 0 )
            
            UI.m_buttonCancel = wx.wxButton( UI.MyDialog1, wx.wxID_ANY, "Cancel", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
            UI.gSizer2:Add( UI.m_buttonCancel, 0, wx.wxALIGN_CENTER + wx.wxALL, 5 )
            
            UI.m_buttonClearOffset = wx.wxButton( UI.MyDialog1, wx.wxID_ANY, "Clear Offset", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
            UI.gSizer2:Add( UI.m_buttonClearOffset, 0, wx.wxALIGN_CENTER + wx.wxALL, 5 )
            
            UI.m_buttonContinue = wx.wxButton( UI.MyDialog1, wx.wxID_ANY, "Continue", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
            UI.gSizer2:Add( UI.m_buttonContinue, 0, wx.wxALIGN_CENTER + wx.wxALL, 5 )
            
            
            UI.gSizer1:Add( UI.gSizer2, 1, wx.wxEXPAND, 5 )
            
            
            UI.bSizer2:Add( UI.gSizer1, 1, wx.wxEXPAND, 5 )
            
            
            UI.bSizer1:Add( UI.bSizer2, 1, wx.wxEXPAND, 5 )
            
            
            UI.MyDialog1:SetSizer( UI.bSizer1 )
            UI.MyDialog1:Layout()
            
            UI.MyDialog1:Centre( wx.wxBOTH )
            
            -- Connect Events
            
            UI.MyDialog1:Connect( wx.wxEVT_CLOSE_WINDOW, function(event)
            --implements MyDialog1OnClose
            UI.MyDialog1:Destroy()
            
            event:Skip()
            end )
            
            UI.MyDialog1:Connect( wx.wxEVT_INIT_DIALOG, function(event)
            --implements MyDialog1OnInitDialog
            
            event:Skip()
            end )
            
            UI.m_buttonCancel:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
            --implements m_buttonCancelOnButtonClick
            UI.MyDialog1:Close(true)
            UI.MyDialog1:Destroy()
            
            event:Skip()
            end )
            
            UI.m_buttonClearOffset:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
            --implements m_buttonClearOffsetOnButtonClick
            mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_Z_W, m_currentOffset, 0);--Clear the wear offset
            mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_Z, m_currentOffset, 0.0000);--Set the Offset
            UI.MyDialog1:Close(true)
            UI.MyDialog1:Destroy()
            
            event:Skip()
            end )
            
            UI.m_buttonContinue:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
            --implements m_buttonContinueOnButtonClick
            mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_Z_W, m_currentOffset, 0);--Clear the wear offset
            mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_Z, m_currentOffset, offset);--Set the Offset
            UI.MyDialog1:Close(true)
            UI.MyDialog1:Destroy()
            
            event:Skip()
            end )
            
        
        UI.MyDialog1:Show(true)
        --wx.wxGetApp():MainLoop()
    
    else
        mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_Z_W, m_currentOffset, 0);--Clear the wear offset
        mc.mcToolSetData(m_inst, mc.MTOOL_LATHE_Z, m_currentOffset, offset);--Set the Offset
    end
    
end
function btnFROMax_Left_Up_Script(...)
    local maxval = scr.GetProperty('slideFRO', 'Max Value')
    scr.SetProperty('slideFRO', 'Value', tostring(maxval));
end
function btnFROUp_Left_Up_Script(...)
    local val = scr.GetProperty('slideFRO', 'Value');
    val = tonumber(val) + 10;
    local maxval = scr.GetProperty('slideFRO', 'Max Value')
    if (tonumber(val) >= tonumber(maxval)) then
     val = maxval;
    end
    scr.SetProperty('slideFRO', 'Value', tostring(val));
end
function btnFRO100_Left_Up_Script(...)
    scr.SetProperty('slideFRO', 'Value', tostring(100));
end
function btnFROMin_Left_Up_Script(...)
    --scr.SetProperty('slideFRO', 'Value', tostring(0));
    local minval = scr.GetProperty('slideFRO', 'Min Value')
    scr.SetProperty('slideFRO', 'Value', tostring(minval));
end
function btnFRODn_Left_Up_Script(...)
    --local val = scr.GetProperty('slideFRO', 'Value');
    --val = tonumber(val) - 10;
    --if (val < 0 ) then
    --    val =0;
    --end
    --scr.SetProperty('slideFRO', 'Value', tostring(val));
    -- Down
    local val = scr.GetProperty('slideFRO', 'Value');
    val = tonumber(val) - 10;
    local minval = scr.GetProperty('slideFRO', 'Min Value')
    if (tonumber(val) <= tonumber(minval)) then
     val = minval;
    end
    scr.SetProperty('slideFRO', 'Value', tostring(val));
end
function btnSROMax_Left_Up_Script(...)
    --Max
    local maxval = scr.GetProperty('slideSRO', 'Max Value')
    scr.SetProperty('slideSRO', 'Value', tostring(maxval));
end
function btnSROUp_Left_Up_Script(...)
    -- Up
    local val = scr.GetProperty('slideSRO', 'Value');
    val = tonumber(val) + 10;
    local maxval = scr.GetProperty('slideSRO', 'Max Value')
    if (tonumber(val) >= tonumber(maxval)) then
     val = maxval;
    end
    scr.SetProperty('slideSRO', 'Value', tostring(val));
end
function btnSRO100_Left_Up_Script(...)
    -- 100
    scr.SetProperty('slideSRO', 'Value', tostring(100));
end
function btnSROMin_Left_Up_Script(...)
    -- Min
    local minval = scr.GetProperty('slideSRO', 'Min Value')
    scr.SetProperty('slideSRO', 'Value', tostring(minval));
end
function btnSRODn_Left_Up_Script(...)
    -- Down
    local val = scr.GetProperty('slideSRO', 'Value');
    val = tonumber(val) - 10;
    local minval = scr.GetProperty('slideSRO', 'Min Value')
    if (tonumber(val) <= tonumber(minval)) then
     val = minval;
    end
    scr.SetProperty('slideSRO', 'Value', tostring(val));
end
function btnSpindleCW_Left_Up_Script(...)
    SpinCW()
    --local inst = mc.mcGetInstance();
    --local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    --local sigState = mc.mcSignalGetState(sigh);
    --if (sigState == 1) then
    --    mc.mcSpindleSetDirection(inst, 0);
    --else
    --    mc.mcSpindleSetDirection(inst, 1);
    --end
    
    
end
function btnSpindleCCW_Left_Up_Script(...)
    SpinCCW()
    --local inst = mc.mcGetInstance();
    --local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    --local sigState = mc.mcSignalGetState(sigh);
    --if (sigState == 1) then
    --    mc.mcSpindleSetDirection(inst, 0);
    --else
    --    mc.mcSpindleSetDirection(inst, -1);
    --end
    
end
function btnRROMax_Left_Up_Script(...)
    --Max
    local maxval = scr.GetProperty('slideRRO', 'Max Value')
    scr.SetProperty('slideRRO', 'Value', tostring(maxval));
end
function btnRROUp_Left_Up_Script(...)
    -- Up
    local val = scr.GetProperty('slideRRO', 'Value');
    val = tonumber(val) + 10;
    local maxval = scr.GetProperty('slideRRO', 'Max Value')
    if (tonumber(val) >= tonumber(maxval)) then
     val = maxval;
    end
    scr.SetProperty('slideRRO', 'Value', tostring(val));
end
function btnRRO50_Left_Up_Script(...)
    -- 50
    scr.SetProperty('slideRRO', 'Value', tostring(50));
end
function btnRROMin_Left_Up_Script(...)
    -- Min
    local minval = scr.GetProperty('slideRRO', 'Min Value')
    scr.SetProperty('slideRRO', 'Value', tostring(minval));
end
function btnRRODn_Left_Up_Script(...)
    -- Down
    local val = scr.GetProperty('slideRRO', 'Value');
    val = tonumber(val) - 10;
    local minval = scr.GetProperty('slideRRO', 'Min Value')
    if (tonumber(val) <= tonumber(minval)) then
     val = minval;
    end
    scr.SetProperty('slideRRO', 'Value', tostring(val));
end

si quelqu'un a une piste sa serait sympa
Merci
 
Haut