Skip to content

Commit

Permalink
add retries on TCP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
BeamCtrl committed Mar 12, 2022
1 parent dcee1cc commit fbaf77a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion request.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,18 @@ def write_register(self, reg, value, tries=10):
os.close(fd)
else:
try:
self.response = self.client.write_single_register(reg, 1)
valid = 0
if tries > 0:
valid = self.client.write_single_register(reg, 1)
if not valid:
tries -= 1
self.write_errors += 1
self.write_register(reg, value, tries)
if tries == 0:
fd = os.open("RAM/err", os.O_WRONLY)
os.write(fd, bytes(f"Write error, no tries left on register:{reg} {valid}\n", "utf-8"))
os.close(fd)

except:
with os.open("RAM/err", os.O_WRONLY) as fd:
os.write(fd, bytes("TCP write error on addrs:" + str(reg) + "\n", "utf-8"))
Expand Down

0 comments on commit fbaf77a

Please sign in to comment.