Hello Guest it is September 26, 2023, 02:23:04 AM

Author Topic: More modbus "functions" or fewer (with multiple regs per)  (Read 499 times)

0 Members and 1 Guest are viewing this topic.

More modbus "functions" or fewer (with multiple regs per)
« on: February 22, 2023, 01:16:30 PM »
Hi everyone,

I've got my modbus TCP working finally and I'm in the process of making a small tab with VFD readbacks (temp, current, voltage, etc).

I currently have 14 functions, all read except for one for spindle speed (run control is by terminals for safety and convenience).  Things are a bit slower than I would like (polling interval 250ms, wait 100)

I have 3 of my 14 functions timing out, (oddly, they are in the middle of the list).  Is it more efficient time-wise to group some of the functions together where possible and have one function read multiple registers? (some of the regs are next to each other).  I've attached the list for reference

Or is it really just the same timing no matter what?

I thought I read somewhere that mach goes down in the sequence, waiting the timeout time for each transfer.  If this is the case, fewer transfers would be better.  In practice, it may not make a difference. 
Re: More modbus "functions" or fewer (with multiple regs per)
« Reply #1 on: February 22, 2023, 04:37:20 PM »
Yes it is much more efficient to read multiple registers a one time as there is quite an overhead in reading the registers one by one.

I wrote an article on using Modbus with Mach3. The concepts in it are also applicable for Mach4.



Homann Designs
email: peter at homanndesigns.com
Re: More modbus "functions" or fewer (with multiple regs per)
« Reply #2 on: February 22, 2023, 06:04:50 PM »
I've got it mostly working now, there is one strange issue though.  The Setpoint value for the Spindle frequency keeps rapidly switching between my setpoint and 0.   

If I watch the frequency output register: "modbus0/freq" it appears to track.  It is almost as if there are two sources controlling the register: one that sets it to 0 and the PLC script setting it to the setpoint.

I have it setup like the folks did it over on this thread:  https://www.machsupport.com/forum/index.php?topic=34023.50

Code: [Select]
--          set Target RPM DRO
local OVRenable=mc.mcSpindleGetOverrideEnable(inst);
if OVRenable then;
    local OVR=mc.mcSpindleGetOverride(inst);
local range=mc.mcSpindleGetCurrentRange(inst)
if RPM>mc.mcSpindleGetMaxRPM(inst,range) then RPM=mc.mcSpindleGetMaxRPM(inst,range) end;
if RPM<mc.mcSpindleGetMinRPM(inst,range) then RPM=mc.mcSpindleGetMinRPM(inst,range) end;
local freq=RPM/6;
local hfreq=mc.mcRegGetHandle(inst,"modbus0/freq");

I've still got to reorganize the "functions" to get rid of the overhead.