Modbus RTU master READ_HOLDING_REGISTERS processed slow #13095
Replies: 1 comment 1 reply
-
I haven't worked with this lib yet, but if You read holding registers always in that same manner, then no need every time (in write function ) to extract params of register definitions to local variable and then to self.host.read_holding_registers. Also if possible you can construct whole PDU frame ( see https://www.simplymodbus.ca/FC03.htm) as 'const' and directly send to slave (no need to build frame by master every time.) , but it will not speed up probably too much. Edit: check if master has some delay set waiting time between two consecutive frames ( but usually it is 3.5 signs ( usually not less than 1.5 - 2 ms), to if you can check timing of frames construct on master side, and then on slave ( slave usually have about 30-50 ms to response) so maybe your 30-40 ms is just caused by slave (as default) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone, I had used the code [https://github.com/brainelectronics/micropython-modbus/tree/develop/umodbus] Modbus RTU READ HOLDING REGISTERS function in PYBV11 with micropython version is V1.22 . It is elapsed time about : 30~40ms, how to speed up the data process time, thanks !
Follow as the master code:
`# modbus master driver for lidar
6 pieces lidar for system, address from 1 to 6
from right to left side, count round closewize
system package
from machine import Pin
import logging
import gc
from InitConfig import config
import uasyncio as asyncio
import time
log = logging.MiniLog("RtuMaster", level = logging.DEBUG)
DEBUG = config.get('DEBUG', False)
MasterUartId = config.get("UART_LIDAR")
self defined package
from umodbus.serial import Serial
gc.collect()
version = '1.0'
author = 'skylin'
def timed_function(f, *args, **kwargs):
myname = str(f).split(' ')[1]
def new_func(*args, **kwargs):
t = time.ticks_us()
result = f(*args, **kwargs)
delta = time.ticks_diff(time.ticks_us(), t)
print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000))
return result
return new_func
register_definitions = {
"HREGS":{ # read hold registers
"slave_address":{
"index1": 1,
"index2": 2,
"index3": 3,
"index4": 4,
"index5": 5,
"index6": 6
},
"register_address": 0x01,
"length": 0x02,
},
}
class Frame(object):
def init(self,data = None):
""" Data struct: """
if data is None:
self.data = bytearray()
else:
self.data = bytearray(data)
class FrameBuffer(object):
def init(self, size):
"""
A FrameBuffer is used to buffer frames received from the Network
over the active Bus.The FrameBuffer is designed as a FIFO and is
useful to overcome the limited storing capability
"""
self._size = size
self._data = [[memoryview(bytearray(4))] for _ in range(size)]
self._index_write = 0
self._index_read = 0
self._null_sink = [0, 0, 0, 0]
self._count = 0
class Master(object):
def init(self, uart_id = MasterUartId, baudrate = 115200, ctrlpin ='485_TR1', fbSize = 128):
if name == 'main':
`
Beta Was this translation helpful? Give feedback.
All reactions