import serial
try:
portx=“com1”
bps=115200
timex=5
ser=serial.Serial(portx,bps,timeout=timex)
result=ser.write(“我是曉99999999東”.encode(“gbk”))
print(“字節總數”,result)
ser.close()
except Exception as e:
print(‘異常:’,e)
///
import serial
from time import sleep
def recv(serial):
while True:
data = serial.read_all()
if data == ‘’:
continue
else:
break
sleep(0.02)
return data
/