Hello Guest it is April 27, 2024, 03:48:26 PM

Author Topic: Modbus Spindle PLC script  (Read 465 times)

0 Members and 1 Guest are viewing this topic.

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.
« Last Edit: December 04, 2023, 01:14:48 AM by lenitech »
Re: Modbus Spindle PLC script
« Reply #1 on: December 04, 2023, 01:27:16 AM »
I have now tried this as well but it doesn't work either:

freq = mc.mcCntlGetPoundVar(inst, mc.MC_SPINDLE_RPM)
Re: Modbus Spindle PLC script
« Reply #2 on: December 04, 2023, 03:35:28 AM »
This worked!

freq=mc.mcCntlGetPoundVar(inst,mc.SV_CUR_SPINDLE_SPEED)