Hello Guest it is October 19, 2019, 07:01:48 PM

Author Topic: need some lua help  (Read 6139 times)

0 Members and 1 Guest are viewing this topic.

Offline dude1

*
  •  1,253 1,253
    • View Profile
need some lua help
« on: May 02, 2015, 05:12:40 AM »
I am going through the M4 scripting manual have got up to the automatic tool height section

how do i set the getregiser function in a M code header file

its this bit
A brief run through: As before the first step in the script is getting and defining necessary variables and the current state of the machine. Register values are retrieved using the GetRegister() function created in section 4.3. It is not defined in this script so it must be defined in an M code header file or a loaded module to allow access to it.

I think I have everything else working

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: need some lua help
« Reply #1 on: May 02, 2015, 09:12:01 AM »
You may have to copy/paste the GetRegister() function from the header file and put it directly into your script.
At least in the scripter, when debugging, it errors out and will not "find" that function in the header file.
It MAY work if calling from the MDI, but, I have not tested that.
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #2 on: May 02, 2015, 04:45:50 PM »
ok I tryed adding this it did not work

function GetRegister(regname)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end

is there a way of defining it as a macro

----------------------------------------------------------------------------
-- Auto Tool Setting Macro
-----------------------------------------------------------------------------
--[[
 Requires the following instance registers to be defined
 TS_XPos-----------X position of probe (machine position)
 TS_YPos-----------Y position of probe (machine position)
 TS_Type-----------Offset type (1 or 2)
 TS_TouchPos-------Z position of touch off surface (machine position)
 TS_ProbeH---------Height of probe above touch off surface
 TS_DefaultL-------Default tool length guess
 TS_Retract--------Retract distance after probe touch
 Offset Type 1-----Length of tool from gauge line to tip
 Offset Type 2-----Distance from tip of tool to the touch position
]]
--The function GetRegister() must be defined for use by macros  (its this bit I cant work out how to do)
« Last Edit: May 02, 2015, 04:54:04 PM by daniellyall »

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: need some lua help
« Reply #3 on: May 02, 2015, 08:44:08 PM »
Just in case you did not, you have to have the register defined, before you call it.........

Scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #4 on: May 02, 2015, 09:22:34 PM »
thats the bit I dont now how to do

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #5 on: May 02, 2015, 09:24:05 PM »
at a guess

function GetRegister(TS_XPos)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s",TS_XPos ))
return mc.mcRegGetValueString(hreg)
end
Re: need some lua help
« Reply #6 on: May 02, 2015, 10:09:07 PM »
I don't know if you can define them through statements but you can define them by opening up Regfile and adding them.  That's how I'm doing it.

Peter

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #7 on: May 02, 2015, 11:59:54 PM »
not quite sure how to do that ever

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #8 on: May 03, 2015, 01:36:41 AM »
I tried adding them to regfile it did not work

I think I have to do what`s at the bottom of page 16 top of 17 in the scripting manual

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: need some lua help
« Reply #9 on: May 03, 2015, 08:58:06 AM »
you have to pass: TS_XPos, as a string: "TS_XPos"

Scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/