# `misc` - Miscellaneous helpers

## Functions

Miscellaneous helpers

class pyftdi.misc.EasyDict(dictionary=None, **kwargs)

  Dictionary whose members can be accessed as instance members

  classmethod copy() → a shallow copy of D
  mirror()

    Instanciate a mirror EasyDict.

    Return type

      `EasyDict`

pyftdi.misc.add_custom_devices(ftdicls=None, vpstr=None, force_hex=False)

  Helper function to add custom VID/PID to FTDI device identifer map.

  The string to parse should match the following format:

  [vendor_name=]<vendor_id>:[product_name=]<product_id>

  - vendor_name and product_name are optional strings, they may be omitted as they only serve as human-readable aliases for vendor and product names.

  - vendor_id and product_id are mandatory strings that should resolve as 16-bit integer (USB VID and PID values). They may be expressed as decimal or hexadecimal syntax.

  ex:

    - `0x403:0x9999`, vid:pid short syntax, with no alias names

    - `mycompany=0x666:myproduct=0xcafe`, vid:pid complete syntax with

        aliases

  Parameters

    - vpstr (`Optional`[`Sequence`[`str`], `None`]) – typically, a option switch string describing the device to add

    - ftdicls – the Ftdi class that should support the new device.

    - force_hex (`bool`) – if set, consider that the pid/vid string are hexadecimal encoded values.

  Return type

    `None`

class pyftdi.misc.classproperty(fget=None, fset=None, fdel=None, doc=None)

  Getter property decorator for a class

pyftdi.misc.hexdump(data, full=False, abbreviate=False)

  Convert a binary buffer into a hexadecimal representation.

  Return a multi-line strings with hexadecimal values and ASCII representation of the buffer data.

  Parameters

    - data (`Union`[`bytes`, `bytearray`, `Iterable`[`int`]]) – binary buffer to dump

    - full (`bool`) – use hexdump -Cv format

    - abbreviate (`bool`) – replace identical lines with ‘*’

  Return type

    `str`

  Returns

    the generated string

pyftdi.misc.hexline(data, sep=' ')

  Convert a binary buffer into a hexadecimal representation.

  Return a string with hexadecimal values and ASCII representation of the buffer data.

  Parameters

    - data (`Union`[`bytes`, `bytearray`, `Iterable`[`int`]]) – binary buffer to dump

    - sep (`str`) – the separator string/char

  Return type

    `str`

  Returns

    the formatted string

pyftdi.misc.is_iterable(obj)

  Tells whether an instance is iterable or not.

  Parameters

    obj (object) – the instance to test

  Returns

    True if the object is iterable

  Return type

    bool

pyftdi.misc.pretty_size(size, sep=' ', lim_k=1024, lim_m=10485760, plural=True, floor=True)

  Convert a size into a more readable unit-indexed size (KiB, MiB)

  Parameters

    - size – integral value to convert

    - sep (`str`) – the separator character between the integral value and the unit specifier

    - lim_k (`int`) – any value above this limit is a candidate for KiB conversion.

    - lim_m (`int`) – any value above this limit is a candidate for MiB conversion.

    - plural (`bool`) – whether to append a final ‘s’ to byte(s)

    - floor (`bool`) – how to behave when exact conversion cannot be achieved: take the closest, smaller value or fallback to the next unit that allows the exact representation of the input value

  Return type

    `str`

  Returns

    the prettyfied size

pyftdi.misc.show_call_stack()

  Print the current call stack, only useful for debugging purpose.

pyftdi.misc.to_bool(value, permissive=True, allow_int=False)

  Parse a string and convert it into a boolean value if possible.

  Input value may be: - a string with an integer value, if allow_int is enabled - a boolean value - a string with a common boolean definition

  Parameters

    - value (`Union`[`int`, `bool`, `str`]) – the value to parse and convert

    - permissive (`bool`) – default to the False value if parsing fails

    - allow_int (`bool`) – allow an integral type as the input value

  Raises

    ValueError – if the input value cannot be converted into an bool

  Return type

    `bool`

pyftdi.misc.to_bps(value)

  Parse a string and convert it into a baudrate value.

  The function accepts common multipliers as K, M and G

  Parameters

    value (str or int or float) – the value to parse and convert

  Return type

    float

  Raises

    ValueError – if the input value cannot be converted into a float

pyftdi.misc.to_int(value)

  Parse a value and convert it into an integer value if possible.

  Input value may be: - a string with an integer coded as a decimal value - a string with an integer coded as a hexadecimal value - a integral value - a integral value with a unit specifier (kilo or mega)

  Parameters

    value (`Union`[`int`, `str`]) – input value to convert to an integer

  Returns

    the value as an integer

  Return type

    int

  Raises

    ValueError – if the input value cannot be converted into an int

pyftdi.misc.xor(_a_, _b_)

  XOR logical operation.

  Parameters

    - _a_ – first argument

    - _b_ – second argument

  Return type

    `bool`

  Returns

    xor-ed value