Hello Guest it is April 18, 2024, 06:28:59 PM

Author Topic: activate script on button from script  (Read 2065 times)

0 Members and 1 Guest are viewing this topic.

Re: activate script on button from script
« Reply #10 on: September 20, 2021, 06:55:59 PM »
Steve and Daz, Back in 2016 I was helped with the same issue of how to set up an Mcode in Mach4. Steve has listed the steps again but it does not work for me.  I am not sure where I am failing but back in 2016, Daz listed putting the require line into a module load file in the profile/macros directory which Steve did not mentioned this time.  Is this an omission or a change in the version of Mach4? I think I have done everything else correctly but the Mcode programmed M100 never does anything.  I have stepped away from Mach4 and Lua for several years and am back trying to get proficient again, sorry.

I updated to the newest version today since I was running on a version from 2016 but that has not helped.  The post dealing with the topic was topic=33849.20  This time, we are taking about a toolbox which I would like to implement.  Should I start a new topic or continue here. I also am working on Steve's last help for machine state, but not successful yet.

Thanks
« Last Edit: September 20, 2021, 06:57:37 PM by thespindoctor »

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: activate script on button from script
« Reply #11 on: September 21, 2021, 01:36:37 AM »
I did mention the module load file. 

In a file called MyToolbox.mcs in your profile's macros directory:
Code: [Select]
mt = require("MyToolboxModule") -- mt is the namespace by which you access the functions in the module.  Short for "My Toolbox". :)

There are several examples out here on the forum that use one file to load/require all modules that you want in the macro script environment.  But I like to put each require into their own separate file, named appropriately of course.  To me, it is a little more clear when you go looking at the stuff months from now.  :) 

Steve
Re: activate script on button from script
« Reply #12 on: September 23, 2021, 12:46:04 PM »
How about using register flags like switches on the old machines before CNC

have reg1, reg2, reg3.  0=off 1=on

reg1 on and reg2 and reg3 off means automatic testing started go ahead and do G code move

reg1on and reg2 on and reg3 off means G code move finished so ok to record from analog inputs then when finished recording turn reg3 on

reg1,2,3 on means done and now save data and switch reg2 and 3 off indicating back to G code move

Re: activate script on button from script
« Reply #13 on: September 28, 2021, 08:32:14 AM »
function WaitForIdle()
    local state = mc.mcCntlGetState()
    if (state == mc.MC_STATE_IDLE) then
         return true
    end
    return false
end

cant get this to work  tried lots of stuff but it will not compile

thanks
Re: activate script on button from script
« Reply #14 on: September 28, 2021, 11:15:45 AM »
You are missing the 'inst' from mcCntlGetState.. see below

Code: [Select]
function WaitForIdle()
    local inst = mc.mcGetInstance()
    local state = mc.mcCntlGetState(inst)
    if (state == mc.MC_STATE_IDLE) then
         return true
    end
    return false
end
Re: activate script on button from script
« Reply #15 on: September 28, 2021, 12:58:36 PM »
function WaitForIdle()
    local inst = mc.mcGetInstance()
    local state = mc.mcCntlGetState(inst)
    if (state == mc.MC_STATE_IDLE) then
         return true
    end
    return false
end

I think I tried the inst without success, but will try again   thanks
Re: activate script on button from script
« Reply #16 on: September 28, 2021, 01:03:57 PM »
function WaitForIdle()
    local inst = mc.mcGetInstance()
    local state = mc.mcCntlGetState(inst)
    if (state == mc.MC_STATE_IDLE) then
         return true
    else
    return false
   end --added end here
end

is this better but I think it still fails I will try both
Re: activate script on button from script
« Reply #17 on: September 30, 2021, 09:11:11 AM »
This is the proper script!

function WaitForIdle()
   local inst = mc.mcGetInstance()
   local state = mc.mcCntlGetPoundVar(inst, mc.SV_MSTATE)--Returns the Machine State
   --Idle will return 0
      if (state == 0) then
      return true
   else
      return false
   end
end

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: activate script on button from script
« Reply #18 on: September 30, 2021, 01:37:16 PM »
I would use mc.mcCntlGetState(inst) over the #var.  The G code variables can be stale depending on what the interpreter is doing. 

This compiles fine:
Code: [Select]
function WaitForIdle()
    local inst = mc.mcGetInstance()
    local state = mc.mcCntlGetState(inst)
    if (state == mc.MC_STATE_IDLE) then
return true
    end
    return false
end

Steve
Re: activate script on button from script
« Reply #19 on: September 30, 2021, 01:58:04 PM »
Thanks Steve