Example #1
0
def serial_handler(connect):
    if connect == "1" and not serial_manager.is_connected():
        print "js is asking to connect serial"
        try:
            global arduino_port, baudrate
            serial_manager.connect(ARDUINO_PORT, BITSPERSECOND)
            ret = "Serial connected to %s:%d." % (ARDUINO_PORT, BITSPERSECOND) + "<br>"
            time.sleep(1.0)  # allow some time to receive a prompt/welcome
            resp = serial_manager.get_responses("<br>")
            if resp == "":
                resp = ret
            return resp
        except serial.SerialException:
            print "Failed to connect to serial."
            return ""
    elif connect == "0" and serial_manager.is_connected():
        print "js is asking to closer serial"
        if serial_manager.close():
            return "1"
        else:
            return ""
    elif connect == "2":
        print "js is asking if serial connected"
        if serial_manager.is_connected():
            return "1"
        else:
            return ""
    else:
        print "got neither: " + connect
        return ""
Example #2
0
def serial_handler(connect):
    if connect == '1' and not serial_manager.is_connected():
        print 'js is asking to connect serial'
        try:
            global arduino_port, baudrate
            serial_manager.connect(ARDUINO_PORT, BITSPERSECOND)
            ret = "Serial connected to %s:%d." % (ARDUINO_PORT,
                                                  BITSPERSECOND) + '<br>'
            time.sleep(1.0)  # allow some time to receive a prompt/welcome
            resp = serial_manager.get_responses('<br>')
            if resp == "": resp = ret
            return resp
        except serial.SerialException:
            print "Failed to connect to serial."
            return ""
    elif connect == '0' and serial_manager.is_connected():
        print 'js is asking to closer serial'
        if serial_manager.close(): return "1"
        else: return ""
    elif connect == "2":
        print 'js is asking if serial connected'
        if serial_manager.is_connected(): return "1"
        else: return ""
    else:
        print 'got neither: ' + connect
        return ""
Example #3
0
def run_with_callback(host="127.0.0.1", 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 "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: http://%s:%d/" % (host, port)
    print "Use Ctrl-C to quit."
    print
    while 1:
        try:
            serial_manager.send_queue_as_ready()
            server.handle_request()
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    serial_manager.close()
Example #4
0
def run_with_callback(host='127.0.0.1', 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 "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: http://%s:%d/" % (host, port)
    print "Use Ctrl-C to quit."
    print
    while 1:
        try:
            serial_manager.send_queue_as_ready()
            server.handle_request()
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    serial_manager.close()