Esempio n. 1
0
	def __del__(self):


		# close usb
		ret = ftdi1.usb_close(self.ftdic)
		if ret < 0:
			print('unable to close ftdi device: %d (%s)' % (ret, ftdi1.get_error_string(self.ftdic)))
		    

		print ('device closed')
		ftdi1.free(self.ftdic)
# read eeprom
eeprom_addr = 1
ret, eeprom_val = ftdi.read_eeprom_location(ftdic, eeprom_addr)
if (ret == 0):
    print('eeprom @ %d: 0x%04x\n' % (eeprom_addr, eeprom_val))

print('eeprom:')
ret = ftdi.read_eeprom(ftdic)
size = 128
ret, eeprom = ftdi.get_eeprom_buf(ftdic, size)
if (ret == 0):
    for i in range(size):
        if isinstance(eeprom[i], str):
            octet = ord(eeprom[i])  # python2
        else:
            octet = eeprom[i]  # python3
        sys.stdout.write('%02x ' % octet)
        if (i % 8 == 7):
            print('')
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)
Esempio n. 3
0
            os._exit(1)
        ftdics.append(ret)

    for ftdic, device in zip(ftdics, devices):
        print(device['path'])
        ret = ftdi.usb_open_bus_addr(ftdic, int(device['bus']),
                                     int(device['device']))
        if ret < 0:
            print('unable to open ftdi device: %d (%s)' %
                  (ret, ftdi.get_error_string(ftdic)))
            os._exit(1)

    if (sys.argv[1] == "bootload"):
        for ftdic in ftdics:
            setBOOT0(ftdic, 1)
        time.sleep(0.1)
        for ftdic in ftdics:
            reset(ftdic)
    elif (sys.argv[1] == "reset"):
        for ftdic in ftdics:
            setBOOT0(ftdic, 0)
        time.sleep(0.1)
        for ftdic in ftdics:
            reset(ftdic)
    else:
        print("Unrecognized command")

    for ftdic in ftdics:
        ftdi.usb_close(ftdic)
        ftdi.free(ftdic)
Esempio n. 4
0
#!/usr/bin/python3

import ftdi1
f = ftdi1.new()
ftdi1.usb_open(f, 0x0403, 0x6001)
ftdi1.set_bitmode(f, 1, 0)
ftdi1.write_data(f, bytes([0]))
ftdi1.write_data(f, bytes([1]))
ftdi1.usb_close(f)
Esempio n. 5
0
# read eeprom
eeprom_addr = 1
ret, eeprom_val = ftdi.read_eeprom_location(ftdic, eeprom_addr)
if (ret == 0):
    print('eeprom @ %d: 0x%04x\n' % (eeprom_addr, eeprom_val))

print('eeprom:')
ret = ftdi.read_eeprom(ftdic)
size = 128
ret, eeprom = ftdi.get_eeprom_buf(ftdic, size)
if (ret == 0):
    for i in range(size):
        octet = eeprom[i]
        if sys.version_info[0] < 3:  # python 2
            octet = ord(octet)
        sys.stdout.write('%02x ' % octet)
        if (i % 8 == 7):
            print('')
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)