Skip to content

Instantly share code, notes, and snippets.

@wwj718
Created April 20, 2018 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wwj718/4bd81877f4155b70beb5a596dafc893c to your computer and use it in GitHub Desktop.
Save wwj718/4bd81877f4155b70beb5a596dafc893c to your computer and use it in GitHub Desktop.
strip bug
from microbit import *
def get_topic_and_data(b):
try:
c = b.rstrip()
sleep(10)
# c = b.split(b"\r\n")[0]
# uart.write(b)
# uart.write(b'{"a": 18}\r\n') # 稳定
uart.write(c + b'\r\n')
# json_str = str(b, 'utf-8')
# json = eval(json_str)
# display.show(str(json["a"])[-1])
return "a"
except:
pass
# uart.write(b'error\r\n')
# display.show(str("!"))
while True:
r = uart.readline() # is bytes or none
if r:
'''
try:
b = r
uart.write(b)
b = b.strip()
# uart.write(b+b"\r\n")
# uart.write(b+b"\r\n")
json_str = str(b, 'utf-8')
json = eval(json_str)
except:
pass
# uart.write(b'error\r\n')
'''
d = get_topic_and_data(r)
if d:
pass
# uart.write(bytes(d,'utf-8')+b'\r\n')
@wwj718
Copy link
Author

wwj718 commented Apr 20, 2018

看去是 切割的时候 \n\r ,被输入捡过去

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment