Hello Guest it is April 26, 2024, 09:02:34 AM

Author Topic: Using old style modbus to write a value to a device.  (Read 16801 times)

0 Members and 1 Guest are viewing this topic.

Using old style modbus to write a value to a device.
« on: November 03, 2013, 03:26:41 PM »
I am trying to turn on a vfd. I can do so by writing a value of 8 to register 1 on my device, a leeson speedmaster. I can do this from the modbus test dialog in mach3. But I cannot do it from inside the m3 macro with a command like SetModOutput(1,8).
In some of the modbus documents for mach3 it is said that direct control of modbus is possible and even some read functions are mentioned but not write. The dozens of comments I've read steer towards polling and brains. Is their no direct write available?  I don't want to write to a register 20x per second. Could this be deleterious for some devices with EEPROM that might have lives of only tens of thousands of writes? There are other registers I might to want to write and I notice that they are non-volatile so I assume EEPROM on this old device.  
  I am so frustrated, the next step will be to try to use the script to  shell start a python script that writes the register.
Re: Using old style modbus to write a value to a device.
« Reply #1 on: November 03, 2013, 09:53:50 PM »
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.
« Last Edit: November 03, 2013, 09:58:52 PM by Billk »