def open_ftdi(): if (ftdi.ftdi_init(ftdic) < 0) : print "ftdi_init fehlgeschlagen" exit(-1) else: print "ftdi_init geklappt" #Öffne FTDI-Chip FT232R - evt. andere Nummern eintragen! #Tut auch mit FT245BL ret = ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001) if (ret) < 0: print "Konnte Gerät nicht öffnen:" + ret + "(" + \ ftdi.ftdi_get_error_string(ftdic) + ")" exit(-1) else: print "Gerät erfolgreich geöffnet" #Bitbag mit DTR, RX und TX beginnen #2. Argument macht die Pins D0-D7 ansprechbar #ftdi.ftdi_enable_bitbang(ftdic, D[0]|D[1]|D[2]|D[3]|D[4]|D[5]|D[6]|D[7] ) ftdi.ftdi_enable_bitbang(ftdic,0x1 | 0x2| 0x4| 0x8| 0x10| 0x20| 0x40| 0x80) #Am Anfang ausschalten ftdi.ftdi_write_data(ftdic, chr(255), 1)
def refresh(): return redirect(url_for('index')) def run_http(): app.run(host='0.0.0.0') # run the HTTP server in a background thread thread.start_new_thread(run_http, ()) # initialize to the ftdi device ftdic = ftdi.ftdi_context() ftdi.ftdi_init(ftdic) ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001) ftdi.ftdi_enable_bitbang(ftdic, RXT | CTS) while True: result = " " ftdi.ftdi_read_pins(ftdic, result) was_closed = is_closed is_closed = 0 != ord(result) & RXT if was_closed != is_closed: with open('status', 'w') as f: \ f.write ('closed' if is_closed else 'open') LOG.info("Full: %s\t Masked: %s\t Is Closed: %s\t To Write: %s", \ hex(ord(result)), hex(ord(result) & RXT),
@app.route('/refresh/') def refresh(): return redirect(url_for('index')) def run_http(): app.run(host='0.0.0.0') # run the HTTP server in a background thread thread.start_new_thread(run_http, ()) # initialize to the ftdi device ftdic = ftdi.ftdi_context() ftdi.ftdi_init(ftdic) ftdi.ftdi_usb_open(ftdic, 0x0403, 0x6001) ftdi.ftdi_enable_bitbang(ftdic, RXT | CTS) while True: result = " " ftdi.ftdi_read_pins(ftdic, result) was_closed = is_closed is_closed = 0 != ord(result) & RXT if was_closed != is_closed: with open ('status', 'w') as f: \ f.write ('closed' if is_closed else 'open') LOG.info("Full: %s\t Masked: %s\t Is Closed: %s\t To Write: %s", \ hex(ord(result)), hex(ord(result) & RXT),