Graig,
The correct way to do the register read is with two API calls.
local hRhr1 = mc.mcRegGetHandle(inst, "modbud0/Rhr1");
local valRhr1 = mc.mcRegGetValue(hRhr1);
local hRhr2 = mc.mcRegGetHandle(inst, "modbud0/Rhr2");
local valRhr2 = mc.mcRegGetValue(hRhr2);
local hRhr3 = mc.mcRegGetHandle(inst, "modbud0/Rhr3");
mc.mcRegSetValue(hRhr3, valRhr1 + valRhr2);
A response to your post said this was working, but I don't see how. Note the spelling is modbu
D which looks like a typo.
An enterprising LUA programmer can shorten the 2 API calls . . .
But put something like them in the Screen load script and you can access them from any screen/object script.
What is the file name of the 'Screen load script' ? The file that scrolls when you select 'LUA sciprt' from the Operator dropdown looks like the right file, but it is compiled and cannot be edited. I tried some tricks, but nothing worked.
local valRhr1 = ReadReg("modbud0/Rhr1");
local valRhr2 = ReadReg("modbud0/Rhr2");
WriteReg("modbud0/Rhr3" valRhr1 + valRhr2);
Is this just a 'cut and paste' typo, or should "modbud" be used?
Being unable to figure out how to add functions to the 'Screen load script', I tried making a macro. The macro runs in the debugger, but almost never from the MDI and never from within G-code.
Even more strange is that it does run on every MACH4 startup. I'm sure I have done something wrong, but I have tried a lot of stuff and no joy. Need a little help here. File name is m40. First and last line commented out because it won't run at all that way. Message boxes are for diagnostic purposes. It runs from the debugger and executes properly, reading and writing the regs as expected.
--function m40()
local inst
local hRhr1;
local valRhr1;
local hRhr2;
local valRhr2;
local hRhr3;
local valString;
wx.wxMessageBox("Start");
inst=mc.mcGetInstance();
hRhr1 = mc.mcRegGetHandle(inst, "modbus0/Hreg1");
valString = tostring(hRhr1);
wx.wxMessageBox(valString);
valRhr1 = mc.mcRegGetValue(hRhr1);
valString = tostring(valRhr1);
wx.wxMessageBox(valString);
hRhr2 = mc.mcRegGetHandle(inst, "modbus0/Hreg2");
valRhr2 = mc.mcRegGetValue(hRhr2);
valString = tostring(valRhr2);
wx.wxMessageBox(valString);
hRhr3 = mc.mcRegGetHandle(inst, "modbus0/Wreg3");
valString = tostring(valRhr2 + valRhr1);
wx.wxMessageBox(valString);
mc.mcRegSetValue(hRhr3, valRhr1 + valRhr2);
wx.wxMessageBox("Done");
--end