zoukankan      html  css  js  c++  java
  • Python3 串口模块移植并使用。

    • 想通过 Python去控制串口模块,直接上层就使用一门语言,这样虽然执行效率低一些,但是开发速度加快

    • 通过 buildroot 先移植 Python-serial 模块

          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 
    
    • 代码编写

        // 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"
        } 
    
  • 相关阅读:
    vb代码控制 Excel锁定单元格
    SendMessage
    vb 中Treeview控件的一些问题!
    NGWS runtime C# 开始学习 第一天 (2006.6.7)
    DTS Transform Data Task的使用
    GetTickCount
    ASP.NET 2.0 中Login控件的使用
    core dump解析(2)
    tcp滑动窗口机制
    linux 查看文件夹大小 du命令
  • 原文地址:https://www.cnblogs.com/chenfulin5/p/8940124.html
Copyright © 2011-2022 走看看