From 3e951c092c4f2debeef2d7a298804b2b287daa8e Mon Sep 17 00:00:00 2001 From: samson0v Date: Mon, 30 Oct 2023 15:40:53 +0200 Subject: [PATCH] Fixed Modbus Slaves stopping --- thingsboard_gateway/connectors/modbus/modbus_connector.py | 5 +++++ thingsboard_gateway/connectors/modbus/slave.py | 6 +++++- thingsboard_gateway/gateway/tb_gateway_service.py | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/thingsboard_gateway/connectors/modbus/modbus_connector.py b/thingsboard_gateway/connectors/modbus/modbus_connector.py index 0296fbe63..46c9a3b81 100644 --- a/thingsboard_gateway/connectors/modbus/modbus_connector.py +++ b/thingsboard_gateway/connectors/modbus/modbus_connector.py @@ -302,6 +302,11 @@ def _save_data(self, data): def close(self): self.__stopped = True self.__stop_connections_to_masters() + + # Stop all slaves + for slave in self.__slaves: + slave.close() + if reactor.running: ServerStop() self.__log.info('%s has been stopped.', self.get_name()) diff --git a/thingsboard_gateway/connectors/modbus/slave.py b/thingsboard_gateway/connectors/modbus/slave.py index f9e7533ad..d423e82b8 100644 --- a/thingsboard_gateway/connectors/modbus/slave.py +++ b/thingsboard_gateway/connectors/modbus/slave.py @@ -71,6 +71,7 @@ def __init__(self, **kwargs): self.last_polled_time = None self.daemon = True + self.stop = False self.start() @@ -78,7 +79,7 @@ def timer(self): self.callback(self) self.last_polled_time = time() - while True: + while not self.stop: if time() - self.last_polled_time >= self.poll_period: self.callback(self) self.last_polled_time = time() @@ -88,6 +89,9 @@ def timer(self): def run(self): self.timer() + def close(self): + self.stop = True + def get_name(self): return self.name diff --git a/thingsboard_gateway/gateway/tb_gateway_service.py b/thingsboard_gateway/gateway/tb_gateway_service.py index 3fb1c7975..e3686f74a 100644 --- a/thingsboard_gateway/gateway/tb_gateway_service.py +++ b/thingsboard_gateway/gateway/tb_gateway_service.py @@ -477,7 +477,8 @@ def _watchers(self): # self.__check_shared_attributes() if cur_time - connectors_configuration_check_time > self.__config["thingsboard"].get( - "checkConnectorsConfigurationInSeconds", 60) * 1000: + "checkConnectorsConfigurationInSeconds", 60) * 1000 and not ( + self.__remote_configurator is not None and self.__remote_configurator.in_process): self.check_connector_configuration_updates() connectors_configuration_check_time = time() * 1000