Hello Guest it is March 28, 2024, 05:51:12 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - sour kraut

Pages: 1 2 3
1
Mach4 General Discussion / Re: Running a subroutine from inside a macro?
« on: February 14, 2018, 10:51:21 PM »
Some days it pays to stay off the internet. I responded in the wrong post.

http://www.machsupport.com/forum/index.php/topic,36577.msg250891.html#msg250891

Findings:

A subroutine can call a macro, and a macro can call a subroutine but more testing is needed.

2
Mach4 General Discussion / Re: Lua script detect when the cycle is running
« on: February 14, 2018, 10:48:38 PM »
$h!t, I replied in the wrong post. Sorry.

3
Mach4 General Discussion / Re: Lua script detect when the cycle is running
« on: February 14, 2018, 07:07:35 PM »
So I decided to download mach4 to my travel computer and do some testing before I get home.  Here's what I did and what I found.  I added the following 2 lines to the standard M6.mcs file after the IF THEN ELSE END. I then moved the O9010 file from the subroutine sample directory into the subroutine directory and added an incremental move in it.
 
Code: [Select]
mc.mcCntlSetLastError(inst, "INSIDE MACRO M6")
mc.mcCntlGcodeExecuteWait(inst,"M98 P9010")
 

I created a simple file to run.

Code: [Select]
G90
M6
M30

So mach called the macro and the error printed.  It then DID make the incremental motion but it didn't seem to like it really waited like the command asks for .  I then reverse the process and called a macro from a subroutine and it seemed to work the same way.  I'll have to test this in more detail when I get home.

4
Mach4 General Discussion / Re: Running a subroutine from inside a macro?
« on: February 14, 2018, 12:10:37 AM »
dude1, don't let my number of posts fool you, I've been working with industrial CNC routers for almost 20 years now so I understand macro programming but it's might be a nice read either way.  You might be thinking about Macro B which can only be run on the industrial version but you can write your own macros using Lua.  Each Profile in the Mach4Hobby directory has a subfolder called Macros where you can store them.  I only asked this because I travel for a living and am not at home this week to test this out. 

5
Mach4 General Discussion / Re: Running a subroutine from inside a macro?
« on: February 13, 2018, 05:31:46 PM »
Sorry, it was a late night last night. If I choose to store a subroutine outside of the main file, it is my understanding that the subroutine must be named using the O# convention. What I’m wondering is two fold.  First, can I call a subroutine that is stored outside of the main file from inside a macro? Second, from reading another forum post (sorry not sure which one) it sounded like I can only call one subroutine stored outside of the main file when using hobby. Is this true or did I misunderstand.

6
Mach4 General Discussion / Running a subroutine from inside a macro?
« on: February 13, 2018, 12:00:34 AM »
Very random question.  I know that the subroutine's O# or name must match the main files O# but can you call said subroutine from inside a macro?  What if I would need to call multiple subroutines from inside of a file?  Is it possible to have it open a different O# subroutine?

Thanks.

7
Mach4 General Discussion / Re: Mach 4 Feature Request
« on: November 18, 2016, 10:48:02 AM »
Better documentation.

8
Mach4 General Discussion / Re: Mach4 Signal Script
« on: November 17, 2016, 01:58:35 PM »
That worked perfectly!  Thank you very much for your help.  Now on to new frustrations!

9
Mach4 General Discussion / Re: Mach4 Signal Script
« on: November 17, 2016, 01:04:52 PM »
Let me see if I'm understanding you correctly. I do not need to change the [sig] in the code you mention to a specific input?  The code should read exactly as it originally was created?

so YES to this in the Signal script:

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

and NO to this in the Signal script:

if SigLib[mc.ISIG_INPUT63] ~= nil then
    SigLib[mc.ISIG_INPUT63](state);
end
 

I'll give that a try and see if that works.  Thanks.

10
Mach4 General Discussion / Re: Mach4 Signal Script
« on: November 17, 2016, 11:59:58 AM »
 I did add the code to reference the input but then it toggled continuously as I held the key down. Besides that, I haven't change the PLC script any. I can't find anything in the PLC script that references any IO signals.  I was under the impression that when the input changed states, this triggered the signal script to run, and then because the input changed states, the signal script called the signal library inside of the screen load script.   I guess I'm just not understanding why I need code in the PLC and what code that is.

Code: [Select]
local inst = mc.mcGetInstance()
local rc = 0;
testcount = testcount + 1
machState, rc = mc.mcCntlGetState(inst);
local inCycle = mc.mcCntlIsInCycle(inst);

-------------------------------------------------------
--  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

-------------------------------------------------------
--  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

-------------------------------------------------------
--  Set Height Offset Led
-------------------------------------------------------
local HOState = mc.mcCntlGetPoundVar(inst, 4008)
if (HOState == 49) then
    scr.SetProperty("ledHOffset", "Value", "0")
else
    scr.SetProperty("ledHOffset", "Value", "1")
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 --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()
   
    --scr.SetProperty('btnCycleStart', 'Label', 'Cycle Start\nGcode')
    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"
    }

-- ******************************************************************************************* --
--  _   _   _  __          __             _____    _   _   _____   _   _    _____   _   _   _  --
-- | | | | | | \ \        / /     /\     |  __ \  | \ | | |_   _| | \ | |  / ____| | | | | | | --
-- | | | | | |  \ \  /\  / /     /  \    | |__) | |  \| |   | |   |  \| | | |  __  | | | | | | --
-- | | | | | |   \ \/  \/ /     / /\ \   |  _  /  | . ` |   | |   | . ` | | | |_ | | | | | | | --
-- |_| |_| |_|    \  /\  /     / ____ \  | | \ \  | |\  |  _| |_  | |\  | | |__| | |_| |_| |_| --
-- (_) (_) (_)     \/  \/     /_/    \_\ |_|  \_\ |_| \_| |_____| |_| \_|  \_____| (_) (_) (_) --
--                                                                                             --
-- 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
-------------------------------------------------------

--if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT63)) == 1 then
--    -- mcSignalWait(inst, ISIG_INPUT63, WAIT_MODE_Low, 0)
--    mc.mcCntlFeedHold (inst)
--else
--    --  Do something else
--end

--This is the last thing we do.  So keep it at the end of the script!
machStateOld = machState;
machWasEnabled = machEnabled;

Pages: 1 2 3