Esempio n. 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 ""
Esempio n. 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 ""
Esempio n. 3
0
def gcode_handler(gcode_line):
    if serial_manager.is_connected():
        print gcode_line
        serial_manager.queue_for_sending(gcode_line + "\n")
        return "Queued for sending."
    else:
        return ""
Esempio n. 4
0
def gcode_handler(gcode_line):
    if serial_manager.is_connected():
        print gcode_line
        serial_manager.queue_for_sending(gcode_line + '\n')
        return "Queued for sending."
    else:
        return ""
Esempio n. 5
0
def gcode_handler_submit():
    gcode_program = request.forms.get("gcode_program")
    if gcode_program and serial_manager.is_connected():
        print gcode_program
        lines = gcode_program.split("\n")
        for line in lines:
            serial_manager.queue_for_sending(line + "\n")
        return "Queued for sending."
    else:
        return ""
Esempio n. 6
0
def gcode_handler_submit():
    gcode_program = request.forms.get('gcode_program')
    if gcode_program and serial_manager.is_connected():
        print gcode_program
        lines = gcode_program.split('\n')
        for line in lines:
            serial_manager.queue_for_sending(line + '\n')
        return "Queued for sending."
    else:
        return ""