Ejemplo n.º 1
0
def main():
    """Main program"""
    restart = True
    ftdic = ftdi.new()
    serial = None

    if len(sys.argv) > 1:                                                                                                                   
        serial = sys.argv[1]

    ret = ftdi.usb_open_desc(ftdic, 0x0403, 0x6001, None, serial)
    if ret < 0:
        print("ftdi.usb_open(): %d" % ret, file=sys.stderr)
        sys.exit(1)

    ret = ftdi.read_eeprom(ftdic)
    if ret < 0:
        print("ftdi.read_eeprom(): %d" % ret, file=sys.stderr)
        sys.exit(1)

    ret = ftdi.eeprom_decode(ftdic, True)
    if ret < 0:
        print("ftdi.eeprom_decode(): %d" % ret, file=sys.stderr)
        sys.exit(1)
    print()

    set_eeprom_value(ftdic, ftdi.CBUS_FUNCTION_0, ftdi.CBUS_TXLED)
    set_eeprom_value(ftdic, ftdi.CBUS_FUNCTION_1, ftdi.CBUS_RXLED)
    set_eeprom_value(ftdic, ftdi.CBUS_FUNCTION_2, ftdi.CBUS_IOMODE)
    set_eeprom_value(ftdic, ftdi.CBUS_FUNCTION_3, ftdi.CBUS_IOMODE)

    ret = ftdi.eeprom_build(ftdic);
    if ret < 0:
        print("ftdi.eeprom_build(): %d" % ret, file=sys.stderr)
        sys.exit(1)

    print("New EEPROM settings:")
    ret = ftdi.eeprom_decode(ftdic, True)
    if ret < 0:
        print("ftdi.eeprom_decode(): %d" % ret, file=sys.stderr)
        sys.exit(1)

    ret = ftdi.write_eeprom(ftdic);
    if ret < 0:
        print("ftdi.write_eeprom(): %d" % ret, file=sys.stderr)
        sys.exit(1)

    ftdi.free(ftdic)
Ejemplo n.º 2
0
    if (ret == 0):
        print('pins: %02x' % ord(pins[0]))

# read chip id
ret, chipid = ftdi.read_chipid(ftdic)
if (ret == 0):
    print('chip id: %X\n' % chipid)

# 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)
Ejemplo n.º 3
0

# read chip id
ret, chipid = ftdi.read_chipid(ftdic)
if (ret == 0):
    print('chip id: %x\n' % chipid)


# 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: