与USB设备通信并将数据存储在数据库中外文翻译资料

 2022-08-25 21:24:24

Communicate with USB devices and store data in databases

Abstract:USB Host and Accessory

Android supports a variety of USB peripherals and Android USB accessories (hardware that implements the Android accessory protocol) through two modes: USB accessory and USB host. In USB accessory mode, the external USB hardware act as the USB hosts. Examples of accessories might include robotics controllers; docking stations; diagnostic and musical equipment; kiosks; card readers; and much more. This gives Android-powered devices that do not have host capabilities the ability to interact with USB hardware. Android USB accessories must be designed to work with Android-powered devices and must adhere to the Android accessory communication protocol. In USB host mode, the Android-powered device acts as the host. Examples of devices include digital cameras, keyboards, mice, and game controllers. USB devices that are designed for a wide range of applications and environments can still interact with Android applications that can correctly communicate with the device.

Figure 1 shows the differences between the two modes. When the Android-powered device is in host mode, it acts as the USB host and powers the bus. When the Android-powered device is in USB accessory mode, the connected USB hardware (an Android USB accessory in this case) acts as the host and powers the bus.

Figure 1. USB Host and Accessory Modes

USB accessory and host modes are directly supported in Android 3.1 (API level 12) or newer platforms. USB accessory mode is also backported to Android 2.3.4 (API level 10) as an add-on library to support a broader range of devices. Device manufacturers can choose whether or not to include the add-on library on the devices system image.

Note: Support for USB host and accessory modes are ultimately dependant on the devices hardware, regardless of platform level. You can filter for devices that support USB host and accessory through a lt;uses-featuregt; element. See the USB accessory and host documentation for more details.

Debugging considerations

When debugging applications that use USB accessory or host features, you most likely will have USB hardware connected to your Android-powered device. This will prevent you from having an adb connection to the Android-powered device via USB. You can still access adb over a network connection. To enable adb over a network connection:

  1. Connect the Android-powered device via USB to your computer.
  2. From your SDK platform-tools/ directory, enter adb tcpip 5555 at the command prompt.
  3. Enter adb connect lt;device-ip-addressgt;:5555 You should now be connected to the Android-powered device and can issue the usual adb commands like adb logcat.
  4. To set your device to listen on USB, enter adb usb.

1.USB Accessory

  1. Android USB Accessory Development Kit

USB accessory mode allows users to connect USB host hardware specifically designed for Android-powered devices. The accessories must adhere to the Android accessory protocol outlined in the Android Accessory Development Kit documentation. This allows Android-powered devices that cannot act as a USB host to still interact with USB hardware. When an Android-powered device is in USB accessory mode, the attached Android USB accessory acts as the host, provides power to the USB bus, and enumerates connected devices. Android 3.1 (API level 12) supports USB accessory mode and the feature is also backported to Android 2.3.4 (API level 10) to enable support for a broader range of devices.

Choosing the Right USB Accessory APIs

Although the USB accessory APIs were introduced to the platform in Android 3.1, they are also available in Android 2.3.4 using the Google APIs add-on library. Because these APIs were backported using an external library, there are two packages that you can import to support USB accessory mode. Depending on what Android-powered devices you want to support, you might have to use one over the other:

com.android.future.usb: To support USB accessory mode in Android 2.3.4, the Google APIs add-on library includes the backported USB accessory APIs and they are contained in this namespace. Android 3.1 also supports importing and calling the classes within this namespace to support applications written with the add-on library. This add-on library is a thin wrapper around the android.hardware.usb accessory APIs and does not support USB host mode. If you want to support the widest range of devices that support USB accessory mode, use the add-on library and import this package. It is important to note that not all Android 2.3.4 devices are required to support the USB accessory feature. Each individual device manufacturer decides whether or not to support this capability, which is why you must declare it in your manifest file.

android.hardware.usb: This namespace contains the classes that support USB accessory mode in Android 3.1. This package is included as part of the framework APIs, so Android 3.1 supports USB accessory mode without the use of an add-on library. Use this package if you only care about Android 3.1 or newer devices

剩余内容已隐藏,支付完成后下载完整资料


与USB设备通信并将数据存储在数据库中

摘要:USB主机和附件

Android支持各种USB外设和Android USB配件(实现Android配件协议的硬件),通过USB配件和USB主机两种模式。在USB附件模式下,外部USB硬件充当USB主机。附件的例子可能包括机器人控制器;坞站;诊断和音乐设备;报亭读卡器;以及更多。这给具有主机功能的Android设备提供与USB硬件交互的能力。 Android USB配件必须设计为与Android设备配合使用,并且必须遵守Android附件通讯协议。在USB主机模式下,Android驱动的设备充当主机。设备的示例包括数码相机,键盘,鼠标和游戏控制器。专为各种应用和环境设计的USB设备仍然可以与可以正确与设备通信的Android应用程序进行交互。

图1显示了两种模式之间的差异。当Android设备处于主机模式时,它充当USB主机并为总线供电。当Android设备处于USB附件模式时,连接的USB硬件(在这种情况下为Android USB配件)充当主机并为总线供电。

Figure 1. USB主机和附件模式

Android 3.1(API级别12)或更新版本直接支持USB附件和主机模式。 USB附件模式也作为附加库返回到Android 2.3.4(API级别10),以支持更广泛的设备。设备制造商可以选择是否在设备的系统映像上包含附加库。

注意:支持USB主机和附件模式最终取决于设备的硬件,无论平台级别如何。您可以通过lt;uses-featuregt;元素过滤支持USB主机和附件的设备。有关详细信息,请参阅USB附件和主机文档。

调试注意事项当调试使用USB附件或主机功能的应用程序时,您很有可能将USB硬件连接到Android设备。这将阻止您通过USB连接到Android设备的adb连接。您仍然可以通过网络连接访问adb。要通过网络连接启用adb:

1.通过USB连接Android电源设备到您的计算机。

2.从SDK平台工具/目录中,在命令提示符下输入adb tcpip 5555。3.输入adb connect lt;device-ip-addressgt;:5555您现在应该连接到Android设备,并且可以发出通常的adb命令,如adb logcat。4.要将设备设置为在USB上侦听,请输入adb usb。

1 .USB配件

Android USB配件开发套件

USB附件模式允许用户连接专为Android设备设计的USB主机硬件。配件必须遵守Android配件开发套件文档中概述的Android附件协议。这使得无法充当USB主机的Android电源设备仍然可以与USB硬件交互。当Android设备处于USB附件模式时,所附的Android USB附件充当主机,为USB总线供电,并列举连接的设备。 Android 3.1(API级别12)支持USB附件模式,并且该功能也被返回到Android 2.3.4(API级别10),以支持更广泛的设备。.

选择正确的USB附件API

虽然USB附件API已经被引入到Android 3.1平台,但它们也可以在Android 2.3.4中使用Google API附加库。因为这些API是使用外部库进行反向输入的,所以有两个包可以导入以支持USB附件模式。根据您要支持的Android功能的设备,您可能需要使用其他设备:

com.android.future.usb:要在Android 2.3.4中支持USB附件模式,Google API附加库包括后端的USB附件API,它们包含在此命名空间中。 Android 3.1还支持在此命名空间中导入和调用类,以支持使用附加库编写的应用程序。这个附加库是围绕android.hardware.usb附件API的薄包装,不支持USB主机模式。如果要支持最广泛的支持USB附件模式的设备,请使用附加库并导入此软件包。重要的是要注意,并不是所有的Android 2.3.4设备都需要支持USB附件功能。每个设备制造商决定是否支持此功能,这就是为什么必须在清单文件中声明它。

android.hardware.usb:这个命名空间包含在Android 3.1中支持USB附件模式的类。这个包是框架的一部分, 所以Android 3.1支持USB附件模式,而不使用附加库。如果您只关心具有USB附件模式硬件支持的Android 3.1或更新的设备,可以在您的清单文件中声明,请使用此软件包。

安装Google API附加库如果要安装附加组件

如果要安装附加组件,您可以请使用SDK Manager安装Google API Android API 10软件包。有关安装附加库的更多信息,请参阅安装Google API插件

API概述

由于附加库是框架API的包装器,支持USB附件功能的类似。即使您正在使用附加库,您也可以使用参考文档来了解android.hardware.usb。

注意: 您应该注意附加库和框架API之间的细微使用差异

下表介绍了支持USB附件API的类

Class

Description

UsbManager

允许您枚举并与连接的USB附件进行通信

UsbAccessory

表示USB附件,包含访问其识别信息的方法

附加库和平台API之间的用途差异

使用Google API附加库和平台API之间的两个使用差异

如果使用附加库,则必须以以下方式获取UsbManager对象:

UsbManager manager = UsbManager.getInstance(this);

如果您不使用附加库,您必须以以下方式获取UsbManager对象:

UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

当你过滤器使用意图过滤器连接的附件,UsbAccessory对象包含在传递给应用程序的意图内。如果您正在使用附加库,则必须以以下方式获取UsbAccessory对象:

UsbAccessory accessory = UsbManager.getAccessory(intent);

如果您不使用附加库,则必须以以下方式获取UsbAccessory对象:

UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);

Android清单要求

以下列表描述了在使用USB辅助API之前需要添加到应用程序的清单文件中。 清单和资源文件示例显示如何声明这些项目:

因为并非所有Android设备都能保证支持USB附件API,还包括一个lt;uses-featuregt;元素,声明您的应用程序使用android.hardware.usb.accessory功能。

如果您正在使用附加库,请添加指定库的com.android.future.usb.accessory的lt;uses-librarygt;元素。

如果您使用附加库,请将应用程序的最小SDK设置为API 10级,如果使用的是android.hardware.usb包,则将其设置为12。

如果希望您的应用程序被通知附件的USB附件,请在主要活动中为theandroid.hardware.usb.action.USB_ACCESSORY_ATTACHED意图指定一个lt;intent-filtergt;和lt;meta-datagt;元素对。 lt;meta-datagt;元素指向一个外部XML资源文件,它声明要检测的附件的信息。

在XML资源文件中,为要过滤的附件声明lt;usb-accessorygt;元素。 每个lt;usb-accessorygt;可以具有以下属性:制造商,模型,版本

将资源文件保存在res / xml /目录中。 资源文件名(不含.xml扩展名)必须与您在lt;meta-datagt;元素中指定的文件名相同。 XML资源文件的格式也在下面的示例中显示。

清单和资源文件示例

以下示例显示了示例清单及其对应的资源文件:

lt;manifest ...gt;
lt;uses-feature android:name='android.hardware.usb.accessory' /gt;

lt;uses-sdk android:minSdkVersion='lt;versiongt;' /gt;
...
lt;applicationgt;
lt;uses-library android:name='com.android.future.usb.accessory' /gt;
lt;activity ...gt;
...
lt;intent-filtergt;
lt;action android:name='android.hardware.usb.action.USB_ACCESSORY_ATTACHED' /gt;
lt;/intent-filtergt;

lt;meta-data android:name='android.hardware.usb.action.USB_ACCESSORY_ATTACHED'
android:resource='@xml/accessory_filter' /gt;
lt;/activitygt;
lt;/applicationgt;
lt;/manifestgt;

在这种情况下,应将以下资源文件保存在res / xml / accessory_filter.xml中,并指定具有相应型号,制造商和版本的任何附件应被过滤。 配件将这些属性发送给Android设备:

lt;?xml version='1.0' encoding='utf-8'?gt;

lt;resourcesgt;
lt;usb-accessory model='DemoKit' manufacturer='Google' version='1.0'/gt;
lt;/resourcesgt;

使用配件

当用户将USB附件连接到Android设备时,Android系统可以确定您的应用程序是否对连接的附件感兴趣。 如果是这样,如果需要,您可以设置与附件的通信。 为此,您的应用程序必须: t

1.通过使用过滤附件事件的意图过滤器或枚举所连接的附件并找到适当的附件来发现连接的附件。

2.请求用户与附件通信,如果尚未获得。

3.通过在相应的接口端点上读取和写入数据与附件进行通信。

发现配件

您的应用程序可以通过使用意图过滤器来发现附件,以便在用户连接附件或枚举已连接的附件时收到通知。 如果希望能够让应用程序自动检测到所需的附件,则使用意图过滤器很有用。 如果您想获得所有连接的配件的列表,或者您的应用程序没有为意图过滤,枚举连接的附件是有用的。

使用意图过滤器

要使您的应用程序发现一个特定的USB附件,您可以指定一个意图过滤器来过滤android.hardware.usb.action.USB_ACCESSORY_ATTACHED意图。 除了该意图过滤器之外,还需要指定一个资源文件,该文件指定USB配件的属性,如制造商,型号和版本。 当用户连接与您的附件过滤器相匹配的附件时,

以下示例显示如何声明intent过滤器:

lt;activity ...gt;
...
lt;intent-filtergt;
lt;action android:name='android.hardware.usb.action.USB_ACCESSORY_ATTACHED' /gt;
lt;/intent-filtergt;

lt;meta-data android:name='android.hardware.usb.actio

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[484676],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。