From 83886247216b439af43160841ae69221d146cf49 Mon Sep 17 00:00:00 2001 From: Thomas Neele Date: Mon, 22 Jul 2019 21:33:15 +0200 Subject: [PATCH 1/2] Read more data from serial port at once A telegram can contain dozens of lines. Reading them one by one is somewhat inefficient. With this change, the client tries to read all data that is available. This significantly reduced CPU load for me. --- dsmr_parser/clients/serial_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsmr_parser/clients/serial_.py b/dsmr_parser/clients/serial_.py index 1d7be89..9939194 100644 --- a/dsmr_parser/clients/serial_.py +++ b/dsmr_parser/clients/serial_.py @@ -30,7 +30,7 @@ class SerialReader(object): """ with serial.Serial(**self.serial_settings) as serial_handle: while True: - data = serial_handle.readline() + data = serial_handle.read(max(1, min(1024, serial_handle.in_waiting))) self.telegram_buffer.append(data.decode('ascii')) for telegram in self.telegram_buffer.get_all(): From b31bcd61fc918fe5b5bc3c0e1cff78fa6947ab3a Mon Sep 17 00:00:00 2001 From: Nigel Dokter Date: Tue, 8 Oct 2019 22:13:58 +0200 Subject: [PATCH 2/2] Updated version number --- CHANGELOG.rst | 4 ++++ setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f7d822c..5fac8e7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ Change Log ---------- +**0.14** (2019-10-08) + +- Changed serial reading to reduce CPU usage (`pull request #37 `_). + **0.13** (2019-03-04) - Fix DSMR v5.0 serial settings which were not used (`pull request #33 `_). diff --git a/setup.py b/setup.py index e375858..b20a2a8 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( author='Nigel Dokter', author_email='nigel@nldr.net', url='https://github.com/ndokter/dsmr_parser', - version='0.13', + version='0.14', packages=find_packages(), install_requires=[ 'pyserial>=3,<4',