import serial from time import sleep def recv(serial): while True: data = serial.read_all() if data == '': continue else: break sleep(0.2) return data if __name__ == '__main__': serial = serial.Serial('/dev/ttyUSB1', 115200, timeout=0.5) #/dev/ttyUSB0 if serial.isOpen() : print("open success") else : print("open failed") number = 0 while True: a='aa aa 00 32 40 20 11 11 00 00' data = bytes.fromhex(a) number = number + 1 print("number is:" + str(number)) #print("write:"+ data) sleep(0.2) serial.write(data) #数据写回 sleep(0.2)
标签:__,十六进制,Python,number,sleep,串口,print,serial,data From: https://www.cnblogs.com/dylancao/p/17339759.html