Hello Guest it is April 24, 2024, 03:13:12 PM

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

311
Mach4 General Discussion / Re: Running a subroutine from inside a macro?
« on: February 14, 2018, 12:42:34 AM »
There are multiple definitions of a macro.  If your gcode had a m900, what would your m900.mcs code contain?  Please provide a simplified example and we may be able to better answer how your definition  of macro differs from Mach4's.

RT

312
Mach4 General Discussion / Re: Running a subroutine from inside a macro?
« on: February 13, 2018, 10:44:01 AM »
Your question is a little bit confusing.  O# are used in gcode files, macros use function calls.  Could you restate the question so we know whether your trying to execute gcode files from a macro or another macro or anther function in the same macro?

RT

313
Mach4 General Discussion / Re: Can mcScriptExecute be called from a macro?
« on: February 10, 2018, 05:42:19 PM »
Thanks DAZ ;D

Could you point me to, or expound on, the difference between mcScriptExecute and mcScriptExecutePrivate?

It does work but I'm not sure if it will work when I start doing things I shouldn't

Code: [Select]
---------------------------------
--Macro to execute a script from call to m9001 with script name commented:
--N0100 m9001 (TestScript.mcs)
---------------------------------
function m9001()
  local inst=mc.mcGetInstance()
  local profile = mc.mcProfileGetName(inst)
  local path = mc.mcCntlGetMachDir(inst)
  local pn=path.."\\Profiles\\"..profile..'\\macros\\'
  local ln=mc.mcCntlGetGcodeLineNbr(0)
  local s=tostring(mc.mcCntlGetGcodeLine(0,ln))
  local n=string.find(s,'(',1,true)
  s=string.sub(s,n+1)
  n=string.find(s,')',1,true)
  s=string.sub(s,1,n-1)
  local fn=wx.wxFileName.FileExists(pn..s)
  if fn==true then
    mc.mcScriptExecutePrivate(0,pn..s,false)
  end
  return
end

if mc.mcInEditor()==1 then
 m9001()
end

It would be nice if it did, I hate having to keep updating the list of what each m... does.  Just naming the script for what it does and calling it with the same macro with the name commented would suit my way of thinking, which is always a bit twisted  ::)

RT

314
Mach4 General Discussion / Can mcScriptExecute be called from a macro?
« on: February 10, 2018, 04:34:50 PM »
Can mcScriptExecute be called from a macro?

I have deleted some file and path checking to verify that the full path and filename are correct and found.  The 'TestScript.mcs' simply contains a mc.mcCntlSetLastError message.  When run in the editor you can step through the code, it hangs for a few seconds on the script execute then moves to the next line.  After completing the debug the editor declares itself closing due to an error. 

function m9001()
    mc.mcScriptExecute(0,'c:\\mach4Hobby\\profiles\\MyTurn4\\macros\\'..'TestScript.mcs',false)
end

if mc.mcInEditor()==1 then
 m9001()
end

Is using mcScriptExecute in a macro not allowed?

TIA

RT

315
Since I don’t use a CAM program often I find myself writing macros and always need to know what settings are current.

I’m not very good at remembering which parameters and letters are supposed to be sent for macros that I created awhile ago.  You know, m6875 D.25 L1.5 P15…which did d, l and  P stand for?  And in your macro having to grab the values from the param list.

if (hVars ~= nil) then
    local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_D)
    if(DFlag == 1) then
      local dia = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_D)
    end
    local LFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_L)
    if(LFlag == 1) then
      local length = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_L)
    end
    local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_P)
    if(PFlag == 1) then
      local DOC= mc.mcCntlGetLocalVar(inst, hVars, mc.SV_P)
    end
  end

Wouldn’t it be nice if you could just read the values from the panel dro’s, led’s,… from your macro
function m6875()
local dia=myModule.getProperty(‘droDia’,’Value’)
local length=myModule.getProperty(‘txtLength’,’Value’)
local DOC=myModule.getProperty(‘droDia’,’Value’)

end

With the following additions you can get/set screen properties.  Concept:

Create 4 gRegs0 registers:
gRegs0:gpFlag
gRegs0:gpComponentName
gRegs0:gpComponentAttribute
gRegs0:gpComponentResult

Macro calls for getting/setting a component’s property through a module function that sets registers and sets a register flag to request the action. Then waits for the flag to indicate that it is finished.
PLC monitors a register to determine if a get or set property has been called by a macro, when requested, calls the function in the Load Script
Load script function reads the component name and component property from registers and either gets/sets the property.  Posts the result in a register and sets the flag that it is finished.

PLC monitor

Code: [Select]
------------------------------------------------------------------
--PLC script addition
------------------------------------------------------------
-- checks to see if macro/module has requested a screen property --myChangeProperty()
------------------------------------------------------------

local hReg,rc= mc.mcRegGetHandle(inst,'gRegs0/gpFlag')
if hReg~=nil then
  local flag=mc.mcRegGetValue(hReg)
  if flag==0 then return end      --no request
  if flag==1 then                 --new request to get a property
    mc.mcRegSetValueLong(hReg,2)  --set flag to processing request
    myGetProperty()               --get the requested data and set result and set flag to 0
  end
  if flag==3 then                 --new request to set a property
    mc.mcRegSetValueLong(hReg,2)  --set flag to processing request
    mySetProperty()               --set the requested property and set result and set flag to 0
  end
end

Screen Load Functions

Code: [Select]
------------------------------------------------
--Add to Screen Load Script
------------------------------------------------
function myGetProperty()
  local hflag=mc.mcRegGetHandle(inst,'gRegs0/gpFlag')
  local hcmp=mc.mcRegGetHandle(inst,'gRegs0/gpComponentName')
  local hattr=mc.mcRegGetHandle(inst,'gRegs0/gpComponentAttribute')
  local hrslt=mc.mcRegGetHandle(inst,'gRegs0/gpComponentResult')
 
  local Cname=mc.mcRegGetValueString(hcmp)
  local Cattr=mc.mcRegGetValueString(hattr)
  local Rslt,rc=scr.GetProperty(Cname,Cattr)

  if (rc == mc.MERROR_NOERROR) then
    mc.mcRegSetValueString(hrslt,tostring(Rslt))
    mc.mcRegSetValueString(hcmp,'')
    mc.mcRegSetValueString(hattr,'')
    mc.mcRegSetValue(hflag,0)
  elseif rc~=nil then
    mc.mcRegSetValueString(hrslt,'')
    mc.mcRegSetValue(hflag,rc)
  end
end 
 
function mySetProperty()
  local hflag=mc.mcRegGetHandle(inst,'gRegs0/gpFlag')
  local hcmp=mc.mcRegGetHandle(inst,'gRegs0/gpComponentName')
  local hattr=mc.mcRegGetHandle(inst,'gRegs0/gpComponentAttribute')
  local hrslt=mc.mcRegGetHandle(inst,'gRegs0/gpComponentResult')
 
  local Cname=mc.mcRegGetValueString(hcmp)
  local Cattr=mc.mcRegGetValueString(hattr)
  local Rslt=mc.mcRegGetValueString(hrslt)
  local rc=scr.SetProperty(Cname,Cattr,Rslt)
  if (rc == mc.MERROR_NOERROR) then
    mc.mcRegSetValueString(hrslt,Rslt)
    mc.mcRegSetValueString(hcmp,'')
    mc.mcRegSetValueString(hattr,'')
    mc.mcRegSetValue(hflag,0)
  elseif rc~=nil then
    mc.mcRegSetValueString(hrslt,'')
    mc.mcRegSetValueString(hflag,rc)
  end
end 

Module Code

Code: [Select]
------------------------------------------------------------------
--Module definition
------------------------------------------------------------------
local rtModule = {}
  function rtModule.rtChangeProperty(cName,cAttr,getSet,vlu)
  local hflag=mc.mcRegGetHandle(inst,'gRegs0/gpFlag')
  local hcmp=mc.mcRegGetHandle(inst,'gRegs0/gpComponentName')
  local hattr=mc.mcRegGetHandle(inst,'gRegs0/gpComponentAttribute')
  local hrslt=mc.mcRegGetHandle(inst,'gRegs0/gpComponentResult')
   
  mc.mcRegSetValueString(hcmp,cName)
  mc.mcRegSetValueString(hattr,cAttr)
  mc.mcRegSetValue(hflag,getSet)
  mc.mcRegSetValueString(hrslt,tostring(vlu))
  wx.wxMilliSleep(200)
  while mc.mcRegGetValue(hflag)==2 do
    wx.wxMilliSleep(100)
  end
  local Rslt,rc=mc.mcRegGetValueString(hrslt)
  return Rslt
end 

function rtModule.rtGetProperty(cName,cAttr)
  return rtModule.rtChangeProperty(cName,cAttr,1)
end;

function rtModule.rtSetProperty(cName,cAttr,vlu)
  if vlu==nil then wx.wxMessageBox('Invalid Value') return end
  return rtModule.rtChangeProperty(cName,cAttr,3,vlu)
end;

return rtModule

Macro

Code: [Select]
-------------------------------------------------------------------------
--Macro for testing
--------------------------------------------------------------------------

function m995() 
--  local rslt=rt.rtGetProperty('ledMeasOnly','Value')
--  local rslt=rt.rtSetProperty('ledMeasOnly','Value',1)
 -- local rslt=rt.rtSetProperty('btn(70)','Label','new test')
--  local rslt=rt.rtSetProperty('droProbeDia','Value',0.665)

  wx.wxMessageBox('In 995: '..tostring(rslt))
end

Obviously this can be used for many other tasks beside an alternate way of getting macro parameters.

HTH


316
Mach4 General Discussion / Re: List of Control States?
« on: February 08, 2018, 04:30:54 PM »
like:
MRUN
FRUN
FH

the rest 'seem' straight forward

RT

317
Mach4 General Discussion / Re: List of Control States?
« on: February 08, 2018, 03:43:14 PM »
Code: [Select]
mcStateCheck = {
[0] = "MC_STATE_IDLE",
[1] = "MC_STATE_HOLD",
[2] = "MC_STATE_FRUN_SUB",
[3] = "MC_STATE_MRUN_SUB",
[4] = "MC_STATE_JOG",
[5] = "MC_STATE_DRYRUN",
[6] = "MC_STATE_HOME",
[7] = "MC_STATE_CONFIG",
[100] = "MC_STATE_FRUN",
[101] = "MC_STATE_FRUN_FH",
[102] = "MC_STATE_FRUN_PROBE",
[103] = "MC_STATE_FRUN_PROBE_FH",
[104] = "MC_STATE_FRUN_THREAD",
[105] = "MC_STATE_FRUN_THREAD_FH",
[106] = "MC_STATE_FRUN_FH_JOG",
[107] = "MC_STATE_FRUN_TAP",
[108] = "MC_STATE_FRUN_MACROH",
[109] = "MC_STATE_FRUN_MACROH_JOG",
[110] = "MC_STATE_FRUN_SINGLE_BLOCK",
[111] = "MC_STATE_FRUN_RETRACT",
[112] = "MC_STATE_FRUN_HOMING",
[113] = "MC_STATE_FRUN_SINGLE_BLOCK_HOLD",
[199] = "MC_STATE_FRUN_END",
[200] = "MC_STATE_MRUN",
[201] = "MC_STATE_MRUN_FH",
[202] = "MC_STATE_MRUN_PROBE",
[203] = "MC_STATE_MRUN_PROBE_FH",
[204] = "MC_STATE_MRUN_THREAD",
[205] = "MC_STATE_MRUN_THREAD_FH",
[206] = "MC_STATE_MRUN_TAP",
[207] = "MC_STATE_MRUN_MACROH",
[208] = "MC_STATE_MRUN_MACROH_JOG",
[209] = "MC_STATE_MRUN_RETRACT",
[210] = "MC_STATE_MRUN_HOMING",
[299] = "MC_STATE_MRUN_END",
}

Chaoticone put it in code tags so the formatting would be correct.

318
Mach4 General Discussion / Re: Message Box with Cancel?
« on: February 08, 2018, 03:11:23 PM »
Yes, but you asked also asked for a way to ask the user for a number for a 'position'.  Thought I would save someone in the future reading this thread some time so they don't try it for that.

319
Mach4 General Discussion / Re: Message Box with Cancel?
« on: February 08, 2018, 02:52:29 PM »
Correct me if i'm wrong but wx.wxGetNumberFromUser() only works with integers. 

hth

rt

320
Mach4 General Discussion / Re: Mach Motion Lathe Wizards Bug? Help.
« on: February 06, 2018, 10:51:27 AM »
I can only think of wo things to try.

Cycle through the button right of the 'E2' button unitl it allows you to check the 'No finish pass' checkbox. Check and uncheck the 'No roughing' checkbox, run again.

Each canned cycle that is saved has an ini file with the settings used.  The groove cycle has a setting called 'RoughingCheck=false' on my machine.  It would seem to me that it should be set to true with the type of groove you are doing since the 'No finish pass' is grayed out.  It appears to be using the finish pass settings, so get to where you can change those to what you have set in the roughing settings.  This doesn't address shy your tool settings don't change. 

Neither I nor Craig can replicate your problem so I am out of ideas.

RT