If you want to control the serial port module through Python, you can use a language directly at the upper layer. Although the execution efficiency is lower, the development speed is accelerated.
First port the Python-serial module through buildroot
x Symbol: BR2_PACKAGE_PYTHON_SERIAL [=y] x x Type : boolean x x Prompt: python-serial x x Location: x x -> Target packages x x -> Interpreter languages and scripting x x -> External python modules
code writing
// vim serial_test.py 1 #!/usr/bin/python3 2 3 import json 4 import serial 5 6 class serial_port(): 7 __configure_file_path = "serial/config.json" 8 9 def __init__(self): 10 json_data = open(self.__configure_file_path); 11 self.config = json.load(json_data) 12 13 def print_msg(self): 14 print(self.config) 15 print(self.config["port"]) 16 print(self.config["baudrate"]) 17 print(self.config["bytesize"]) 18 print(self.config["stopbits"]) 19 print(self.config["parity"]) 20 print(self.config["timeout"]) 21 22 23 if __name__ == '__main__': 24 ser_config = serial_port(); 25 ser_config.print_msg(); 26 27 ser = serial.Serial(ser_config.config["port"], ser_config.config["baudrate"] , timeout = ser_config.config["timeout"]) 28 29 ser.write(("hello").encode()); 30 ser.close(); 31 32 pass; // vim config.json { "port" : "/dev/ttyO1", "baudrate" : 115200, "timeout" : 0.5, "bytesize" : 8, "stopbits" : 1, "parity" : "N" }
The Python3 serial port module is ported and used.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324890443&siteId=291194637
Ranking