【发布时间】:2015-06-25 09:08:45
【问题描述】:
我正在通过串行端口将 PIC 与 Raspberry PI 连接起来。我的 max485 发送和接收使能引脚由 gpio 引脚控制。我收到的数据打印成功。但它没有执行所需的功能。
while True:
GPIO.output(repin, False)
port.flushInput()
time.sleep(.oo5)
port.write(bytes(address))
time.sleep(.01)
GPIO.output(repin, Ture)
port.flushInput()
data=port.readline()
if data:
address=address+1
if data == "ok" :
print "reached"
print data
if not data:
print "no data"
当我收到 OK 时。它打印“ok”,但没有打印“reached”。当没有收到数据时,它会打印一个空白值而不是“无数据”。
【问题讨论】:
-
您收到的字符串可能包含终止的 CR、LF 或 NULL。尝试专门比较前两个字符。
-
您的代码以“while Ture”开头。我想它应该是“当真”?
-
当使用 data=port.read(2) 时,它工作正常。但我需要使用 readline() 。我的数据可能是 2 或 3 字节长。@ Roger Rowland
-
是的,你是对的。这只是一个愚蠢的错误,不是我的实际问题@S.L.巴特
-
打印类型(数据)、长度(数据)会得到什么??
标签: python networking raspberry-pi pic