Skip to content

Commit

Permalink
Sets minimum param bank save timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
gfrn committed Jul 25, 2022
1 parent c9a7b2f commit 59dd811
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Changed:
- Empty reply always throws exception
- Fixed exception type on error response (proper `SerialError` response instead of `SerialErrPckgLen`)
- Fixed leftover "broken" messages on a new command when another command times out

### Removed:
- Removed `get_ps_model`
Expand Down
8 changes: 7 additions & 1 deletion src/pydrs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,13 @@ def save_param_bank(self, type_memory: int = 2) -> bytes:
+ index_to_hex(list_func.index("save_param_bank"))
+ hex_type
)
return self._transfer(send_packet, 6)

# User defined timeout is temporarily changed to a "safe" value to prevent lockups
old_timeout = self.timeout
self.timeout = 10
ret = self._transfer(send_packet, 6)
self.timeout = old_timeout
return ret

def load_param_bank(self, type_memory: int = 2) -> bytes:
"""Loads all parameter values into param_data"""
Expand Down
5 changes: 3 additions & 2 deletions src/pydrs/pydrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EthDRS(BaseDRS):

def __init__(self, address: str = None, port: int = 5000):
super().__init__()
self.serial_timeout = 50
self._serial_timeout = 50
if address is None:
print(
"From 2.0.0 onwards, creating the object then using 'connect' to connect will be deprecated. Please use 'EthDRS(address, port)' instead."
Expand All @@ -95,7 +95,7 @@ def __init__(self, address: str = None, port: int = 5000):
self.connect(address, port)

def _format_message(self, msg: bytes, msg_type: bytes) -> bytes:
msg = msg_type + struct.Struct(">f").pack(self.serial_timeout) + msg
msg = msg_type + struct.Struct(">f").pack(self._serial_timeout) + msg
return msg[0:1] + struct.pack(">I", (len(msg) - 1)) + msg[1:]

@staticmethod
Expand Down Expand Up @@ -140,6 +140,7 @@ def timeout(self) -> float:

@timeout.setter
def timeout(self, new_timeout: float):
self._serial_timeout = new_timeout*1000
self.socket.settimeout(new_timeout)

def is_open(self) -> bool:
Expand Down

0 comments on commit 59dd811

Please sign in to comment.