Repository navigation
Expand file tree
/
Copy pathtools.py
More file actions
85 lines (72 loc) · 2.02 KB
/
Copy pathtools.py
File metadata and controls
85 lines (72 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""Validation and status-reporting helpers for serial responses."""
from .errcodes import error_codes
from enum import Enum
def is_null_or_empty(msg):
"""Check whether a response is empty or lacks the expected terminator.
Parameters
----------
msg : bytes
Raw serial response.
Returns
-------
bool
``True`` when the message is incomplete or empty.
"""
if not msg.endswith(b"\r\n") or (len(msg) == 0):
return True
else:
return False
def is_metric(num):
"""Convert a thread-system code to its descriptive name.
Parameters
----------
num : str
``"0"`` for metric or ``"1"`` for imperial.
Returns
-------
str or None
Thread-system name, or ``None`` for an unknown code.
"""
if num == "0":
thread_type = "Metric"
elif num == "1":
thread_type = "Imperial"
else:
thread_type = None
return thread_type
def error_check(status):
"""Print a diagnostic for a controller status response.
Parameters
----------
status : sequence or dict or None
Parsed controller response to inspect.
"""
if not status:
print("Status is None")
elif isinstance(status, dict):
print("Status is a dictionary.")
elif status[1] == "GS":
if status[2] != "0": # is there an error?
err = error_codes[status[2]]
print(f"ERROR: {err}")
else:
print("Status OK")
elif status[1] == "PO":
print("Status OK (position)")
else:
print("Other status:", status)
def move_check(status):
"""Print whether a movement response indicates success.
Parameters
----------
status : sequence or None
Parsed controller response to inspect.
"""
if not status:
print("Status is None")
elif status[1] == "GS":
error_check(status)
elif (status[1] == "PO") or (status[1] == "MO"):
print("Move Successful.")
else:
print(f"Unknown response code {status[1]}")