コード例 #1
0
 def purgeBuffers(self):
     """ Purge ftdi buffers
     """
     err = ftdi.ftdi_usb_purge_buffers(self.__ftdic)
     if err < 0:
         self._log.error("Can't purge buffers (%d, %s)" % (err, ftdi.ftdi_get_error_string(self.__ftdic)))
         raise FtdiError("Can't purge buffers (%d, %s)" % (err, ftdi.ftdi_get_error_string(self.__ftdic)))
コード例 #2
0
    def __init__(self):
        # open channel A
        self.ft_ctx = ftdi.ftdi_context()
        if ftdi.ftdi_init(self.ft_ctx) < 0:
            raise RuntimeError("ftdi_init failed")
        ftdi.ftdi_set_interface(self.ft_ctx, ftdi.INTERFACE_A)
        if ftdi.ftdi_usb_open(self.ft_ctx, 0x0403, 0x6010) != 0:
            raise RuntimeError(ftdi.ftdi_get_error_string(self.ft_ctx))

        try:
            # open and purge channel B
            ft_ctx_b = ftdi.ftdi_context()
            if ftdi.ftdi_init(ft_ctx_b) < 0:
                raise RuntimeError("ftdi_init failed")
            ftdi.ftdi_set_interface(ft_ctx_b, ftdi.INTERFACE_B)
            if ftdi.ftdi_usb_open(ft_ctx_b, 0x0403, 0x6010) != 0:
                raise RuntimeError(ftdi.ftdi_get_error_string(ft_ctx_b))
            # purge buffers
            if ftdi.ftdi_usb_purge_buffers(ft_ctx_b) != 0:
                raise RuntimeError(ftdi.ftdi_get_error_string(ft_ctx_b))
            # close channel B
            ftdi.ftdi_usb_close(ft_ctx_b)
            ftdi.ftdi_deinit(ft_ctx_b)
        except RuntimeError:
            self.close()
            raise

        # setup FIFO mode
        try:
            self.ft_ctx.usb_read_timeout = 5000000
            self.ft_ctx.usb_write_timeout = 5000000
            ftdi.ftdi_read_data_set_chunksize(self.ft_ctx, self.READ_CHUNKSIZE)
            ftdi.ftdi_write_data_set_chunksize(self.ft_ctx,
                                               self.WRITE_CHUNKSIZE)

            if ftdi.ftdi_usb_reset(self.ft_ctx) != 0:
                raise RuntimeError("Reset failed")
            time.sleep(100e-3)

            if ftdi.ftdi_set_bitmode(self.ft_ctx, 0, ftdi.BITMODE_SYNCFF) != 0:
                raise RuntimeError("Setting FIFO mode failed")

            if ftdi.ftdi_set_latency_timer(self.ft_ctx, 1) != 0:
                raise RuntimeError("Setting latency failed")
        except RuntimeError:
            self.close()
            raise
コード例 #3
0
ファイル: ft2232h.py プロジェクト: pwuertz/faout
    def __init__(self):
        # open channel A
        self.ft_ctx = ftdi.ftdi_context()
        if ftdi.ftdi_init(self.ft_ctx) < 0:
            raise RuntimeError("ftdi_init failed")
        ftdi.ftdi_set_interface(self.ft_ctx, ftdi.INTERFACE_A)
        if ftdi.ftdi_usb_open(self.ft_ctx, 0x0403, 0x6010) != 0:
            raise RuntimeError(ftdi.ftdi_get_error_string(self.ft_ctx))

        try:
            # open and purge channel B
            ft_ctx_b = ftdi.ftdi_context()
            if ftdi.ftdi_init(ft_ctx_b) < 0:
                raise RuntimeError("ftdi_init failed")
            ftdi.ftdi_set_interface(ft_ctx_b, ftdi.INTERFACE_B)
            if ftdi.ftdi_usb_open(ft_ctx_b, 0x0403, 0x6010) != 0:
                raise RuntimeError(ftdi.ftdi_get_error_string(ft_ctx_b))
            # purge buffers
            if ftdi.ftdi_usb_purge_buffers(ft_ctx_b) != 0:
                raise RuntimeError(ftdi.ftdi_get_error_string(ft_ctx_b))
            # close channel B
            ftdi.ftdi_usb_close(ft_ctx_b)
            ftdi.ftdi_deinit(ft_ctx_b)
        except RuntimeError:
            self.close()
            raise

        # setup FIFO mode
        try:            
            self.ft_ctx.usb_read_timeout = 5000000;
            self.ft_ctx.usb_write_timeout = 5000000;
            ftdi.ftdi_read_data_set_chunksize(self.ft_ctx, self.READ_CHUNKSIZE)
            ftdi.ftdi_write_data_set_chunksize(self.ft_ctx, self.WRITE_CHUNKSIZE)
            
            if ftdi.ftdi_usb_reset(self.ft_ctx) != 0:
                raise RuntimeError("Reset failed")
            time.sleep(100e-3)
            
            if ftdi.ftdi_set_bitmode(self.ft_ctx, 0, ftdi.BITMODE_SYNCFF) != 0:
                raise RuntimeError("Setting FIFO mode failed")
                
            if ftdi.ftdi_set_latency_timer(self.ft_ctx, 1) != 0:
                raise RuntimeError("Setting latency failed")
        except RuntimeError:
            self.close()
            raise