我有兩個英國廣播公司微型位,並使用無線電功能從一個從屬數據傳輸到主微位。當數據傳輸時,我得到隨機回車,我不知道是什麼問題,我試圖剝離任何隨機CR等,但仍然得到同樣的問題。英國廣播公司微型:位 - 無線電串轉移隨機回車
a = 1時,開,
= 2,
關,77
= 3,
在88
=== ================================================
網關的代碼
from microbit import *
import radio
radio.config(group=0)
radio.on()
while True:
incoming = radio.receive()
if incoming:
uart.write(incoming)
====================================== ========
從代碼
from microbit import *
import radio
radio.config(group=0)
radio.on()
while True:
if button_a.was_pressed():
radio.send('Matt,A=On,Off' + '\n') # a-ha
display.scroll("A")
if button_b.was_pressed():
radio.send('Matt,B=On,Off' + '\n') # a-ha
display.scroll("B")
============================= ============================
PySerial代碼
import sys
import glob
import serial
def serial_ports():
ports = ['COM%s' % (i + 1) for i in range(256)]
result = []
for port in ports:
try:
s = serial.Serial(port)
s.close()
result.append(port)
except (OSError, serial.SerialException):
pass
return result
if __name__ == '__main__':
print(serial_ports())
try:
ser = serial.Serial('COM5', 115200, timeout = 0)
print("connected to: " + (ser.portstr))
except serial.SerialException:
pass
while True:
line = ser.readline().decode('utf-8')
# Read a line and convert it from b'xxx\r\n' to xxx
if line: # If it isn't a blank line
f = open('output.csv', 'a+')
f.write(line + '\n')
print(line)
f.close()
ser.close()
好點測試與另一個串行終端,我一直在使用pyserial所以必須是我的pyserial代碼的問題。感謝您的測試 – Brendon
如果您想發佈您的pyserial代碼,也許我們可以看到什麼是添加回車。 – oppy
這是我的PySerial代碼 – Brendon