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


Python Device.gen_lines方法代码示例

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


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

示例1: GadgetsConnector

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import gen_lines [as 别名]
class GadgetsConnector(Daemon):
  ''' daemonized token connector '''
  def __init__(self, log_file=None):
    Daemon.__init__(self, '/tmp/turris-gadgets.pid')
    self.log = self.open_file(log_file)
    self.token = Device(device="/dev/ttyUSB0")
    self.reader = self.token.gen_lines(timeout=5)

  def open_file(self, filename):
    ''' file helper'''
    if filename:
      import os.path
      if os.path.exists(filename):
        file_mode = "a"
      else:
        file_mode = "w"
      return file(filename, file_mode)
    return None

  def send_raw(self, command):
    ''' send raw command to token '''
    self.token.send_command(command)
    return self.reader.next()

  def whoami(self):
    ''' token info''' 
    return self.send_raw('WHO AM I?')

  def getslot(self, index):
    ''' get gadget address registered on slot '''
    str_i = str(index).zfill(2)
    reply = self.send_raw('GET SLOT:%s' % str_i)
    slot = re.search("^SLOT:%s \[(\d{8}|-{8})\]" % str_i, reply)
    return slot.group(1)

  def cmd_read(self, line):
    m = re.search("^\[(\d{8})\]\s([a-zA-Z0-9_-]+)\s(.+)", line)
    if m.group():
      return [m.group(1), m.group(2), m.group(3)]
    return None

  def run(self):
    ''' only method called by daemon (start, restart) '''
    if self.log:
      self.log.write("%s\n" % self.whoami())
      for i in range(0, 32):
        self.log.write("SLOT: %s - %s\n" % (i, self.getslot(i)))
        self.log.flush()
开发者ID:trusnak,项目名称:turris_gadgets_deamon,代码行数:50,代码来源:daemon.py

示例2: OasisUnit

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import gen_lines [as 别名]
class OasisUnit(object):

    '''
        class representing one oasis unit (turris dongle)
    '''

    def __init__(self, unitName):
        '''
            init
        '''
        self.unitName = unitName
        self.queue = list()
        # pgx device
        self.pgx = None
        # pgy device
        self.pgy = None
        # beeper status
        self.beeper = 'NONE'
        self.device = None
        self.reader = None

        unitDevice = Glob.config.getUnitParams(unitName)['device']
        try:
            self.device = Device(device=unitDevice)
            self.reader = self.device.gen_lines(0.05)
        except Exception as e:
            Glob.logger.error(
                'Unable to open device %s (unit: %s): %s' % (unitDevice, unitName, str(e)))

    def alarm(self):
        self.beeper = 'ALARM'
        self.sendStatus()

    def beepSlow(self):
        self.beeper = 'SLOW'
        self.sendStatus()

    def beepFast(self):
        self.beeper = 'FAST'
        self.sendStatus()

    def alarmStop(self):
        self.beeper = 'NONE'
        self.sendStatus()

    def sendStatus(self, repeat=1, delay=0):
        pgx = 0
        pgy = 0
        if self.pgx:
            pgx = self.pgx.getStatus()
        if self.pgy:
            pgy = self.pgy.getStatus()
        if self.beeper == 'ALARM':
            alarm = 1
            beep = 'NONE'
        else:
            alarm = 0
            beep = self.beeper
        cmd = 'TX ENROLL:0 PGX:%s PGY:%s ALARM:%s BEEP:%s' % (
            pgx, pgy, alarm, beep)
        timestamp = time.time() + delay
        while True:
            self.queueCommand(cmd, timestamp)
            timestamp += 0.2
            repeat -= 1
            if repeat <= 0:
                break

    def queueCommand(self, cmd, timestamp):
        self.queue.append((cmd, timestamp))

    def sendCommand(self, cmd):
        Glob.loggerOasis.info(cmd)
        self.device.send_command(cmd)

    def beep(self):
        st = self.beeper
        self.beeper = 'SLOW'
        self.sendStatus(0)
        self.beeper = st
        self.sendStatus(1, 0.4)

    def checkTimeout(self):
        '''
            check if there is some timeouted command in the queue
        '''
        if self.queue:
            cmd, timestamp = self.queue[0]
            if timestamp < time.time():
                self.sendCommand(cmd)
                self.queue.pop(0)
开发者ID:janredl,项目名称:turhouse,代码行数:93,代码来源:oasisunit.py

示例3: Device

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import gen_lines [as 别名]
"""
Turris
"""
from __future__ import print_function
import sys
import datetime
import time

from device import Device

if __name__ == "__main__":
    device_name = "/dev/ttyUSB0"
    device = Device(device="/dev/ttyUSB0")
    reader = device.gen_lines()

    dvere_open="[XXXXXXXX] JA-81M SENSOR LB:0 ACT:1"

    device = Device(device=device_name)
    reader = device.gen_lines()
    while True:
        line = reader.next()
        if line == dvere_open:
            device.send_command("TX ENROLL:0 PGX:0 PGY:1 ALARM:0 BEEP:NONE")
            time.sleep(5)
            device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:NONE")
开发者ID:mhaken,项目名称:OpeningDoors,代码行数:27,代码来源:doors.py

示例4: print

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import gen_lines [as 别名]
    else:
        cmd2 = "PGX:0"

    if pc2 == 0 or pc3 == 0:
        cmd3 = "PGY:1"
    else:
        cmd3 = "PGY:0"
    
    #--------------------------------------------------------------
    if prx == 1:
        print("Zasuvky:",cmd2,cmd3)
    #------- sestaveni cmd line ---------------------------------------------
    c = cmd1 + " " + cmd2 + " " + cmd3 + " " + cmd4
    #------- odeslani cmd line ---------------------------------------------
    device = Device(device="/dev/ttyUSB0")
    reader = device.gen_lines(timeout=20)
    if prx == 1:
        print("SENDING:", c)
    device.send_command(c)
    r = reader.next()
    if prx == 1:
        print("REPLY:",r)
    time.sleep(0.3)
    if prx == 1:
        print("SENDING:", c)
    device.send_command(c)
    r = reader.next()
    if prx == 1:
        print ("REPLY:",r)
    time.sleep(0.4)
    if prx == 1:
开发者ID:lzita,项目名称:turris-gadgets-axlprint,代码行数:33,代码来源:axlprint.py


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