Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: cd_edwards on June 28, 2018, 03:07:19 PM
-
does the following even work? I added the rc variables to find out where the problem was. mc.mcRegGetHandle returns a -27 which causes mc.mcRegSetValueString to return -27.
#define MERROR_REG_NOT_FOUND -27
function Master.LoadRegister(ini, name)
local val, rc = mc.mcProfileGetString(inst , tostring(ini), name, "0.000")
local hreg, rc = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", name))
rc = mc.mcRegSetValueString(hreg, val)
return tonumber(val)
end
I've been trying to gain access to the scr.* properties. in particular some DRO's I've created for use in the m6() macro.
I added the following to my m6 startup.
if (package.loaded.scr == nil) then
scr = require "screenipc"
scr.scIpcInit("127.0.0.1")
end
scr.GetProperty("droSafeZ", "Value") always returns "" even though I've set it earlier to a value of 0.75 using scr.SetProperty("droSafeZ", "Value", tostring(num))
I have two functions.. I've modified mcMasterModule.lua's LoadRegister function so it returns the numeric value of the register.
function LoadAll()
{
SafeZ = mcp.LoadRegister(N_, "SafeZ", "0.00")
scr.SetProperty("droSafeZ", "Value", tostring(SafeZ))
}
function SaveAll()
{
val = scr.GetProperty("droSafeZ", "Value")
mcp.SaveRegister(N_, "SafeZ", val)
}
if (mc.mcInEditor() == 1) then
LoadAll2016()
SaveAll2016()
end
-
btw Master.LoadRegister is part of the mcMasterModule.lua file which is supposed to be an example.
-
I'm not the expert on Lua or Mach4 so take this for what you paid for it.
Not sure about the new versions (using 3741) but the scr variable was not available to macros. You had to set a register with a value and then retrieve the register value. I seem to recall a post about it being available in the newer versions though. While you can load a variable 'scr' from a macro I don't believe you get connected to Mach4's scr.
SafeZ = mcp.LoadRegister(N_, "SafeZ", "0.00")
I assume N_ was set somewhere from N_=mc.mcGetInstance()
assume typo mcp
mc.mcLoadRegister name is of the form 'iRegs0/SafeZ' or 'gRegs0/SafeZ' depending on where you defined the register.
I think should be SafeZ = mc.mcLoadRegister(N_, "gRegs0/SafeZ", "0.00")
HTH
RT
-
found my old thread where smurph says it is a vailable but doesn't say what versions
https://www.machsupport.com/forum/index.php/topic,36554.0.html
-
mcp is a local version of the mcMasterModule which I load as a require.
N_ is a "section name" which is loaded from the ini file. and of course "SafeZ" is the key and 0.00 is the default.
What this is supposed todo is read a value from the ini file and then set a register with that value in the iRegs0 section
the iRegs0 is in the LoadRegister function from mcMasterModule.lua which is included with Mach4.
My issue's are that scr.GetProperty() doesn't appear to work from a macro even when I have the required module loaded via a require.
and that mc.mGetRegister() doesn't work as per the example file. Now this problem I had a answer for before and forgot about it when I asked this question before.
Registers can only be created from a plugin. It would be much handier if we could mc.mcSetRegister() and create registers from a plugin. But then I guess that's why they
have the pound variables. So basically if I want this to work, I need to create a plugin which creates the appropriate registers and then work from there..
this is in my m6() macro.
local ToolChangePosX = mcp.GetRegister("ToolChangePosX", 1)
--scr.GetProperty("droToolChangePosX", "Value"))
Since scr.GetProperty() doesn't work, I changed to a Register which doesn't work either. it looks like I will need to use a ini value and work from there.
-
you don't need to create a mcp variable as mc is defined and available at load to macros as well as buttons etc. If you were to add the line wx.wxMessageBox(tostring(mc)) at the beginning of your m6 macro you will see that it is defined as a table, the one created at Mach4 load. I don't think the mcp table that is returned links to your running version of Mach4 but rather creates another lua chunk.
You can access the the register values by requesting a handle to it an then requesting the value using the mc variable and the core API's:
hReg, rc = mc.mcRegGetHandle(mInst, 'gRegs0/SafeZ')
mVal, rc = mcRegGetValue(hReg)
Assuming you have created a gReg0 value named SafeZ through Configure->Plugins->Regfile
I can't help with with the scr problem since I get the same result as you do with the version I listed. maybe there is a development version that allows direct access to the scr variable loaded at screenload. My workaround shown in the link I provided does work but it would be better if someone (SMURPH) would respond on this one.
HTH
RT
-
if(package.loaded.Master == nil) then
mcp = require "mcMasterModule"
end
mcp.* is how you access the functions within that module.
-
If my understanding of what I'm looking at is correct, we are looking at a "class" of functions which are then accessed through a pointer "mcp"
-
Your understanding is correct, but, try this:
wx.wxMessageBox(tostring(mcp)..' - '..tostring(mc))
Are the tables returned the same address? If not then mcp cannot access the values in Mach4.
-
they are differant but I expected that. mc.* are internal mach4 functions. mcp.* are a lua script with functions.
-
Your SafeZ value is saved in the machine.ini file in your profile's directory. If your search the file and don't find it then it has never been created. You can also check by going to Configure->Plugins->Regfile and see it there, where you created it, or, 'Diagnostic->RegFile' and see it's current value if it exists.
Sorry, that's all got.
-
I just confirmed that scr.GetProperty is not working at all.
scr.SetProperty("droToolChangePosZ", "Value", "1")
val = scr.GetProperty("droToolChangePosZ", "Value")
always returns "". they are in the same function as a test. DRO value on screen changes as it should. retrieving it, fails.
-
Try checing the return code of the scr API call.
val, rc = scr.GetProperty("droToolChangePosZ", "Value")
What is the value of rc? It will be one of:
SERROR_NOERROR 0
SERROR_API_INIT -1
SERROR_CONTROL_NOT_FOUND -2
SERROR_PROPERTY_NOT_FOUND -3
SERROR_PAGE_NOT_FOUND -4
SERROR_INVALID_PARAM -5
SERROR_FUNCTION_NOT_FOUND -6
SERROR_IPC_NOT_READY -99
Steve