-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (52 loc) · 1.68 KB
/
main.py
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
import serial
BANK_A = 0x00
BANK_B = 0x01
BANK_C = 0x02
CHANNEL_1 = 0x01
CHANNEL_2 = 0x02
CHANNEL_3 = 0x03
CHANNEL_4 = 0x04
CHANNEL_5 = 0x05
CHANNEL_6 = 0x06
CHANNEL_7 = 0x07
CHANNEL_8 = 0x08
COMMAND_ADD_MOTOR = 0xAA
COMMAND_DELETE_MOTOR = 0xAB
COMMAND_PRESET = 0xAD
COMMAND_TILT_UP = 0xBA
COMMAND_TILT_DOWN = 0xBB
COMMAND_STOP = 0xCC
COMMAND_UP = 0xDD
COMMAND_DOWN = 0xEE
def send_instruction(bank, channel, command):
instructions = [0x67, bank, channel, command]
checksum = 0x00
for instruction in instructions:
checksum ^= instruction
instructions.append(checksum)
binary_date = bytes(instructions)
print("Instructions: %s" % instructions)
print("Checksum: %X" % checksum)
print("Binary Data: %s" % binary_date)
with serial.Serial(
port='/tmp/ttyV1',
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=5
) as serial_port:
serial_port.write(binary_date)
# The expected response is 0x66 <COMMAND> 0xFF
response = serial_port.read(3)
print("Response: %s" % response)
if __name__ == '__main__':
send_instruction(BANK_A, CHANNEL_1, COMMAND_ADD_MOTOR)
send_instruction(BANK_A, CHANNEL_1, COMMAND_DELETE_MOTOR)
send_instruction(BANK_A, CHANNEL_1, COMMAND_PRESET)
send_instruction(BANK_A, CHANNEL_1, COMMAND_TILT_UP)
send_instruction(BANK_A, CHANNEL_1, COMMAND_TILT_DOWN)
send_instruction(BANK_A, CHANNEL_1, COMMAND_STOP)
send_instruction(BANK_A, CHANNEL_1, COMMAND_UP)
send_instruction(BANK_A, CHANNEL_1, COMMAND_ADD_MOTOR)
send_instruction(BANK_A, CHANNEL_1, COMMAND_DOWN)