• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python serial_manager.SerialManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: run_with_callback

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,代码行数:25,代码来源:app.py


示例2: run_with_callback

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,代码行数:31,代码来源:app.py


示例3: job_submit_handler

def job_submit_handler():
    job_data = request.forms.get('job_data')
    if job_data and SerialManager.is_connected():
        SerialManager.queue_gcode(job_data)
        return "__ok__"
    else:
        return "serial disconnected"
开发者ID:art103,项目名称:LasaurApp,代码行数:7,代码来源:app.py


示例4: gcode_handler

def gcode_handler(gcode_line):
    if SerialManager.is_connected():    
        print gcode_line
        SerialManager.queue_for_sending(gcode_line)
        return "Queued for sending."
    else:
        return ""
开发者ID:darthrake,项目名称:LasaurApp,代码行数:7,代码来源:app.py


示例5: checkErr

def checkErr(* flag):
    for index in range(len(flag)):
        if flag[index] != 0:
            SerialManager.read_existing() #clear rx_buffer
            if SerialManager.write('O000'+'\r'):
                relayStatus=SerialManager.read_to('\r')
                print 'relay status is:',relayStatus
开发者ID:oeshine,项目名称:batterySimulator,代码行数:7,代码来源:readData.py


示例6: serial_handler

def serial_handler(connect):
    if connect == '1':
        print 'js is asking to connect serial'      
        if not SerialManager.is_connected():
            try:
                global SERIAL_PORT, 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:
                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:darthrake,项目名称:LasaurApp,代码行数:27,代码来源:app.py


示例7: flash_firmware_handler

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,代码行数:8,代码来源:app.py


示例8: sendCommand

def sendCommand(command):
	
	#clear rx_buffer
    SerialManager.read_existing() 
	
    if SerialManager.write(command + '\r'):
        return SerialManager.read_to('\r')
    else:
        return 'error'
开发者ID:oeshine,项目名称:batterySimulator,代码行数:9,代码来源:BMS_simulator.py


示例9: gcode_submit_handler

def gcode_submit_handler():
    gcode_program = request.forms.get('gcode_program')
    if gcode_program and SerialManager.is_connected():
        lines = gcode_program.split('\n')
        print "Adding to queue %s lines" % len(lines)
        for line in lines:
            SerialManager.queue_gcode_line(line)
        return "__ok__"
    else:
        return "serial disconnected"
开发者ID:TyberiusPrime,项目名称:LasaurApp,代码行数:10,代码来源:app.py


示例10: gcode_submit_handler

def gcode_submit_handler():
    gcode_program = request.forms.get("gcode_program")
    if gcode_program and SerialManager.is_connected():
        lines = gcode_program.split("\n")
        print "Adding to queue %s lines" % len(lines)
        for line in lines:
            SerialManager.queue_for_sending(line)
        return "Queued for sending."
    else:
        return ""
开发者ID:cheewee2000,项目名称:LasaurApp,代码行数:10,代码来源:app.py


示例11: job_submit_handler

def job_submit_handler():
    job_data = request.forms.get('job_data')
    if job_data and SerialManager.is_connected():
        lines = job_data.split('\n')
        print "Adding to queue %s lines" % len(lines)
        for line in lines:
            SerialManager.queue_gcode_line(line)
        return "__ok__"
    else:
        return "serial disconnected"
开发者ID:ArtisansAsylum,项目名称:LasaurApp,代码行数:10,代码来源:app.py


示例12: get_status

def get_status():
    if args.raspberrypi:
        powertimer.reset()
    status = copy.deepcopy(SerialManager.get_hardware_status())
    status['serial_connected'] = SerialManager.is_connected()
    print "Connected: %d" % SerialManager.is_connected()
    status['lasaurapp_version'] = VERSION
    global user_approved
    global user_admin
    global current_user
    if args.disable_rfid:
        return json.dumps(status)
    card_id = reader.getid()
    print "Card ID %s" % card_id
    username = ''
    global current_cardid
    if len(card_id) == 0:
        print "No card inserted"
        username = 'No card inserted'
        user_approved = False
        if current_user != '':
            logger.log(current_user, 'Card removed')
        current_user = ''
    elif len(card_id) == 12:
        if not card_id in card_data:
            print "Card not found"
            username = 'Unknown card'
            user_approved = False
            if card_id != current_cardid:
                logger.log(card_id, 'Unknown card')
        else:
            print "Card found"
            data = card_data[card_id]
            username = data['name']
            if data['approved']:
                user_approved = True
            else:
                user_approved = False
            if data['admin']:
                user_admin = True
            else:
                user_admin = False
            if current_user == '':
                logger.log(username, 'Card inserted')
            current_user = username
            print "Approved: %s" % user_approved
        current_cardid = card_id
    else:
        print "Bad length: %d" % len(card_id)
    status['username'] = username
    global shutdown_msg
    status['shutdown_msg'] = shutdown_msg
    shutdown_msg = ''
    return json.dumps(status)
开发者ID:bullestock,项目名称:LasaurApp,代码行数:54,代码来源:app.py


示例13: job_submit_handler

def job_submit_handler():
    job_data = request.forms.get('gcode_program')
    if not job_data:
        return HTTPResponse(status=400)

    if SerialManager.is_connected():
        lines = job_data.split('\n')
        print "Adding to queue %s lines" % len(lines)
        for line in lines:
            SerialManager.queue_gcode_line(line)
        return "__ok__"
    else:
        return HTTPResponse(status=502, body="serial disconnected")
开发者ID:Protospace,项目名称:LasaurApp,代码行数:13,代码来源:app.py


示例14: job_submit_handler

def job_submit_handler():
    job_data = request.forms.get('job_data')
    global user_approved
    global current_user
    if not user_approved and job_data[0] != "!":
        print 'User not approved'
        return 'Access denied'
    if job_data and SerialManager.is_connected():
        SerialManager.queue_gcode(job_data)
        logger.log(current_user, 'Run job: '+re.sub('[\s+]', ' ', job_data)[:50])
        return "__ok__"
    else:
        return "serial disconnected"
开发者ID:bullestock,项目名称:LasaurApp,代码行数:13,代码来源:app.py


示例15: flash_firmware_handler

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,代码行数:50,代码来源:app.py


示例16: set_pause

def set_pause(flag):
    # returns pause status
    if flag == '1':
        if SerialManager.set_pause(True):
            print "pausing ..."
            return '1'
        else:
            return '0'
    elif flag == '0':
        print "resuming ..."
        if SerialManager.set_pause(False):
            return '1'
        else:
            return '0'
开发者ID:art103,项目名称:LasaurApp,代码行数:14,代码来源:app.py


示例17: set_pause

def set_pause(flag):
    if flag == '1':
        if SerialManager.set_pause(True):
            print "pausing ..."
            return '1'
        else:
            print "warn: nothing to pause"
            return ''
    elif flag == '0':
        print "resuming ..."
        if SerialManager.set_pause(False):
            return '1'
        else:
            return ''
开发者ID:TyberiusPrime,项目名称:LasaurApp,代码行数:14,代码来源:app.py


示例18: get_status

def get_status():
    status = copy.deepcopy(SerialManager.get_hardware_status())
    status['serial_connected'] = SerialManager.is_connected()
    if HARDWARE == 'raspberrypi':
      status['power'] = RPiPowerControl.get_power_status()
      status['assist_air'] = RPiPowerControl.get_assist_air_status()
      RPiPowerControl.set_process_status(status['serial_connected'] and not status['ready'])
    else:
      status['power'] = 1;
      status['assist_air'] = 1;
    status['lasaurapp_version'] = VERSION
    status['admin'] = admin_check()
    status['user'] = accessUser
    status['accounts'] = accountsTable
    status['statistics'] = statistics
    return status
开发者ID:mnakada,项目名称:SmartLaserCO2,代码行数:16,代码来源:app.py


示例19: checkStatus

def checkStatus():
    global lastCheck
    checkFlag = 1
    now = time.time()
    if now - lastCheck < 1.0:
      return checkFlag
    status = get_status()
    if (int(status['power']) > 0) and not status['door_open'] and status['ready'] and status['serial_connected']:
      SerialManager.queue_gcode('!\n')
      time.sleep(1.0)
      SerialManager.queue_gcode('~\nG90\nG30\n')
      checkFlag = 0
    if (int(status['power']) == 0):
      checkFlag = 0
    lastCheck = now
    return checkFlag
开发者ID:mnakada,项目名称:SmartLaserCO2,代码行数:16,代码来源:app.py


示例20: set_pause

def set_pause(flag):
    global user_approved
    if not user_approved:
        return 'Access denied'
    # returns pause status
    if flag == '1':
        if SerialManager.set_pause(True):
            print "pausing ..."
            return '1'
        else:
            return '0'
    elif flag == '0':
        print "resuming ..."
        if SerialManager.set_pause(False):
            return '1'
        else:
            return '0'
开发者ID:bullestock,项目名称:LasaurApp,代码行数:17,代码来源:app.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python serializable.serialize_object函数代码示例发布时间:2022-05-27
下一篇:
Python list_ports.comports函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap