Skip to content

Commit

Permalink
Fix dis/reconnection.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Oct 9, 2023
1 parent 22d7a8d commit c16f0a0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions chillerd
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class ChillerDaemon:
try:
self._port = serial.Serial(self._config.serial_port, self._config.serial_baud,
timeout=self._config.serial_timeout, xonxoff=True)

# Make sure the chiller responds
self.send_message(TTKCommand.ReadStatus)
self.read_response()
time.sleep(1)

print('Connected to', self._config.serial_port)
prefix = 'Restored' if self._port_error else 'Established'
log.info(self._config.log_name, prefix + ' serial connection to chiller')
Expand Down Expand Up @@ -165,11 +171,10 @@ class ChillerDaemon:

except Exception as exception:
with self._lock:
with self._lock:
self._status = {
'date': datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
'status': ChillerStatus.Disabled,
}
self._status = {
'date': datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
'status': ChillerStatus.Disabled,
}

self._port.close()
print(exception)
Expand Down

0 comments on commit c16f0a0

Please sign in to comment.