应用Inven实现树莓pihc05与android应用程序的蓝牙通信

2024-10-01 17:28:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了一个python代码

import time

import serial
port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=3.0)
state = "4"
var = 6
while 1:
    port.flushInput()

    state = port.read()
    #print state
    if state == "1":
        print "ON"
        #relay on
        #start logging script

    if state == "0":
        print "OFF"
        #relay off
        #stop data logging script

    if state == "2":

        print "SENDING"
        print var
        final = str(var)

        print final
        port.flushInput()
        port.writelines(final)


    else:
        continue

port.close()

这段代码基本上是用来读取hc05的数据,hc05是由android应用程序发送的。。。android应用程序是使用app Inventor设计的

App Inventor的代码块如下所示

enter image description here

运行应用程序时出现以下错误

^{pr2}$

我不明白是什么导致了这个错误。在


Tags: 代码import应用程序ifportvarloggingserial

热门问题