ljean / modbus-tk

Create Modbus app easily with Python
Other
568 stars 213 forks source link

enh: RTU master can be easily made more efficient (less CPU load) #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As described in 
http://stackoverflow.com/questions/17081442/python-modbus-library/21459211#21459
211 the RTU master implementation could read the whole serial buffer instead of 
reading by one byte. 

suggested modification:
modbus_rtu.py -> class RtuMaster(Master) -> _recv method:

instead: read_bytes = self._serial.read(1)
could use: read_bytes = self._serial.read(expected_length)
or could use: read_bytes = self._serial.read(expected_length) just for the 
first pass and then try to read by single byte (to handle case when slave sends 
more bytes than it should). 

Hanging on read should not be a problem as timeout is used. 

Currently for bigger payload CPU load increases drastically and profiling shows 
the problem is not in modbus-tk module but in the serial port access by 
pywin32. Reducing the number of reads helps a lot making modbus-tk the best 
module to implement RTU modbus master over a serial line I know of.  

Original issue reported on code.google.com by z.zasiec...@gmail.com on 6 Mar 2014 at 10:02

GoogleCodeExporter commented 9 years ago
Please change to enhancement. I'm not used to code.google.com and didn't see 
where to set the proper issue type. 

Original comment by z.zasiec...@gmail.com on 6 Mar 2014 at 10:04

GoogleCodeExporter commented 9 years ago
Marked as enhancement

Original comment by luc.jean@gmail.com on 6 Mar 2014 at 2:52

GoogleCodeExporter commented 9 years ago
Excuse me, is there anything can be done to reduce CPU load?

Original comment by azat...@gmail.com on 9 Aug 2014 at 1:02