logo

串口读取的问题

2018-07-23 10:04
B
_15092752038
17ee1191-e1c7-4327-ae98-cfcaea152e04.png
2018-07-23 13:55
I
网红小智智 星瞳科技

if判断要用双等于符号

if a==1

2018-07-23 19:41
B
_15092752038

还是不对

import time
from pyb import UART
uart = UART(3, 9600)
uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters
def sending_data():
    global uart
    data=bytearray([0x0F,0xA2,0x52,0x09,0x01,0x01,0x60,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x69,0x03])
    uart.write(data)
def recive_data():
    global uart
    if uart.any():
        tmp_data = uart.readline()
        print(tmp_data)
        if tmp_data == ‘\x16\xa2\x00\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11[\x03’:  
while(True):
    sending_data()
    recive_data()
    time.sleep(1000)
2018-07-24 10:56
I
网红小智智 星瞳科技

你if里面没有内容。