GUsb.Context

g GObject.GInterface GObject.GInterface Gio.Initable Gio.Initable GObject.GInterface->Gio.Initable GObject.Object GObject.Object GUsb.Context GUsb.Context GObject.Object->GUsb.Context Gio.Initable->GUsb.Context

Subclasses:None

Methods

Inherited:GObject.Object (37), Gio.Initable (2)
Structs:GObject.ObjectClass (5)
class error_quark ()
class new ()
  enumerate ()
  find_by_bus_address (bus, address)
  find_by_platform_id (platform_id)
  find_by_vid_pid (vid, pid)
  get_devices ()
  get_flags ()
  get_main_context ()
  get_source (main_ctx)
  set_debug (flags)
  set_flags (flags)
  set_main_context (main_ctx)
  wait_for_replug (device, timeout_ms)

Virtual Methods

Inherited:GObject.Object (7), Gio.Initable (1)
  do_device_added (device)
  do_device_removed (device)

Properties

Name Type Flags Short Description
debug-level int r/w  
libusb-context int r  

Signals

Inherited:GObject.Object (1)
Name Short Description
device-added This signal is emitted when a USB device is added.
device-removed This signal is emitted when a USB device is removed.

Fields

Inherited:GObject.Object (1)
Name Type Access Description
parent GObject.Object r  
priv GUsb.ContextPrivate r  

Class Details

class GUsb.Context(**kwargs)
Bases:GObject.Object, Gio.Initable
Abstract:No
Structure:GUsb.ContextClass
classmethod error_quark()
Returns:Our personal error quark.
Return type:int

New in version 0.1.0.

classmethod new()
Raises:GLib.Error
Returns:a new GUsb.Context object or None on error.
Return type:GUsb.Context

Creates a new context for accessing USB devices.

New in version 0.1.0.

enumerate()

Enumerates all the USB devices and adds them to the context.

You only need to call this function once, and any subsequent calls are silently ignored.

New in version 0.2.2.

find_by_bus_address(bus, address)
Parameters:
  • bus (int) – a bus number
  • address (int) – a bus address
Raises:

GLib.Error

Returns:

a new GUsb.Device, or None if not found.

Return type:

GUsb.Device

Finds a device based on its bus and address values.

New in version 0.2.2.

find_by_platform_id(platform_id)
Parameters:platform_id (str) – a platform id, e.g. “usb:00:03:03:02”
Raises:GLib.Error
Returns:a new GUsb.Device, or None if not found.
Return type:GUsb.Device

Finds a device based on its platform id value.

New in version 0.2.4.

find_by_vid_pid(vid, pid)
Parameters:
  • vid (int) – a vendor ID
  • pid (int) – a product ID
Raises:

GLib.Error

Returns:

a new GUsb.Device, or None if not found.

Return type:

GUsb.Device

Finds a device based on its bus and address values.

New in version 0.2.2.

get_devices()
Returns:a new GLib.PtrArray of GUsb.Device’s.
Return type:[GUsb.Device]

New in version 0.2.2.

get_flags()
Returns:the GUsb.ContextFlags, e.g. GUsb.ContextFlags.AUTO_OPEN_DEVICES
Return type:GUsb.ContextFlags

Sets the flags to use for the context.

New in version 0.2.11.

get_main_context()
Returns:the GLib.MainContext
Return type:GLib.MainContext

Gets the internal GLib.MainContext to use for synchronous methods. By default the value is set to the value of GLib.MainContext.default()

New in version 0.2.5.

get_source(main_ctx)
Parameters:main_ctx (GLib.MainContext) – a GLib.MainContext, or None
Returns:the GUsb.Source.
Return type:GUsb.Source

This function does nothing.

New in version 0.1.0.

set_debug(flags)
Parameters:flags (GLib.LogLevelFlags) – a GLib.LogLevelFlags such as GLib.LogLevelFlags.LEVEL_ERROR | GLib.LogLevelFlags.LEVEL_INFO, or 0

Sets the debug flags which control what is logged to the console.

Using GLib.LogLevelFlags.LEVEL_INFO will output to standard out, and everything else logs to standard error.

New in version 0.1.0.

set_flags(flags)
Parameters:flags (GUsb.ContextFlags) – some GUsb.ContextFlags, e.g. GUsb.ContextFlags.AUTO_OPEN_DEVICES

Sets the flags to use for the context. These should be set before GUsb.Context.enumerate() is called.

New in version 0.2.11.

set_main_context(main_ctx)
Parameters:main_ctx (GLib.MainContext) –

Sets the internal GLib.MainContext to use for synchronous methods.

New in version 0.2.5.

wait_for_replug(device, timeout_ms)
Parameters:
Raises:

GLib.Error

Returns:

a new GUsb.Device, or None for invalid

Return type:

GUsb.Device

Waits for the device to be replugged. It may come back with a different VID:PID.

Warning: This is synchronous and blocks until the device comes back or the timeout triggers.

New in version 0.2.9.

do_device_added(device) virtual
Parameters:device (GUsb.Device) –
do_device_removed(device) virtual
Parameters:device (GUsb.Device) –

Signal Details

GUsb.Context.signals.device_added(context, device)
Signal Name:

device-added

Flags:

RUN_LAST

Parameters:

This signal is emitted when a USB device is added.

GUsb.Context.signals.device_removed(context, device)
Signal Name:

device-removed

Flags:

RUN_LAST

Parameters:

This signal is emitted when a USB device is removed.

Property Details

GUsb.Context.props.debug_level
Name:debug-level
Type:int
Default Value:0
Flags:READABLE, WRITABLE
GUsb.Context.props.libusb_context
Name:libusb-context
Type:int
Default Value:None
Flags:READABLE