1
Mach4 General Discussion / Modbus Spindle PLC script
« on: December 04, 2023, 01:05:42 AM »
I'm a long time Mach3 user and I'm finally trying to see if I should upgrade to Mach4. I have it mostly working except for the controlling spindle speed via VFD. I have read through lots of forum posts and the lua guide but still can't get it to work. I used the instructions from user "giddyup" for my Automation Direct GS2 VFD located here: https://www.machsupport.com/forum/index.php?topic=34023.60 and it mostly works.
I do know that my modbus registers are working because I can turn the spindle on and off using M3, M4, and M5. I also know that I can send the speed to the VFD because I see the modbus register update using the diagnostics window when using the script below. Below is the PLC script that works to set a single spindle speed of 60Hz. How can I pull the spindle RPM from the spindle DRO or the mach4 system variable mc.MC_SPINDLE_RPM and put into my freq variable below?:
freq = 60x10
hfreq = mc.mcRegGetHandle(inst,"modbus0/speed0")
mc.mcRegSetValue(hfreq,freq)
Below are things I have tried to get the current set spindle speed:
freq = mc.MC_SPINDLE_RPM
freq = scr.GetProperty("Spindle RPM", "Value")
freq = mc.mcCntlGetPoundVar(inst,2132)
Also, one thing I have noticed is that using mc.mcCntlGetPoundVar(inst,2132) seems to write a 0 into my modbus speed0 register because it overwrites manually inputted values. It seems like maybe the default spindle speed it is reading is 0 rather than the value displayed in the DRO.
I do know that my modbus registers are working because I can turn the spindle on and off using M3, M4, and M5. I also know that I can send the speed to the VFD because I see the modbus register update using the diagnostics window when using the script below. Below is the PLC script that works to set a single spindle speed of 60Hz. How can I pull the spindle RPM from the spindle DRO or the mach4 system variable mc.MC_SPINDLE_RPM and put into my freq variable below?:
freq = 60x10
hfreq = mc.mcRegGetHandle(inst,"modbus0/speed0")
mc.mcRegSetValue(hfreq,freq)
Below are things I have tried to get the current set spindle speed:
freq = mc.MC_SPINDLE_RPM
freq = scr.GetProperty("Spindle RPM", "Value")
freq = mc.mcCntlGetPoundVar(inst,2132)
Also, one thing I have noticed is that using mc.mcCntlGetPoundVar(inst,2132) seems to write a 0 into my modbus speed0 register because it overwrites manually inputted values. It seems like maybe the default spindle speed it is reading is 0 rather than the value displayed in the DRO.