Tinyos.com到r0x中继模块的接口。

tosr0x的Python项目详细描述


用于与[tinyosshop.com](http://www.tinyosshop.com/index.php?route=product/product&product_id=365)和其他在线零售商提供的“tosr0x”中继控制器通信的python模块。

功能性

  • 检测TOSR0X USB和WiFi设备。
  • 设置继电器状态。
  • 查询中继状态。
  • 查询温度(在支持的模型上)。

要求

  • python串行模块(应默认安装)

安装

使用setup.py:

python setup.py install

如果使用Debian或衍生物(ubuntu),可能需要额外的USB权限:

Add the user to the ‘dialout’ group:

$ sudo usermod -G dialout -a <username>

添加udev规则文件以允许访问usb设备:

$ cat /etc/udev/rules.d/50-usb.rules # allow access to usb devices for users in dialout group SUBSYSTEM==”usb”, MODE=”0666”, GROUP=”dialout”

用法

调用handler函数返回tosr0x对象的列表:

>import tosr0x >th = tosr0x.handler()

Testing USB serial device on /dev/ttyUSB0 Testing USB serial device on /dev/ttyUSB1 Testing USB serial device on /dev/ttyUSB2 Testing USB serial device on /dev/ttyUSB3 TOSR0x device found on /dev/ttyUSB3

>myTosr0x = th[0] >print myT0sr0x

<tosr0x.relayModule instance at 0xb68be46c>

默认情况下,处理程序会扫描所有USB端口以查找与r0x设备兼容的设备。你 还可以指定要扫描的端口范围:

>th = tosr0x.handler(devicePath=[‘/dev/ttyUSB3’])

Testing USB serial device on /dev/ttyUSB3 TOSR0x device found on /dev/ttyUSB3

通常模块上的所有继电器在初始化时循环,以确定 中继计数。您可以指定一个中继计数来防止此情况:

>th = tosr0x.handler(devicePath=[‘/dev/ttyUSB3’], relayCount=4)

Testing USB serial device on /dev/ttyUSB3 TOSR0x device found on /dev/ttyUSB3

也可以不使用处理程序直接使用类:

FOR SERIAL: >import serial >import tosr0x >sd=serial.Serial(‘/dev/ttyUSB0’, timeout=0.1) >myTosr0x=tosr0x.relayModule(sd) #Num relays not specified in this example

FOR WIFI: >import tosr0x >myTosr0x = tosr0x.relayModule( (‘192.168.1.2’,2000), 2) #Module of 2 relays

将继电器状态设置为0或1:

>myTosr0x.set_relay_position(1,1) True

>myTosr0x.set_relay_position(2,0) True

(注:继电器编号从1开始。使用继电器编号0设置所有继电器的状态。

获取中继位置(返回为dict{relay:state}):

>myTosr0x.get_relay_positions() {1: 1, 2: 0}

对于支持温度探头的模块,获得环境温度摄氏度:

>myTosr0x.get_temperature() 23.94

项目

  • james stewart(@amorphic)在一个温度监测框架[braubuddy](http://braubuddy.org)中使用tosr0x来实现环境控制器。
  • alex roche(@alexroche)正在使用带有wifi选项的tosr0x,通过运行在覆盆子pi上的openremote控制器来控制百叶窗。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java异常无法从资源中找到可绘制的图标   Android 6.0.0上应用程序崩溃后java Android VM重新启动   当我将java项目导出到runnable jar中时,log4j不会记录日志   java在Jtable netbeans中显示MS访问数据   为什么不呢。Java中的NETstyle委托而不是闭包?   java如何正确使用如此多的CPU停止命令队列循环?   java使用==   java如何将scriptlet转换为JSTL?   java mvn测试失败,但通过IntelliJ IDEA运行测试   java为什么文件在使用另一个按钮后不会被删除   java JDBC MySQL不读取最新插入   java如何在安卓中绘制从Firebase数据库检索到的数据   java HTML解析getElementByClass方法   java Arraylist hashmap 安卓