Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Fermate on March 30, 2022, 04:35:20 AM
-
I have two DRO's that keeps the value of the displacement of my laser-cross from the spindle tip.
I save these using mcProfileWriteString and read them back using mcProfileGetString and this works fine (when the code is behind buttons).
But I would like to read them automatically each time I start Mach4, so I put this code at the end of the Screen Load Script:
function GetLaserDisp()
local inst = mc.mcGetInstance()
local xVal = mc.mcProfileGetString(inst,"MyUserSettings","LaserDispX","-48.7");
local yVal = mc.mcProfileGetString(inst,"MyUserSettings","LaserDispY","163.9");
scr.SetProperty("droLaserDispX", "Value",tostring(xVal));
scr.SetProperty("droLaserDispY", "Value",tostring(yVal));
mc.mcCntlSetLastError(inst, "GET Laser Point Displacement from file");
end
GetLaserDisp()
The message is displayed but the DRO's are not getting any value?
What am I doing wrong?
(I am a experienced programmer but not that experienced with Mach4 and LUA)
-
I use registers for many things.
They are always available to all parts of Mach4.
Bill
-
That's a good idea from Bill about using persistent registers for the DROs.
You could also try putting your function call in the PLC script instead of the screen load script. In the PLC script, towards the bottom, there's a conditional that only runs in the first loop...try it in there. Sometimes not all the screen elements have been loaded when the screen load script is called.
-
... so I put this code at the end of the Screen Load Script:
The screen load script is run when the screen is first loaded. Meaning the screen hasn't yet loaded. So you will never be able to do it this way.
You could probably use the PLC script and scr.IsLoaded() in combination with a flag to only allow the code to run once.
But the better way, as others have mentioned, is to use the register plugin to create a persistent register. Then point a DRO (Register Property) to that register in the screen editor.
Steve
-
The screen load script is run when the screen is first loaded. Meaning the screen hasn't yet loaded.
Aha That explains a lot (both for this question and for later use of the "Screen Load Script")
Thanks a lot!
I will check out the PLC and the persistent registers