Skip to content

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilit1122 committed Dec 25, 2020
1 parent c627236 commit e8947ff
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions ptd_client_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,20 @@ def _get_initial_range(self) -> None:

response_list = response.split(",")

def get_range_from_ranges_list(param_num: int) -> str:
def get_range_from_ranges_list(param_num: int, setting_name: str) -> str:
try:
if (
response_list[param_num] == "0"
and float(response_list[param_num + 1]) > 0
):
return response_list[param_num + 1]
except ValueError:
logging.info(
"Can not get ptd range value for "
+ ("Amps" if param_num == 1 else "Volts")
)
logging.warning(f"Can not get ptd range value for {setting_name}")
return "Auto"
return "Auto"

self._init_Amps = get_range_from_ranges_list(1)
self._init_Volts = get_range_from_ranges_list(3)
self._init_Amps = get_range_from_ranges_list(1, "Amps")
self._init_Volts = get_range_from_ranges_list(3, "Volts")
logging.info(
f"Initial range for Amps is {self._init_Amps} for Volts is {self._init_Volts}"
)
Expand Down Expand Up @@ -359,7 +356,7 @@ def _handle_cmd(self, cmd: str, p: lib.Proto) -> str:
return "OK"
if cmd[0] == "start-testing" and len(cmd) == 2:
maxVolts, maxAmps = self._ranging_table[cmd[1]]
self._set_range(f"{maxVolts}", f"{maxAmps}")
self._set_range(maxVolts, maxAmps)
logging.info("Starting testing mode")
self._ptd.cmd(f"Go,1000,0,testing-{cmd[1]}")
self._mode = "testing"
Expand Down

0 comments on commit e8947ff

Please sign in to comment.