Phase 3: STM32 Removal: Shared RX/TX parts (#3016)
[ExpressLRS.git] / src / python / set_model.py
blob02e01163ef8185d901d54e7cd9b0c53c5ba05a0d
1 import serial, time
2 import argparse
3 import serials_find
4 import bootloader
5 from BFinitPassthrough import *
8 def send_model_command(args):
9 dbg_print("======== SEND SET MODEL COMMAND ========")
10 s = serial.Serial(port=args.port, baudrate=args.baud,
11 bytesize=8, parity='N', stopbits=1,
12 timeout=1, xonxoff=0, rtscts=0)
13 TelemSeq = bootloader.get_model_seq(args.model)
14 s.write(TelemSeq)
15 s.flush()
16 time.sleep(.5)
17 s.close()
20 if __name__ == '__main__':
21 parser = argparse.ArgumentParser(
22 description="Initialize BetaFlight passthrough and send the 'enter bind mode' command")
23 parser.add_argument(
24 'model', metavar='int', nargs=1, type=int,
25 help='The model match number to set')
26 parser.add_argument("-b", "--baud", type=int, default=420000,
27 help="Baud rate for passthrough communication")
28 parser.add_argument("-p", "--port", type=str,
29 help="Override serial port autodetection and use PORT")
30 args = parser.parse_args()
32 if (args.port == None):
33 args.port = serials_find.get_serial_port()
35 try:
36 bf_passthrough_init(args.port, args.baud)
37 except PassthroughEnabled as err:
38 dbg_print(str(err))
40 send_model_command(args)