if ret < 0: print('Cannot enable bitbang') os._exit(1) #for i in range( 8 ): val = 0x0 print('enabling bit #%d (0x%02x)' % (i, val)) ftdi.write_data(ftdic, chr(val)) time.sleep(5.5) val = 0x2 print('enabling bit #%d (0x%02x)' % (i, val)) ftdi.write_data(ftdic, chr(val)) time.sleep(5.5) #ftdi.write_data( ftdic, chr(0x00)) time.sleep(0.2) ftdi.disable_bitbang(ftdic) print('') # close usb ret = ftdi.usb_close(ftdic) if ret < 0: print('unable to close ftdi device: %d (%s)' % (ret, ftdi.get_error_string(ftdic))) os._exit(1) print('device closed') ftdi.free(ftdic)
def close_comms(self): print ftdi.disable_bitbang(self.ftdic) print ftdi.usb_close(self.ftdic)
ret = ftdi.set_bitmode(ftdic, 0xff, ftdi.BITMODE_BITBANG) if ret < 0: print('Cannot enable bitbang') os._exit(1) print('turning everything on') ftdi.write_data(ftdic, chr(0xff), 1) time.sleep(1) print('turning everything off\n') ftdi.write_data(ftdic, chr(0x00), 1) time.sleep(1) for i in range(8): val = 2 ** i print('enabling bit #%d (0x%02x)' % (i, val)) ftdi.write_data(ftdic, chr(val), 1) time.sleep(1) ftdi.disable_bitbang(ftdic) print('') # read pins ret, pins = ftdi.read_pins(ftdic) if (ret == 0): if sys.version_info[0] < 3: # python 2 pins = ord(pins) else: pins = pins[0] print('pins: 0x%x' % pins) # read chip id ret, chipid = ftdi.read_chipid(ftdic)
## Loop grabbing data and storing in array print 'Gathering data. Press Ctrl-C to quit.' output = [] try: while True: # Sleep based on baudrate time.sleep(1.0/BAUD) # Read the input and store to array ret, pins = ftdi.read_pins(ftdictx) # reads pins directly, needs sleep time to be exact output.append(pins) #ret, databuf = ftdi.read_data(ftdictx) # reads the data buffer, no need for exact timing (just fast enough to keep buffer from overflowing) #output.extend(databuf) except KeyboardInterrupt: pass ## Write captured data to file with open("output.bin", "wb") as outfile: writedata = bytearray(output) outfile.write(writedata) ## Cleanup: free devlist, reset bitmode, close usb, etc ftdi.list_free(devlist) ftdi.disable_bitbang(ftdictx) ftdi.set_bitmode(ftdictx, 0x00, ftdi.BITMODE_RESET) ret = ftdi.usb_close( ftdictx ) if ret < 0: print( 'unable to close ftdi device: %d (%s)' % ( ret, ftdi.get_error_string( ftdictx ) ) ) os._exit( 1 ) print ('device closed') ftdi.free( ftdictx )