How to use the pyftdi.ftdi.FtdiError function in pyftdi

To help you get started, we’ve selected a few pyftdi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eblot / pyftdi / pyftdi / ftdi.py View on Github external
return data
                    else:
                        # partial copy, not enough bytes in the local cache to
                        # fulfill the request
                        part_size = min(size-len(data),
                                        len(self._readbuffer)-self._readoffset)
                        if part_size < 0:
                            raise FtdiError("Internal Error")
                        data += self._readbuffer[self._readoffset:
                                                 self._readoffset+part_size]
                        self._readoffset += part_size
                        return data
        except USBError as ex:
            raise FtdiError('UsbError: %s' % str(ex))
        # never reached
        raise FtdiError("Internal error")
github eblot / pyftdi / pyftdi / ftdi.py View on Github external
def purge_tx_buffer(self) -> None:
        """Clear the USB transmit buffer on the chip (ftdi-to-host)."""
        if self._ctrl_transfer_out(Ftdi.SIO_REQ_RESET,
                                   Ftdi.SIO_RESET_PURGE_TX):
            raise FtdiError('Unable to flush TX buffer')
github eblot / pyftdi / pyftdi / ftdi.py View on Github external
delta = 100*abs(float(actual-baudrate))/baudrate
        self.log.debug('Actual baudrate: %d %.1f%% div [%04x:%04x]',
                       actual, delta, index, value)
        # return actual
        if constrain and delta > Ftdi.BAUDRATE_TOLERANCE:
            raise ValueError('Baudrate tolerance exceeded: %.02f%% '
                             '(wanted %d, achievable %d)' %
                             (delta, baudrate, actual))
        try:
            if self._usb_dev.ctrl_transfer(
                    Ftdi.REQ_OUT, Ftdi.SIO_REQ_SET_BAUDRATE, value, index,
                    bytearray(), self._usb_write_timeout):
                raise FtdiError('Unable to set baudrate')
            return actual
        except USBError as ex:
            raise FtdiError('UsbError: %s' % str(ex))
github eblot / pyftdi / pyftdi / ftdi.py View on Github external
def port_width(self) -> int:
        """Report the width of a single port / interface

           :return: the width of the port, in bits
           :raise FtdiError: if no FTDI port is open
        """
        if not self.is_connected:
            raise FtdiError('Device characteristics not yet known')
        if self.device_version in (0x0700, 0x0900):
            return 16
        if self.device_version in (0x0500, ):
            return 12
        return 8
github eblot / pyftdi / pyftdi / ftdi.py View on Github external
Word to the wise. Not only do RS232 level shifting devices
                level shift, but they also invert the signal.
        """
        ctrl = {'hw': Ftdi.SIO_RTS_CTS_HS,
                '': Ftdi.SIO_DISABLE_FLOW_CTRL}
        try:
            value = ctrl[flowctrl] | self._index
        except KeyError:
            raise ValueError('Unknown flow control: %s' % flowctrl)
        try:
            if self._usb_dev.ctrl_transfer(
                    Ftdi.REQ_OUT, Ftdi.SIO_REQ_SET_FLOW_CTRL, 0, value,
                    bytearray(), self._usb_write_timeout):
                raise FtdiError('Unable to set flow control')
        except USBError as exc:
            raise FtdiError('UsbError: %s' % str(exc))
github eblot / pyftdi / pyftdi / ftdi.py View on Github external
try:
            data = bytearray()
            while word_count:
                buf = self._usb_dev.ctrl_transfer(
                    Ftdi.REQ_IN, Ftdi.SIO_REQ_READ_EEPROM, 0,
                    word_addr, 2, self._usb_read_timeout)
                if not buf:
                    raise FtdiEepromError('EEPROM read error @ %d' %
                                          (word_addr << 1))
                data.extend(buf)
                word_count -= 1
                word_addr += 1
            start = addr & 0x1
            return bytes(data[start:start+length])
        except USBError as ex:
            raise FtdiError('UsbError: %s' % ex)
github eblot / pyftdi / pyftdi / ftdi.py View on Github external
if self.is_mpsse:
            raise FtdiFeatureError('Cannot change frequency w/ current mode')
        actual, value, index = self._convert_baudrate(baudrate)
        delta = 100*abs(float(actual-baudrate))/baudrate
        self.log.debug('Actual baudrate: %d %.1f%% div [%04x:%04x]',
                       actual, delta, index, value)
        # return actual
        if constrain and delta > Ftdi.BAUDRATE_TOLERANCE:
            raise ValueError('Baudrate tolerance exceeded: %.02f%% '
                             '(wanted %d, achievable %d)' %
                             (delta, baudrate, actual))
        try:
            if self._usb_dev.ctrl_transfer(
                    Ftdi.REQ_OUT, Ftdi.SIO_REQ_SET_BAUDRATE, value, index,
                    bytearray(), self._usb_write_timeout):
                raise FtdiError('Unable to set baudrate')
            return actual
        except USBError as ex:
            raise FtdiError('UsbError: %s' % str(ex))