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()

posted @ 2019-02-28 15:54  上下求索之  阅读(1252)  评论(0编辑  收藏  举报