Hello Guest it is March 29, 2024, 04:32:53 AM

Author Topic: More modbus "functions" or fewer (with multiple regs per)  (Read 1205 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 »
Hi,
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.

http://www.homanndesigns.com/pdfs/Using_Modbus_with_Mach3.pdf

Cheers,

Peter
----------------------------------------------------
Homann Designs
http://www.homanndesigns.com
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
---------------------------------------------------------
RPM=mc.mcCntlGetPoundVar(inst,2132);
mc.mcSpindleSetOverrideEnable(inst,1);
local OVRenable=mc.mcSpindleGetOverrideEnable(inst);
if OVRenable then;
    local OVR=mc.mcSpindleGetOverride(inst);
    RPM=RPM*OVR;
end;
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");
mc.mcRegSetValue(hfreq,freq);
scr.SetProperty('dro(128)','Value',tostring(RPM));

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