-
Notifications
You must be signed in to change notification settings - Fork 0
/
aimos_select
32 lines (27 loc) · 880 Bytes
/
aimos_select
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
#!/usr/bin/env python3
import serial
import sys
def aimos_select(x):
if not 1 <= x <= 8:
raise ValueError("Input must be between 1 and 8 inclusive")
# Define the bytes to send
byte1 = 0x56
byte2 = 0x30
byte3 = 0x30 + x
byte4 = 0x53
byte5 = 0x0E
# Open the serial port
with serial.Serial("/dev/ttyAMA0", 19200, timeout=1) as ser:
# Send the bytes
ser.write(bytearray([byte1, byte2, byte3, byte4, byte5]))
print(f"Sent bytes: {[hex(byte) for byte in [byte1, byte2, byte3, byte4, byte5]]}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python aimos_select.py <number between 1 and 8>")
sys.exit(1)
try:
input_number = int(sys.argv[1])
aimos_select(input_number)
except ValueError as e:
print(f"Error: {e}")
sys.exit(1)