Bootstrap

python制作串口工具

# coding:utf-8
import time
import serial
import string
import binascii
import linecache

FilePath="G:\\WorkSVN\\TPMS\\TOOLS\\R01\\App\\APP_FIFO\\SampleCode\\tpmsRcode\\TDATEST\\12_spi.def"

file = open(FilePath,'rb')
c = file.read(1)
count = linecache.getline(FilePath,100)

lines = open(FilePath,'rb').readlines()

ser = serial.Serial()
ser.baudrate = 115200
ser.port = 'COM3'
ser.open()
print(ser.isOpen())

print(lines.__len__())
for linx in lines:
    ser.write(linx)
    time.sleep(0.01)
    str = ser.read_all()
    print(str)
ser.write('go\n'.encode())
time.sleep(0.1)
str = ser.read_all()
print(str)
ser.close()

转载于:https://www.cnblogs.com/mynight2012/p/10450931.html

;