1. 硬件: DS9490R, 温度探头: DS18B20, 刷好openwrt的WR703N一台
2. 安装python-mini, 大约占用空间1.6M.
opkg install libffi python-mini
3. 提供ar71xx内核的python专用库, 文件名为: xuowpy.so
将本文件拷贝到路由器上, 并修改属性
chmod +x xuowpy.so
4. python的代码如下
-
# 1-wire的linux下的python专用库测试例程
-
# 硬件: DS9490R, 温度探头: DS18B20, 刷好openwrt的WR703N一台
-
# http://blog.chinaunix.net/uid-27194309-id-4371278.html
-
# opkg install libffi python-mini
-
# chmod +x xuowpy.so
-
-
import xuowpy
-
-
str1 = xuowpy.test1("12")
-
print str1
-
-
data1 = [0x31, 0x32, 0x33, 0x34, 0x35, 0x36]
-
#data1 = [0x01, 0x32, 0x33, 0x34, 0x35, 0x36]
-
str1 = ""
-
for i in range(len(data1)):
-
str1 = str1 + "%02X" % data1[i] #大写2位16进制字串
-
print str1
-
-
num = xuowpy.get_crc8(str1)
-
print "crc8 = " + hex(num) + ", " + str(num)
-
-
num = xuowpy.get_crc16(str1)
-
print "crc16 = " + hex(num) + ", " + str(num)
-
-
num = xuowpy.get_crc32(str1)
-
print "crc32 = " + hex(num) + ", " + str(num)
-
-
#---- 1-wire 测试
-
device_name = "USB"
-
portnum = xuowpy.device_open(device_name)
-
-
if portnum > 0:
-
value = xuowpy.ds18b20_get(portnum)
-
print "ds18b20 = " + str(value)
-
-
xuowpy.device_close(portnum)
阅读(2601) | 评论(0) | 转发(0) |