当前位置: 首页>>代码示例>>Python>>正文


Python Sensor.read方法代码示例

本文整理汇总了Python中sensor.Sensor.read方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.read方法的具体用法?Python Sensor.read怎么用?Python Sensor.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sensor.Sensor的用法示例。


在下文中一共展示了Sensor.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Slice

# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import read [as 别名]
class Slice(Thread):
    def __init__(self, local=False, interval=INTERVAL):
        Thread.__init__(self)
        self.done = None
        self.interval = interval
        self.local = local
        self.sensor = Sensor()

    def run(self):
        self.done = Event()
        while not self.done.wait(self.interval):
            info = self.sensor.read()
            if info:
                if self.local:
                    print info
                else:
                    self.send(info)
            else:
                print('The sensor could not be read')

    def send(self, info):
        # search for the server service
        service_matches = bt.find_service(uuid=UUID)

        if not service_matches:
            print('The server could not be found')

        first_match = service_matches[0]
        port = first_match['port']
        name = first_match['name']
        host = first_match['host']

        print('Attempting to connect to \'%s\' on %s' % (name, host))

        # Create the client socket
        sock = bt.BluetoothSocket(bt.RFCOMM)
        sock.connect((host, port))
        print('The connection has been accepted by the server')

        sock.send(str(info))
        print('The information has been sent')

        sock.close()
        print('The client socket has been closed')

    def stop(self):
        try:
            self.done.set()
        except AttributeError:
            print('The client cannot be stopped. It is not running')
        else:
            print('The client has been stopped')
开发者ID:felipedau,项目名称:blueberrywsn,代码行数:54,代码来源:slice.py


注:本文中的sensor.Sensor.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。