Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: TommyG on January 30, 2022, 10:55:49 AM
-
Hi folks
I'm new to Mach4 programming although I've a reasonable bit of experience with both Mach4 and programming individually :-)
I'm trying to configure Mach4 to control a VFD via MODBUS. I've the MODBUS bit up and working and can control the spindle via the "Diagnostic - Newfangled Solutions - MODBUS" screen but I'm having trouble wiring the relevant control signals to the MODBUS registers.
I can do this with a PMC script but a more elegant method would seem to be to use a signal script. However, went I try to set the register value I get an error "attempt to call a nil value (field 'RegSetValue')" I've added some debugging messages and I can see that the 'hreg' variable is getting a value.
The code below has been added to my screen load script in the 'SigLib' section. I'm just using test registers for debugging.
[mc.OSIG_SPINDLEFWD] = function (state)
if (state == 1) then
local hreg = mc.mcRegGetHandle(inst, "iRegs0/test/spindleCtrl")
mc.RegSetValue(hreg, 1)
else
mc.mcCntlSetLastError(inst, "INFO: OSIG_SPINDLEFWD != 1")
local hreg = mc.mcRegGetHandle(inst, "iRegs0/test/spindleCtrl")
mc.mcCntlSetLastError(inst, "INFO: hreg value was " .. tostring(hreg))
mc.RegSetValue(hreg, 0)
end
end,
I get the error when I click on 'Enable' in Mach4, I'd assume part of the enable process is to set the motor off so that makes sense.
Any help would be greatly appreciated.
Tommy
-
Never mind folks, the classic case of 'read the manual one more time after posting a forum message'
The command is, of course, 'mc.mcRegSetValue(hreg, 0)' rather than 'mc.RegSetValue(hreg, 0)'
Doh!