Write modbus register only when I need

Post anything you want to discuss with others about the software.

Write modbus register only when I need

Postby Doncis » Fri Nov 01, 2024 9:51 am

I have bunch of registers, eg. Vfd vf parameters for heat control and energy saving ( low torq high speed engraving, high power milling), SVC on off, servo drive gains, IO expanders and etc. How do i set registers one time only when i need it? For now all registers are constantly writing in loop, even if value is the same, and no need to constantly writing on top.
Doncis
 
Posts: 43
Joined: Thu Jul 15, 2021 11:51 am

Re: Write modbus register only when I need

Postby densa » Thu Nov 14, 2024 2:03 am

Keep a local cache (in memory) of the current values of each register.
Before writing to the register, compare the current value you want to write with the cached value.
If the value has changed, write the new value to the register and update the local cache.
If the value is the same, skip the write operation.
Code: Select all
# Dictionary to hold the last known values of the registers
local_cache = {}

def update_register(register, new_value):
    # Check if the register value has changed
    if register not in local_cache or local_cache[register] != new_value:
        # Update the hardware register if the value has changed
        write_to_hardware_register(register, new_value)
        # Update the local cache with the new value
        local_cache[register] = new_value
snow rider 3d project for Christmas!
densa
 
Posts: 1
Joined: Thu Nov 14, 2024 2:01 am


Return to General discussion about the UCCNC software

Who is online

Users browsing this forum: Bing [Bot] and 35 guests