From 83886247216b439af43160841ae69221d146cf49 Mon Sep 17 00:00:00 2001 From: Thomas Neele Date: Mon, 22 Jul 2019 21:33:15 +0200 Subject: [PATCH] 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():