我根据上面的帖子得到了一个简单的例子,不确定它有多稳定或有用,但仍然在这里发布:
电路Python代码:
import supervisor
while True:
if supervisor.runtime.serial_bytes_available:
value = input().strip()
print(f"Received: {value}\r")
个人电脑代码
import time
import serial
ser = serial.Serial('COM6', 115200) # open serial port
command = b'hello\n\r'
print(f"Sending Command: [{command}]")
ser.write(command) # write a string
ended = False
reply = b''
for _ in range(len(command)):
a = ser.read() # Read the loopback chars and ignore
while True:
a = ser.read()
if a== b'\r':
break
else:
reply += a
time.sleep(0.01)
print(f"Reply was: [{reply}]")
ser.close()
c:\circuitpythontest>python TEST1.PY
Sending Command: [b'hello\n\r']
Reply was: [b'Received: hello']