python3 调用串口功能

python调用串口,写入数据 

#!/usr/bin/python3

import serial

def serialTest():
    try:
        port = "COM3"
        bps = 115200
        timeO = 5
        ser = serial.Serial(port, bps, timeout = timeO)
        result = ser.write("python invoke serial".encode("gbk"))
        print("write data: ", result)
        ser.close()
    except Exception as e:
        print("ERROR: ", e)

if __name__ == "__main__":
    serialTest()

 

你可能感兴趣的:(Python)