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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM