USB Host

You can use the USB host functionality to learn about connected USB devices and communicate with them on the USB protocol layer.

This API is supported on specifc Tizen devices that support USB host features.

Figure: USB host mode overview

USB host mode

The main features of the USB Host API include:

The following figure shows an overview of the USB host architecture.

Figure: USB host architecture

USB host architecture

Prerequisites

To enable your application to use the USB host functionality:

  1. To use the USB host features, include the following feature in your tizen-manifest.xml file.

<feature name="http://tizen.org/feature/usb.host"/>

  1. The USB Host API does not require any Tizen privileges to be defined, instead the user is asked for confirmation when performing a potentially privileged operation.

    USB Host access

  2. To use the methods and properties of the Tizen.System.Usb namespace, include it in your application:

    C#
    Copy
    using Tizen.System.Usb;

Finding and Opening a Device

To begin working with a device, you must find it in the device list.

  1. Get the device list:

    C#
    Copy
    var usb = new UsbManager(); var devices = usb.AvailableDevices(); foreach (UsbDevice dev in devices) { ...
  2. Gather information about the device by inspecting UsbDevice properties.

    Various USB Host API functions allow you to get some basic information about the USB devices in the device list. You can get values, such as vendor ID or product ID, from the descriptors sent by the device. By checking the device information, you can select a device suitable for your communication needs. Usually, the USB device vendor ID and product ID are used to uniquely identify the device.

    All the USB Host API functions can operate on a device even if it has not been opened.

  3. Open the device.

    After the device is uniquely identified and you have found the one you need, open it for further use:

    C#
    Copy
    foreach (UsbDevice dev in devices) { if (dev.UsbDeviceInformation.VendorId == 0x1234 && dev.UsbDeviceInformation.ProductId == 0x5678) { try { dev.Open();
  4. While the device is open, you can get strings from it.

    Identify the device using strings, such as the string associated with the manufacturer.

    C#
    Copy
    var str = dev.Strings; if (str.Manufacturer == "Samsung") { ...
  5. When the device is no longer needed, close it.

    C#
    Copy
    dev.Close(); dev.Dispose();

Monitoring Device Connections

To receive notifications when a USB device is attached or detached, use the DeviceHotPlugged event listener:

C#
Copy
var manager = new UsbManager(); manager.DeviceHotPlugged += ...;

Interfaces, Endpoints, and Transfer

USB communication always happens between the host and one of the endpoints. The endpoints are grouped into interfaces and interfaces into configurations. A device can have multiple configurations, but only one can be active at a time. All interfaces inside an active configuration can be used at the same time.

Programs which are dedicated for one specific device often hardcode the interface index and endpoints numbers. More flexible programs must go through a list of interfaces in a configuration, check the basic interface information (such as class), and check the endpoints. After finding a suitable interface, they claim it before starting communication with any of its endpoints.

C#
Copy
var device = manager.AvailableDevices.Single(...); device.Configurations[123].SetAsActive(); var interface = device.ActiveConfiguration.Interfaces.Single(...); // or .Interfaces[123] interface.Claim(); var endpoint = interface.Endpoints.Single(...); // or .Endpoints[123] endpoint.Transfer(Encoding.ASCII.GetBytes("foobar"), 6, 1000); // timeout in ms interface.Release();
  • Dependencies
    • Since Tizen 3.0
  • API References
Attached Devices
Next System Information
Submit your feedback to GitHub