从NAO接收数据

当ALInfrared从另一个NAO接收到数据时,它会引发一个包含该数据的事件。

该事件的所有信息也都保存在内存中。

下表中介绍了事件数组及被分开的数据:

事件/数据 类型 ALMemory 说明
事件 字符串 "InfraRedIpAdressReceived" IP地址
数据 字符串 "Device/SubDeviceList/IR/LIRC/Data/uInt8/Byte/Sensor/Value/" IP地址
事件 整型(int) "InfraRedOneByteReceived" 8位值
数据 整型(int) "Device/SubDeviceList/IR/LIRC/Data/uInt8/Byte/Sensor/Value/" 8位值
事件 数组 "InfraRedFourBytesReceived" 包含4个八位字节的数组
数据 整型(int) "Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte1/Sensor/Value/" 第1个八位字节
数据 整型(int) "Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte2/Sensor/Value/" 第2个八位字节
数据 整型(int) "Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte3/Sensor/Value/" 第3个八位字节
数据 整型(int) "Device/SubDeviceList/IR/LIRC/Data/uInt32/Byte4/Sensor/Value/" 第4个八位字节

Python范例:接收一个IP地址

from naoqi import * import time # create python module class myModule(ALModule): """python class myModule test auto documentation""" def pythondatachanged(self, strVarName, value, strMessage): """callback when data change""" print "----------------------------------------------------------" print "IP address = ", value, " ", strMessage print "----------------------------------------------------------" broker = ALBroker("pythonBroker","127.0.0.1",9999,"127.0.0.1",9559) # call method try: lirc=ALProxy("ALInfrared") eventName = "InfraRedIpAdressReceived" pythonModule = myModule("pythonModule") prox = ALProxy("ALMemory") prox.subscribeToEvent(eventName,"pythonModule", "pythondatachanged") except Exception,e: print "error" print e exit(1) time.sleep(10) exit(0)





Copyright © 2010 Aldebaran-Robotics - 版权所有