Hello Guest it is April 18, 2024, 07:02:17 AM

Author Topic: Save in register from lua  (Read 888 times)

0 Members and 1 Guest are viewing this topic.

Save in register from lua
« on: February 18, 2022, 06:54:36 PM »
Hi again,
             all i want to do is to save a box that contain an offset for my laser. I create a register LaserDroOffsetX from within the reg plugin. For testing pupose i create a button that trigger this function:
Code: [Select]
function LaserDroOffset()
local LaserXOffset = scr.GetProperty("LaserdroOffsetX", "Value");
inst = mc.mcGetInstance()
mc.mcProfileWriteString(inst, "iReg0", "LaserDroOffsetX", LaserXOffset);
end
But when i look in the plugin diagnostic, the value stay to zero
Thanks
Re: Save in register from lua
« Reply #1 on: February 18, 2022, 09:00:41 PM »
Got it need to close mach4 to reccord the data
Re: Save in register from lua
« Reply #2 on: February 19, 2022, 05:31:17 AM »
you can create a 'real-time' register using the Configure->Plugins->RegFile and access it via:

theRegister = mc.mcRegGetHandle(inst, "gRegs0/whateverTheNameIs")
theRegisterValue = mc.mcRegGetValue(theRegister)

then you can save it in machine.ini with how you did it
« Last Edit: February 19, 2022, 05:33:19 AM by compewter_numerical »
Re: Save in register from lua
« Reply #3 on: February 19, 2022, 09:46:00 AM »
Thanks, it work live now, by any chance, do you have an idea how to trigger this function after the value of the box have benn change.
Thanks afain
Re: Save in register from lua
« Reply #4 on: February 19, 2022, 10:06:51 AM »
What you're trying to do doesn't need any lua scripting.

1. Create your register via Configure>Plugins>Regfile. If you want to it be persistent i.e. save the value after you shutdown Mach4 then tick the 'Persistent' column
2. In the screen editor select your DRO and then in the properties on the left hand side there is a 'Register' property. In the dropdown list you will find your register you just created either iReg0/... or gRegs0/...
3. Exit the screen editor.

When you now enter a value in the DRO it will update the register automatically. You can see the register value by going to Diagnostics>Regfile and then selecting the + next to iRegs0 or gRegs0 depending on where you made your register.


If you need to now read the register value from inside an mcode or button script you can follow what compewter_numerical posted above
Re: Save in register from lua
« Reply #5 on: February 19, 2022, 01:54:04 PM »
Thanks,
            everything is working now.