381
Mach4 General Discussion / Re: MACH4 - Modbus
« on: May 14, 2014, 11:35:25 AM »
I just focused on the functions and made sure it found my register values, pulled, computed and passed back the right value.
all done under a button I created to test.
I'm just adding the first and the second and putting the new value back in the first, basically an additive loop.
just to prove out how to do a modbus scripting feature.
now to figure out how to use the data and make bit wise decision.
found they did not really make a difference in my setup, so did not address them.
but going back, now that you reminded me of it, could be very useful.
if you change them to the correct modbus0 name, as you step thru the function you can see them pass the values
local hRhr1 = mc.mcRegGetHandle(inst, "modbus0/Rhr1");
local valRhr1 = mc.mcRegGetValue(hRhr1);
local hRhr2 = mc.mcRegGetHandle(inst, "modbus0/Rhr2");
local valRhr2 = mc.mcRegGetValue(hRhr2);
local hRhr3 = mc.mcRegGetHandle(inst, "modbus0/Rhr3");
mc.mcRegSetValue(hRhr3, valRhr1 + valRhr2);
far as a m40
you would have to put the script in a m40.mcs file
then call it as a mcode
remember that you have to restart Mach4 to compile the new m40.mcs file
everytime you edit it.
all done under a button I created to test.
I'm just adding the first and the second and putting the new value back in the first, basically an additive loop.
just to prove out how to do a modbus scripting feature.
now to figure out how to use the data and make bit wise decision.
found they did not really make a difference in my setup, so did not address them.
but going back, now that you reminded me of it, could be very useful.
if you change them to the correct modbus0 name, as you step thru the function you can see them pass the values
local hRhr1 = mc.mcRegGetHandle(inst, "modbus0/Rhr1");
local valRhr1 = mc.mcRegGetValue(hRhr1);
local hRhr2 = mc.mcRegGetHandle(inst, "modbus0/Rhr2");
local valRhr2 = mc.mcRegGetValue(hRhr2);
local hRhr3 = mc.mcRegGetHandle(inst, "modbus0/Rhr3");
mc.mcRegSetValue(hRhr3, valRhr1 + valRhr2);
far as a m40
you would have to put the script in a m40.mcs file
then call it as a mcode
remember that you have to restart Mach4 to compile the new m40.mcs file
everytime you edit it.