我已经编写了一个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()
此代码主要用于从hc 05读取数据,这是由Android应用程序发送的... Android应用程序是使用 App Inventor
设计的App Inventor的代码块如下所示
运行应用时出现以下错误
Traceback (most recent call last): File "try11.py", line 10, in <module>
state = port.read() File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 456, in read
raise SerialException('device reports readiness to read but returned no data (device disconnected?)') serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
我不明白导致此错误的原因。