本文整理汇总了Python中device.Device.send_command方法的典型用法代码示例。如果您正苦于以下问题:Python Device.send_command方法的具体用法?Python Device.send_command怎么用?Python Device.send_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类device.Device
的用法示例。
在下文中一共展示了Device.send_command方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GadgetsConnector
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import send_command [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()
示例2: OasisUnit
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import send_command [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)
示例3: Device
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import send_command [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")
示例4: print
# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import send_command [as 别名]
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:
print("SENDING:", c)
device.send_command(c)
r = reader.next()