示例#1
0
 def __init__(self, opts):
     import ft232
     flags = [0, 0, 0, 0, 0, 0, 0, 0]
     reset_pin = 5
     host_pin = 3
     serial = opts.ft232_serial[0]
     self.sp = ft232.Ft232(serial, baudrate=115200)
     self.sp.cbus_setup(mask=0xf, init=0xf)
     self.flags = flags
     self.reset_pin = reset_pin
     self.host_pin = host_pin
示例#2
0
def main():
    inifile = configparser.ConfigParser()
    inifile.read('bootloader.ini')
    comport = inifile.get('settings', 'comport')

    i = 1
    boot_mode = 3
    while i < len(sys.argv):  # in range(1, len(sys.argv)):
        arg2 = sys.argv[i].strip()
        if 0 <= arg2.find('--port'):
            comport = sys.argv[i + 1].strip()
            i += 2
            continue
        if 0 <= arg2.find('--mode'):
            boot_mode = int(sys.argv[i + 1].strip())
            continue
        i += 1

    serial_number = get_serialnumber(comport)
    if None == serial_number:
        print('serial_number not found')
        return
    print('target is {}'.format(serial_number))
    sp = []
    try:
        sp = ft232.Ft232(serial_number, baudrate=115200)
    except ft232.Ft232Exception:
        print("Unable to open the ftdi device: %s" % serial_number)
        sys.exit(1)

    reboot(sp, boot_mode)

    # You may use sp as you would a Serial object
    # sp.write(b"Hello World!\n")
    # resp = sp.read(100)

    # If you want to use the CBUS pins, you enable them with cbus_setup
    # 'mask' is a bitmask which specifies which pins to enable
    # 'init' is a bitmask for the initial value for each pin
    # while True:
    # 	sp.cbus_write(1)
    # 	time.sleep(0.1)
    # 	sp.cbus_write(2)
    # 	time.sleep(0.1)
    # 	sp.cbus_write(4)
    # 	time.sleep(0.1)
    # 	sp.cbus_write(8)
    # 	time.sleep(0.1)

    # Print the current value of all setup pins
    print("CBUS: %s" % sp.cbus_read())
示例#3
0
def main():
	# serial_number = "DJ5LV1RQ"
	serial_number = "DJ61E92G"
	serial_number = "DN0556IZ"  # IF314_USBIF
	serial_number = "DN6KHMZE"  # IF314_USBIF
	sp = []
	try:
		sp = ft232.Ft232(serial_number, baudrate=115200)
	except ft232.Ft232Exception:
		print("Unable to open the ftdi device: %s" % serial_number)
		sys.exit(1)

	# You may use sp as you would a Serial object
	# sp.write(b"Hello World!\n")
	# resp = sp.read(100)

	# If you want to use the CBUS pins, you enable them with cbus_setup
	# 'mask' is a bitmask which specifies which pins to enable
	# 'init' is a bitmask for the initial value for each pin
	sp.cbus_setup(mask=15, init=0)

	# Change the current value of all setup pins
	for i in range(1000):
		sp.cbus_write(1)
		time.sleep(0.1)
		sp.cbus_write(2)
		time.sleep(0.1)
		sp.cbus_write(4)
		time.sleep(0.1)
		sp.cbus_write(8)
		time.sleep(0.1)
	return
	# while True:
	# 	sp.cbus_write(1)
	# 	time.sleep(0.1)
	# 	sp.cbus_write(2)
	# 	time.sleep(0.1)
	# 	sp.cbus_write(4)
	# 	time.sleep(0.1)
	# 	sp.cbus_write(8)
	# 	time.sleep(0.1)
	# break

	# Print the current value of all setup pins
	print("CBUS: %s" % sp.cbus_read())
 def __init__(self, conn, timeout=10., term_write=None, term_read=None, open_retry_times=3):
     conn_dict=self.combine_serial_conn(conn,self._default_conn)
     if term_write is None:
         term_write="\r\n"
     if term_read is None:
         term_read="\n"
     if isinstance(term_read,anystring):
         term_read=[term_read]
     IDeviceBackend.__init__(self,conn_dict.copy(),term_write=term_write,term_read=term_read)
     port=conn_dict.pop("port")
     try:
         self.instr=ft232.Ft232(port,**conn_dict)
         self._operation_cooldown=self._default_operation_cooldown
         self._opened_stack=0
         self._open_retry_times=open_retry_times
         self.cooldown()
         self.set_timeout(timeout)
     except self.Error as e:
         raise self.BackendOpenError(e)
    def __init__(self, terminal, opts):
        # Lazy-init FT232.
        # On windows systems, if D2XX drivers are not installed
        try:
            import ft232
        except:
            print("ERROR: Failed to load pyft232")
            print("ERROR: Is D2XX/libftdi installed?")
            sys.exit(1)
        # HACK: On some linux systems (debian buster) we can't free libftdi context
        # HACK: or things will segfault
        # HACK: This hack causes intentional memory leak, but prevents segfault
        def dummy(x):
            pass

        try:
            ft232.libftdi.ftdi.ftdi_free = dummy
        except:
            pass

        serial = opts["mt12505_serial"]
        if opts["mt12505_serial"] == None:
            devices = ft232.list_devices()
            devices = self.__to_mt12505_devices(devices)
            if len(devices) == 0:
                raise Exception("ERROR: No MT12505 devices found")

            if len(devices) == 1:
                serial = devices[0][0]
            else:
                print(
                    "WARNING: Multiple MT12505 devices found, please specify serial"
                )
                for d in devices:
                    print(f"Serial: {d[0]} Description: {d[1]}")
                sys.exit(1)

        self.sp = ft232.Ft232(serial, baudrate=115200)
        self.sp.cbus_setup(mask=0xf, init=0xf)
        return super().__init__(terminal, opts)