我现在正在使用 USB Weatherboard V3。
数据每 1 秒从 /dev/ttyUSB* 连续发送一次……我尝试使用 PySerial 获取数据,但仍然失败。
我只能在输出控制台中获得“RESET”。我无法获取数据。
我想要的是这样的输出:
SHT15 temperature: 2.5 75.1 deg F
SHT15 humidity: 65%
SHT15 dewpoint: 62.7 deg F
BMP085 pressure: 2 2011, 10:05:235.967 in Hg FAIL
BMP085 temperature: 75.3 deg F
TEMT6000 light: 0.1%
Weather meters wind speed: speci0.0 MPH FAIL
Weather meters wind direction: -1 degrees FAIL
Weather meters rainfall: 0.00 inches FAIL
External power: 0.00 Volts FAIL
^ 它来自 minicom(unix 串行程序)。
有人能帮我吗 ?
顺便说一句,这是我目前的代码:
import serial;
import io;
import time;
import os;
# Weather board script #
if __name__ == '__main__' :
try :
print '===================================\n'
print 'USB Weatherboard V3 - Python Script'
print 'Connection datasheet : '
print '(+) Port : /dev/ttyUSB0'
print '(+) Baud rate : 9600'
print '(+) Type : 8N1'
print '===================================\n'
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1, xonxoff=False, rtscts=False, dsrdtr=True)
while True :
arr = ser.readlines()
for strarr in arr :
s = strarr.decode('cp1252').replace('\00','')
#s2 = s.encode('ascii');
s2 = s
if s2[1:3] != '[H' :
print s2
pass
pass
pass
except :
print 'Program exit !'
pass
finally :
ser.close()
pass
请帮助我更正它,或者如果有人在我之前编写过代码,请与我分享:)
Weatherboard v3 数据表:http ://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/USB_Weather_Board_V3_datasheet_110615.pdf
Weatherboard v3 产品:https ://www.sparkfun.com/products/10586