The idea of using python to control a modbus vfd spindle drive through the M3, M5 macros calling python modbus script works well.
The vfd is a leeson speedmaster micro model.
The interface is a usb serial cable on com5 with a $9 rs485 converter from amazon
Python was installed. The 32 bit version. 64 had issues.
PySerial library was installed.
The python library Minimalmodbus was installed. This library has good documentation and any explanation on modbus from python should be read there.
A python script called spindleCW.py turns on the spindle.
A python script called spindleOff.py turns off the spindle.
M3 is modified.
M5 is modified.
SpindleCW.py
#!/usr/bin/env python
import minimalmodbus
instrument = minimalmodbus.Instrument('com5', 1) # port name, slave address
instrument.serial.baudrate = 9600
instrument.serial.bytesize = 8
instrument.serial.stopbits = 2
instrument.serial.timeout = 0.2 # seconds
instrument.write_register(1,8,0) # Registernumber, value, number of decimals
SpindleOff.py
#!/usr/bin/env python
import minimalmodbus
instrument = minimalmodbus.Instrument('com5', 1) # port name, slave address
instrument.serial.baudrate = 9600
instrument.serial.bytesize = 8
instrument.serial.stopbits = 2
instrument.serial.timeout = 0.2 # seconds
instrument.write_register(1,4,0) # Registernumber, value, number of decimals
M3
dim x
x = shell("c:\python27\python.exe c:\python27\spindleCW.py",6)
sleep(2000)
M5
dim x
x = shell("c:\python27\python.exe c:\python27\spindleOff.py",6)
It appears passing the S value for spindle speed to a python script as an argument will work too. But that is not yet tried.