Hello Guest it is March 28, 2024, 06:26:04 AM

Author Topic: Initiating values from "ini file"  (Read 645 times)

0 Members and 1 Guest are viewing this topic.

Initiating values from "ini file"
« 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)

« Last Edit: March 30, 2022, 04:48:57 AM by Fermate »

Offline Bill_O

*
  •  562 562
    • View Profile
Re: Initiating values from "ini file"
« Reply #1 on: March 30, 2022, 08:40:25 AM »
I use registers for many things.
They are always available to all parts of Mach4.

Bill

Offline jbuehn

*
  •  101 101
    • View Profile
Re: Initiating values from "ini file"
« Reply #2 on: March 30, 2022, 11:53:16 AM »
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.

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Initiating values from "ini file"
« Reply #3 on: March 31, 2022, 07:43:48 PM »
... 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
Re: Initiating values from "ini file"
« Reply #4 on: April 06, 2022, 04:24:50 AM »
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