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_hotplug_poll_interval ()

get_main_context ()

get_source (main_ctx)

load (json_object)

load_with_tag (json_object, tag)

save (json_builder)

save_with_tag (json_builder, tag)

set_debug (flags)

set_flags (flags)

set_hotplug_poll_interval (hotplug_poll_interval)

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_changed (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-changed

This signal is emitted when a USB device is changed.

device-removed

This signal is emitted when a USB device is removed.

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

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_hotplug_poll_interval()
Returns:

interval in ms

Return type:

int

Gets the poll interval for platforms like Windows that do not support LIBUSB_CAP_HAS_HOTPLUG.

New in version 0.3.10.

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.

load(json_object)
Parameters:

json_object (Json.Object) – a Json.Object

Raises:

GLib.Error

Returns:

True on success

Return type:

bool

Loads the context from a JSON object.

New in version 0.4.0.

load_with_tag(json_object, tag)
Parameters:
Raises:

GLib.Error

Returns:

True on success

Return type:

bool

Loads any devices with a specified tag into the context from a JSON object.

New in version 0.4.1.

save(json_builder)
Parameters:

json_builder (Json.Builder) – a Json.Builder

Raises:

GLib.Error

Returns:

True on success

Return type:

bool

Saves the context to an existing JSON builder.

New in version 0.4.0.

save_with_tag(json_builder, tag)
Parameters:
Raises:

GLib.Error

Returns:

True on success

Return type:

bool

Saves any devices with a specified tag into an existing JSON builder.

New in version 0.4.1.

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_hotplug_poll_interval(hotplug_poll_interval)
Parameters:

hotplug_poll_interval (int) – the interval in ms

Sets the poll interval for platforms like Windows that do not support LIBUSB_CAP_HAS_HOTPLUG. This defaults to 1000ms and can be changed before or after GUsb.Context.enumerate() has been called.

New in version 0.3.10.

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_changed(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_changed(context, device)
Signal Name:

device-changed

Flags:

RUN_LAST

Parameters:

This signal is emitted when a USB device is changed.

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