- Main
- Tutorials
- Library
- Samples

- File List
- Globals

uart.py
Go to the documentation of this file.
1 '''
2 Copyright (C) 2019 Moxa Inc. All rights reserved.
3 SPDX-License-Identifier: Apache-2.0
4
5 UART Python Sample Application
6
7 Date Author Comment
8 2019-02-11 William Chang Created it.
9 '''
10
11
19
20 from ioThinx_4530 import ioThinx_4530_API
21 import argparse
22 import os
23
24 BUF_LEN = 4096
25 UART_MODE_RS232 = 0
26 UART_PORT_1 = 0
27
28
29 def main():
30 parser = argparse.ArgumentParser(description="Miscellaneous sample program.")
31 parser.add_argument("-b", "--baudrate", dest="uart_baudrate", type=int, default=115200)
32 parser.add_argument("-p", "--port", dest="uart_port", type=int, default=UART_PORT_1)
33 parser.add_argument("-m", "--mode", dest="uart_mode", type=int, default=UART_MODE_RS232)
34 args = parser.parse_args()
35
36 uart_slot = 0
37 uart_port = args.uart_port
38 uart_mode = args.uart_mode
39 uart_baudrate = args.uart_baudrate
40 print("UART slot = {}".format(uart_slot))
41 print("UART port = {}".format(uart_port))
42 print("UART mode = {}".format(uart_mode))
43 print("UART baudrate = {}".format(uart_baudrate))
44
45 device = ioThinx_4530_API.ioThinx_4530_API()
46 fd = device.ioThinx_Uart_Open(uart_slot, uart_port, uart_mode, uart_baudrate)
47 print("fd = {}".format(fd))
48 print("Start UART echo.")
49
50 while True:
51 buf = os.read(fd, BUF_LEN)
52 print(len(buf))
53 print(buf)
54 if len(buf) > 0:
55 os.write(fd, buf)
56 if 'quit' in buf.decode():
57 break
58
59 print("Stop UART echo.")
60 os.close(fd)
61
62
63 if __name__ == '__main__':
64 main()
uart.main
def main()
Definition: uart.py:29
format
char const int const cJSON_bool format
Definition: cJSON.h:161