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


Python SerialManager.close方法代码示例

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


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

示例1: run_with_callback

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
def run_with_callback(host):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    handler = default_app()
    server = wsgiref.simple_server.make_server(host, NETWORK_PORT, handler)
    server.timeout = 0.01
    server.quiet = True
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "
    print "http://%s:%d/      (local)" % ("127.0.0.1", NETWORK_PORT)
    if host == "":
        print "http://%s:%d/   (public)" % (socket.gethostbyname(socket.gethostname()), NETWORK_PORT)
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"
    print
    try:
        webbrowser.open_new_tab("http://127.0.0.1:" + str(NETWORK_PORT))
    except webbrowser.Error:
        print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    while 1:
        try:
            SerialManager.send_queue_as_ready()
            server.handle_request()
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    SerialManager.close()
开发者ID:cheewee2000,项目名称:LasaurApp,代码行数:33,代码来源:app.py

示例2: run_with_callback

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
def run_with_callback(host, port=4444, timeout=0.01):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    handler = default_app()
    server = wsgiref.simple_server.make_server(host, port, handler)
    server.timeout = timeout
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "    
    print "http://%s:%d/      (local)" % ('127.0.0.1', port)    
    if host == '':
        print "http://%s:%d/   (public)" % (socket.gethostbyname(socket.gethostname()), port)
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"    
    print
    while 1:
        try:
            SerialManager.send_queue_as_ready()
            server.handle_request()
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    SerialManager.close()
开发者ID:darthrake,项目名称:LasaurApp,代码行数:27,代码来源:app.py

示例3: flash_firmware_handler

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
def flash_firmware_handler():
    if SerialManager.is_connected():
        SerialManager.close()
    global SERIAL_PORT, GUESS_PREFIX
    if not SERIAL_PORT:
        SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX)        
    flash_upload(SERIAL_PORT, resources_dir())
    return '<h2>flashing finished!</h2> Check Log window for possible errors.<br><a href="/">return</a>'
开发者ID:DingFabrik,项目名称:laserapp,代码行数:10,代码来源:app.py

示例4: run_with_callback

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
def run_with_callback(host, port, rfidreader, logger, powertimer):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    debug(True)
    handler = default_app()
    handler.catchall = False
    handler.rfidreader = rfidreader
    handler.logger = logger
    handler.powertimer = powertimer
    server = make_server(host, port, handler, handler_class=HackedWSGIRequestHandler)
    server.timeout = 0.01
    #server.quiet = True
    print "Persistent storage root is: " + storage_dir()
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "
    print "http://%s:%d/      (local)" % ('127.0.0.1', port)
    # if host == '':
    #     try:
    #         print "http://%s:%d/   (public)" % (socket.gethostbyname(socket.gethostname()), port)
    #     except socket.gaierror:
    #         # print "http://beaglebone.local:4444/      (public)"
    #         pass
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"
    print
    # auto-connect on startup
    global SERIAL_PORT
    if not SERIAL_PORT:
        SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
    SerialManager.connect(SERIAL_PORT, BITSPERSECOND)
    # open web-browser
    try:
        webbrowser.open_new_tab('http://127.0.0.1:'+str(port))
        pass
    except webbrowser.Error:
        print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    server.timeout = 0
    while 1:
        try:
            SerialManager.send_queue_as_ready()
            server.handle_request()
            time.sleep(0.0004)
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    SerialManager.close()
开发者ID:bullestock,项目名称:LasaurApp,代码行数:52,代码来源:app.py

示例5: flash_firmware_handler

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
def flash_firmware_handler(firmware_file=FIRMWARE):
    global user_approved
    global user_admin
    if not user_approved and user_admin:
        return 'Access denied'
    logger.log(current_user, 'Flashing ATMEGA')
    return_code = 1
    if SerialManager.is_connected():
        SerialManager.close()
    # get serial port by url argument
    # e.g: /flash_firmware?port=COM3
    if 'port' in request.GET.keys():
        serial_port = request.GET['port']
        if serial_port[:3] == "COM" or serial_port[:4] == "tty.":
            SERIAL_PORT = serial_port
    # get serial port by enumeration method
    # currenty this works on windows only for updating the firmware
    if not SERIAL_PORT:
        SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
    # resort to brute force methode
    # find available com ports and try them all
    if not SERIAL_PORT:
        comport_list = SerialManager.list_devices(BITSPERSECOND)
        for port in comport_list:
            print "Trying com port: " + port
            return_code = flash_upload(port, resources_dir(), firmware_file, HARDWARE)
            if return_code == 0:
                print "Success with com port: " + port
                SERIAL_PORT = port
                break
    else:
        return_code = flash_upload(SERIAL_PORT, resources_dir(), firmware_file, HARDWARE)
    ret = []
    ret.append('Using com port: %s<br>' % (SERIAL_PORT))
    ret.append('Using firmware: %s<br>' % (firmware_file))
    if return_code == 0:
        print "SUCCESS: Arduino appears to be flashed."
        ret.append('<h2>Successfully Flashed!</h2><br>')
        ret.append('<a href="/">return</a>')
        return ''.join(ret)
    else:
        print "ERROR: Failed to flash Arduino."
        ret.append('<h2>Flashing Failed!</h2> Check terminal window for possible errors. ')
        ret.append('Most likely LasaurApp could not find the right serial port.')
        ret.append('<br><a href="/flash_firmware/'+firmware_file+'">try again</a> or <a href="/">return</a><br><br>')
        if os.name != 'posix':
            ret. append('If you know the COM ports the Arduino is connected to you can specifically select it here:')
            for i in range(1,13):
                ret. append('<br><a href="/flash_firmware?port=COM%s">COM%s</a>' % (i, i))
        return ''.join(ret)
开发者ID:bullestock,项目名称:LasaurApp,代码行数:52,代码来源:app.py

示例6: serial_handler

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
def serial_handler(connect):
    if connect == '1':
        # print 'js is asking to connect serial'
        if not SerialManager.is_connected():
            try:
                global SERIAL_PORT, BITSPERSECOND, GUESS_PREFIX
                if not SERIAL_PORT:
                    SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
                SerialManager.connect(SERIAL_PORT, BITSPERSECOND)
                ret = "Serial connected to %s:%d." % (SERIAL_PORT, BITSPERSECOND)  + '<br>'
                time.sleep(1.0) # allow some time to receive a prompt/welcome
                SerialManager.flush_input()
                SerialManager.flush_output()
                return ret
            except serial.SerialException:
                SERIAL_PORT = None
                print "Failed to connect to serial."
                return ""
    elif connect == '0':
        # print 'js is asking to close serial'
        if SerialManager.is_connected():
            if SerialManager.close(): return "1"
            else: return ""
    elif connect == "2":
        # print 'js is asking if serial connected'
        if SerialManager.is_connected(): return "1"
        else: return ""
    else:
        print 'ambigious connect request from js: ' + connect
        return ""
开发者ID:art103,项目名称:LasaurApp,代码行数:32,代码来源:app.py

示例7: flash_firmware_handler

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
def flash_firmware_handler():
    global SERIAL_PORT, GUESS_PREFIX
    return_code = 1
    if SerialManager.is_connected():
        SerialManager.close()
    # get serial port by url argument
    # e.g: /flash_firmware?port=COM3
    if "port" in request.GET.keys():
        serial_port = request.GET["port"]
        if serial_port[:3] == "COM" or serial_port[:4] == "tty.":
            SERIAL_PORT = serial_port
    # get serial port by enumeration method
    # currenty this works on windows only for updating the firmware
    if not SERIAL_PORT:
        SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
    # resort to brute force methode
    # find available com ports and try them all
    if not SERIAL_PORT:
        comport_list = SerialManager.list_devices(BITSPERSECOND)
        for port in comport_list:
            print "Trying com port: " + port
            return_code = flash_upload(port, resources_dir())
            if return_code == 0:
                print "Success with com port: " + port
                SERIAL_PORT = port
                break
    else:
        return_code = flash_upload(SERIAL_PORT, resources_dir())
    ret = []
    ret.append("Using com port: %s<br>" % (SERIAL_PORT))
    if return_code == 0:
        print "SUCCESS: Arduino appears to be flashed."
        ret.append("<h2>Successfully Flashed!</h2><br>")
        ret.append('<a href="/">return</a>')
        return "".join(ret)
    else:
        SERIAL_PORT = None
        print "ERROR: Failed to flash Arduino."
        ret.append("<h2>Flashing Failed!</h2> Check Log window for possible errors. ")
        ret.append('Most likely LasaurApp could not find the right serial port.<br><a href="/">return</a><br><br>')
        if os.name != "posix":
            ret.append("If you know the COM ports the Arduino is connected to you can specifically select it here:")
            for i in range(1, 13):
                ret.append('<br><a href="/flash_firmware?port=COM%s">COM%s</a>' % (i, i))
        return "".join(ret)
开发者ID:cheewee2000,项目名称:LasaurApp,代码行数:47,代码来源:app.py

示例8: run_with_callback

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
def run_with_callback(host, port):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    handler = default_app()
    server = make_server(host, port, handler, handler_class=HackedWSGIRequestHandler)
    if CERTSDIR:
      server.socket = ssl.wrap_socket(server.socket,
        keyfile=KEYFILE,
        certfile=CERTSFILE,
        server_side=True,
        cert_reqs=ssl.CERT_REQUIRED,
        ca_certs=CA_CERTSFILE)
      loadAccounts()
      server.verify_request = verify_request
    server.timeout = 0.01
    server.quiet = True
    print "Persistent storage root is: " + storage_dir()
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "
    if CERTSDIR:
      print "https://%s:%d/" % (COMMON_NAME, port)
    elif COMMON_NAME:
      print "http://%s:%d/" % (COMMON_NAME, port)
    else:
      print "http://%s:%d/" % ('127.0.0.1', port)
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"
    print
    # auto-connect on startup
    global SERIAL_PORT
    if not SERIAL_PORT:
        SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
    SerialManager.connect(SERIAL_PORT, BITSPERSECOND)
# I:Mega Start
    time.sleep(1.0)
# I:Mega End
#    # open web-browser
#    try:
#        webbrowser.open_new_tab('http://127.0.0.1:'+str(port))
#        pass
#    except webbrowser.Error:
#        print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    server.timeout = 0
    lastPowerStatus = 0
    powerStateChange = 0
    while 1:
        try:
            serial_handler('1')
            SerialManager.send_queue_as_ready()
            server.handle_request()
            if HARDWARE == 'raspberrypi':
              powerStatus = RPiPowerControl.interval_check()
              if powerStatus != lastPowerStatus:
                powerStateChange = 1
                lastPowerStatus = powerStatus
            if powerStateChange:
              powerStateChange = checkStatus()
            time.sleep(0.0004)
        except KeyboardInterrupt:
            if HARDWARE == 'raspberrypi':
              RPiPowerControl.gpio_cleanup()
            break
        except:
            import traceback
            traceback.print_exc()
            break
    print "\nShutting down..."
    if redirect_pid:
      os.kill(redirect_pid, signal.SIGTERM)
    SerialManager.close()
开发者ID:mnakada,项目名称:SmartLaserCO2,代码行数:76,代码来源:app.py

示例9: EventWrapper

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
ev1 = EventWrapper(e1, marm.calculate_timeout(115200))
ev2 = EventWrapper(e2, marm.calculate_timeout(115200) + v2dt.calculate_timeout(115200))

sertest = AutoTimer(period=1, events=[ev0,ev1,ev2])

if manager.open_port('0', 115200):
	sertest.start()

try:
	while True:

		if dataflag:
			print(marm.voltages)
			print(marm.test)
			dataflag = False

		#user_input = raw_input()

			'''
		if manager.open_port(user_input, 115200):
			sertest.start()
		else:
			if user_input == 'q' or user_input == 'quit':
				sertest.stop()
				manager.close()
				quit()'''
except KeyboardInterrupt:
	print('Closing threads, serial port, and quitting...')
	sertest.kill()
	manager.close()
	quit(0)
开发者ID:openrobotics,项目名称:serial_simulator,代码行数:33,代码来源:S3P_master.py

示例10: Utility

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
from Servo import *
from data_structures import mini_arm as marm

utils = Utility()
alive = True

def quit():
	global alive
	alive = False

manager1 = SerialManager()
print 'Ports available'
manager1.list_ports()
print 'Select Dynamixel port'
user_input = utils.getch()

if manager1.open_port(user_input, 57600):
	
	serv_2 = Robotis_Servo(manager1, 1)
	print 'Setting up Dynamixel 2'
	
	print 'Dynamixel 2 at ' + str(serv_2.read_angle())

	while(alive):
		serv_2.move_angle(1, 1.5, blocking=False)
		time.sleep(1)
		serv_2.move_angle(2, 1.5, blocking=False)
		time.sleep(1)

manager1.close()
开发者ID:openrobotics,项目名称:serial_simulator,代码行数:32,代码来源:head_controller.py

示例11: SlideshowManager

# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import close [as 别名]
slideRenderer = SlideshowManager(config, screen)
slideRenderer.load_default_slideshow()

serialManager = SerialManager(port="/dev/ttyAMA0", baudrate=9600)

done = False

while not done:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                done = True

    serialManager.pool()
    data = serialManager.process()
    if data:
        process_input(slideRenderer, config, data)

    slideRenderer.tick()

    time.sleep(0.05)


serialManager.close()
slideRenderer.destroy()
pygame.quit()
开发者ID:hansihe,项目名称:PySlides,代码行数:31,代码来源:run.py


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