Hello Guest it is April 26, 2024, 05:15:26 PM

Author Topic: LUA set modbus register  (Read 748 times)

0 Members and 1 Guest are viewing this topic.

LUA set modbus register
« on: November 07, 2021, 10:16:18 AM »
Hi Guys, this is a follow on and a broader question to scripting gurus....

I have a modbus connection, and i am trying to update the register from the cmd rpm but i am having no luck.  Joeaverage has been helping me but i am still not successful, would much appreciate dazthegaz or anyone else taking a look at this for me please?
The spindle specs
12000rpm
register values 100% = 10000 etc

Code: [Select]
local registerHandle=mc.mcRegGetHandle(mInst,"modbus0/wrtvfdspeed")
local commandedSpeed=mc.mcSpindleGetCommandRPM(mInst)
local registerValue=(commandedSpeed/12000)*10000
mc.mcRegSetValue(registerHandle,registerValue)   

this does not seem to be writing the register as expected, any help appreciated!
Re: LUA set modbus register
« Reply #1 on: January 08, 2022, 03:02:23 AM »
There is a difference between read and write registers in the Modbus plugin. You can only use the LUA api to write the registers that are defined as write registers in the Modbus plugin configuration. If you can get your hands on an cheap Arduino UNO and ethernet shield, I wrote a document on how to use Mach4 TCP Modbus with code examples and detailed instructions for Mach4. It just got buried in the forums https://www.machsupport.com/forum/index.php?topic=44512.0.

If you already have the modbus hardware setup then just use the examples to read and write registers in the document in that link without the arduino.

Offline Tweakie.CNC

*
  • *
  •  9,200 9,200
  • Super Kitty
    • View Profile
Re: LUA set modbus register
« Reply #2 on: January 08, 2022, 04:45:42 AM »
To prevent compewter_numerical's excellent .pdf document getting buried again in the future I have now included it in Members Documents here:  https://www.machsupport.com/forum/index.php?topic=45688.msg290244#msg290244

Tweakie.
PEACE