本文整理汇总了Python中interface.Interface类的典型用法代码示例。如果您正苦于以下问题:Python Interface类的具体用法?Python Interface怎么用?Python Interface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Interface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(name):
sm = generate_map(name)
opcd = OPCD_Interface(sm['opcd_ctrl'])
platform = opcd.get('platform')
device = opcd.get(platform + '.nrf_serial')
global THIS_SYS_ID
THIS_SYS_ID = opcd.get('aircomm.id')
key = opcd.get('aircomm.psk')
crypt.init(key)
mhist = MessageHistory(60)
out_socket = sm['aircomm_out']
in_socket = sm['aircomm_in']
aci = Interface(device)
acr = ACIReader(aci, out_socket, mhist)
acr.start()
# read from SCL in socket and send data via NRF
while True:
data = loads(in_socket.recv())
if len(data) == 2:
msg = [data[0], THIS_SYS_ID, data[1]]
elif len(data) > 2:
msg = [data[0], THIS_SYS_ID] + data[1:]
else:
continue
crypt_data = crypt.encrypt(dumps(msg))
mhist.append(crypt_data)
aci.send(crypt_data)
示例2: iwconfig
def iwconfig():
devnull = open(os.devnull, 'w')
lst = []
cmd = Popen(['iwconfig'], stdout=PIPE, stderr=devnull)
for line in cmd.communicate()[0].split('\n\n'):
tmpiface = Interface(None, None, None, None)
line = line.strip()
if len(line) == 0:
continue
ifname = re.search('^([A-Za-z0-9]+)', line)
ifessid = re.search('ESSID:"([A-Za-z0-9]+)"', line)
ifmode = re.search('Mode:([A-Za-z]+)', line)
ifbssid = re.search('Access Point: ([0-9:A-F]+)', line)
if ifname is not None:
tmpiface.name = ifname.group(1)
if ifessid is not None:
tmpiface.essid = ifessid.group(1)
if ifmode is not None:
tmpiface.mode = ifmode.group(1)
if ifbssid is not None:
tmpiface.bssid = ifbssid.group(1)
lst.append(tmpiface)
devnull.close()
return lst
示例3: main
def main():
# command line arguments
history = DATA_FILES_FOLDER_PATH + sys.argv[1]
control_input = DATA_FILES_FOLDER_PATH + sys.argv[2]
control_output = DATA_FILES_FOLDER_PATH + sys.argv[3]
bid_stream_files = []
for i in range(0, NUMBER_BID_STREAMS):
bid_stream_files.append(DATA_FILES_FOLDER_PATH + sys.argv[4+i])
bid_market = BidMarket()
bid_market.import_history(history)
interface = Interface(
bid_market,
control_input,
control_output)
bid_streams = []
for i in range(0, NUMBER_BID_STREAMS):
bid_streams.append(BidStream(bid_stream_files[i], bid_market))
# make daemons so threads close with program
bid_streams[i].daemon = True
bid_streams[i].start()
interface.open_control_input_stream()
示例4: __init__
def __init__(self):
Interface.__init__(self, "RSC")
Configurable.__init__(self)
LOG("Created")
self.toCheck = [ 'TM', 'TC' ]
self.rscStatus = {}
self.rscCallbacks = []
示例5: __init__
def __init__(self):
Interface.__init__(self, "TC")
Configurable.__init__(self)
self.__lastStatus = None
self.__lastElement = None
self.__useConfig = {}
LOG("Created")
示例6: run
def run():
import optparse
from cli.console import Console
parser = optparse.OptionParser()
parser.add_option('-d', '--debug', action='store_true', default=False,
dest='debug',
help='show debugging output (default: no)')
parser.add_option('-l', '--line', default='/dev/ttyUSB1',
dest='line',
help='serial line device (default: /dev/ttyUSB1)')
parser.add_option('-b', '--baud', default=9600, type='int',
dest='baudrate',
help='serial baud rate (default: 9600 bps)')
parser.add_option('-t', '--timeout', default=1, type='int',
dest='timeout',
help='serial read timeout (default: 1 second)')
options, args = parser.parse_args()
ser = serial.Serial(options.line, options.baudrate, timeout=options.timeout)
rcv = Receiver(ser,options).start()
if args and args[0] == "console":
console = Console()
interface = Interface(ser,console)
try:
try:
interface.loop()
except KeyboardInterrupt:
rcv.running = False
finally:
console.restore()
示例7: __init__
def __init__(self):
'''setup the serial device handler. Once this object is created,
you must call destroy() before exiting.
Updates are typles in one of three formats:
('BATTERY', <battery level>) # system battery level
('SHUTDOWN', None) # system has recieved a shutdown command
('CONTROL', <control update>) # button press
'''
Interface.__init__(self)
self.kill_flag = False
self.battery = 100 # current battery level
self.controls = None # current control state
self.do_shutdown = True # flag for shutting down unit on destroy()
# try to open the serial ports and handler threads
try:
# serial port uses long reads to block and timeouts to wake back up
self.pwr_port = serial.Serial(PWR_NAME, timeout=TIMEOUT, writeTimeout=TIMEOUT)
self.pwr_port.baudrate = BAUD
thread = threading.Thread(target=self.pwr_thread)
thread.start()
except: print 'Could not open power device'
try:
# conn port uses a similar structure, timeouts determine how long to block for
self.con_port = serial.Serial(CON_NAME, timeout=TIMEOUT, writeTimeout=TIMEOUT)
self.con_port.baudrate = BAUD
thread = threading.Thread(target=self.con_thread)
thread.start()
except: print 'Could not open controller device'
示例8: __init__
def __init__(self, cni, mac, host_ifname, tag):
self.pid = os.getpid()
self.container_mac = mac
self.host_ifname = host_ifname
self.vlan_tag = tag
self.vlan_ifname = CniMacVlan._make_vlan_intf_name(tag)
CniInterface.__init__(self, cni)
return
示例9: new_interface
def new_interface(self, server, socket):
self.add_recent_server(server)
interface = Interface(server, socket)
interface.mode = 'checkpoint'
self.interfaces[server] = interface
self.request_header(interface, self.blockchain.checkpoint_height)
if server == self.default_server:
self.switch_to_interface(server)
self.notify('interfaces')
示例10: __init__
def __init__(self):
Interface.__init__(self, "TM")
Configurable.__init__(self)
self.__tmParameters = {}
self.__verifiers = []
self.__verifTable = []
self.__verifMutex = thread.allocate_lock()
self.__ctxName = None
LOG("Created")
示例11: main
def main():
interface = Interface()
while True:
try:
print(interface.recv())
except KeyboardInterrupt:
print("interrupted")
break
interface.stop()
示例12: __init__
def __init__(self, probeIp):
Interface.__init__(self, probeIp)
# Thread.__init__(self)
# self.setName("Cli")
self.isRunning = True
# wins and boxes
self.status = None
self.commandInput = None
self.text = None
self.probesPanel = None
示例13: new_game
class Billiard:
def new_game(self):
self.scores = [0, 0]
self.sim.add_ball(0, 0.5, 0.5, 0.0, 0.0)
#build balls triangle
for i in range(6):
for j in range(i):
self.sim.add_ball((i*(i-1))/2+j+1, 1.3+i*0.06, 0.5+j*0.06-i*0.03, 0.0, 0.0)
def __init__(self):
self.gui = Interface()
self.gui.start()
self.sim = Simulation()
clock = pygame.time.Clock()
self.gui.current_player = 0
while not self.gui.done:
current_player = self.gui.current_player
#start new game if requested
if self.gui.new_game_request:
self.gui.new_game_request = False
self.new_game()
self.gui.balls = {}
#has current player changed?
if not self.gui.stable and self.sim.is_stable():
current_player = (current_player+1)%2
self.gui.current_player = current_player
self.gui.stable = self.sim.is_stable()
#update ball positions
for label, ball in self.sim.balls.iteritems():
self.gui.balls[label] = ball.pos
#read shot command from interface and execute them
if len(self.gui.shots) != 0:
(angle, power) = self.gui.shots.pop()
v = Conf.VMAX*power
angle = (angle/180.0)*math.pi
self.sim.balls[0].x_velocity = -v*math.sin(angle)/Conf.FPS
self.sim.balls[0].y_velocity = -v*math.cos(angle)/Conf.FPS
#check if player hit any pockets and update score
res = self.sim.next_iter()
if 0 in [p[0] for p in res]:
self.sim.add_ball(0, 0.5, 0.5, 0.0, 0.0)
self.scores[current_player] -= 1
for ball, pocket in res:
if ball != 0:
self.scores[current_player] += 1
self.gui.scores = self.scores
clock.tick(Conf.FPS)
示例14: new_interface
def new_interface(self, server, socket):
# todo: get tip first, then decide which checkpoint to use.
self.add_recent_server(server)
interface = Interface(server, socket)
interface.blockchain = None
interface.tip = 0
interface.mode = 'checkpoint'
self.interfaces[server] = interface
self.request_header(interface, self.get_checkpoint())
if server == self.default_server:
self.switch_to_interface(server)
self.notify('interfaces')
示例15: __init__
class Game:
def __init__(self, size, manager=None, player_one=None,
player_two=None, rnd=1, online=None):
self.size = size
self.manager = manager
if manager is not None:
self.manager.load_images(size)
self.interface = Interface(size,
self.manager.img_dict,
self.manager.options)
self.person = 1
self.online = online
self.end = False
self.message = None
self.players = {1-2*rnd: player_one, -1+2*rnd: player_two}
self.points = {-1: 2, 1: 2}
self.active = False
self.load = 0
self.field = [[0] * size for i in range(size)]
self.size = size
if manager is not None:
self.interface.set_information(self.points, self.person, self.players)
def is_end(self):
return self.end
def the_end(self):
self.end = True
def descend(self, x, y):
pass
def get_valid_path(self):
pass
def start(self):
pass
def event(self, events):
pass
def update(self, dt):
if not self.active:
if self.load <= PASSIVE:
self.load += dt
else:
self.active = True
def draw(self, display):
path = self.valid_path if (self.players[self.person] == Player.man) \
else {}
self.interface.draw(display, self.field, path)