Skip to content

Commit

Permalink
Merge pull request #1208 from samson0v/master
Browse files Browse the repository at this point in the history
Fixed Modbus Slaves stopping
  • Loading branch information
imbeacon authored Oct 30, 2023
2 parents 618d2d4 + 3e951c0 commit b857292
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions thingsboard_gateway/connectors/modbus/modbus_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 5 additions & 1 deletion thingsboard_gateway/connectors/modbus/slave.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ def __init__(self, **kwargs):

self.last_polled_time = None
self.daemon = True
self.stop = False

self.start()

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()
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion thingsboard_gateway/gateway/tb_gateway_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b857292

Please sign in to comment.