UsbSerialForAndroid 2.0.1

dotnet add package UsbSerialForAndroid --version 2.0.1
                    
NuGet\Install-Package UsbSerialForAndroid -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UsbSerialForAndroid" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UsbSerialForAndroid" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="UsbSerialForAndroid" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add UsbSerialForAndroid --version 2.0.1
                    
#r "nuget: UsbSerialForAndroid, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package UsbSerialForAndroid@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=UsbSerialForAndroid&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=UsbSerialForAndroid&version=2.0.1
                    
Install as a Cake Tool

UsbSerialForAndroid

This is a driver library to allow your Microsoft Android app to communicate with many common USB serial hardware. It uses the Android USB Host API available on Android 3.1+.

No root access, ADK, or special kernel drivers are required; all drivers are implemented in C#. You get a raw serial port with Read(), Write(), and other basic functions for use with your own protocols. The appropriate driver is picked based on the device's Vendor ID and Product ID.

This is a C# port of Mike Wakerly's Java usb-serial-for-android library. It followed that library very closely when it was ported. The main changes were to make the method names follow C# standard naming conventions. Some Java specific data types were replaced with .NET types and the reflection code is .NET specific. Code examples written for the Java version of the library should translate more or less faithfully to C#.

It also includes code derived from a portion of LusoVU's XamarinUsbSerial library. XamarinUsbSerial was a C# wrapper for the Java usb-serial-for-android. It used an older version of the usb-serial-for-android .jar file. Only the C# code was used, the Java library is not referenced.

This library supports .NET 10 and Microsoft Android. Support for Xamarin Android and previous versions of .NET have been dropped. Sample application has been replaced with a new app demo. If you need the old demo or want to support older versions of .NET, please use verson 1.1.1.

If you are seeing this from the nuget package, the source code for this library and demo project can be accessed via the Github repo UsbSerialForAndroid.

Getting Started

1. Reference the library to your project

2. Copy the device_filter.axml from the example app to your Resources/xml folder. Make sure that the Build Action is set to AndroidResource

3. Add the following attribute to the main activity to enable the USB Host

[assembly: UsesFeature("android.hardware.usb.host")]

4. Add the following IntentFilter to the main activity to receive USB device attached notifications

[IntentFilter(new[] { UsbManager.ActionUsbDeviceAttached })]

5. Add the MetaData attribute to associate the device_filter with the USB attached event to only see the devices that we are looking for

[MetaData(UsbManager.ActionUsbDeviceAttached, Resource = "@xml/device_filter")]

6. Refer to MainActivity.cs in the example app to see how connect to a serial device and read data from it.

Working with unrecognized devices

The UsbSerialForAndroid has been compiled with the Vendor ID/Product ID pairs for many common serial devices. If you have a device that is not defined by the library, but will work with one of the drivers, you can manually add the VID/PID pair. If you have a device that is not in the GetSupportedDevices() method for that driver, you can submit a pull request that adds the vendor and product IDs to that driver.

UsbSerialProber is a class to help you find and instantiate compatible UsbSerialDrivers from the tree of connected UsbDevices. Normally, you will use the default prober returned by UsbSerialProber.getDefaultProber(), which uses the built-in list of well-known VIDs and PIDs that are supported by our drivers.

To use your own set of rules, create and use a custom prober:

// Probe for our custom CDC devices, which use VID 0x1234
// and PIDS 0x0001 and 0x0002.
var table = UsbSerialProber.DefaultProbeTable;
table.AddProduct(0x1b4f, 0x0008, typeof(CdcAcmSerialDriver)); // IOIO OTG

table.AddProduct(0x09D8, 0x0420, typeof(CdcAcmSerialDriver)); // Elatec TWN4

var prober = new UsbSerialProber(table);
List<UsbSerialDriver> drivers = prober.FindAllDrivers(usbManager);
// ...

Of course, nothing requires you to use UsbSerialProber at all: you can instantiate driver classes directly if you know what you're doing; just supply a compatible UsbDevice.

Compatible Devices

Additional information

This is a port of the usb-serial-for-android library and code examples written for it can be adapted to C# without much effort.

For common problems, see the Troubleshooting wiki page for usb-serial-for-android library. For other help and discussion, please join the usb-serial-for-android Google Group, usb-serial-for-android. These two resources are for the Android Java version, but this library is port of that code base.

Pull Requests are welcome, but please include what hardware was used for testing. We do not have the hardware or the bandwidth to test the various chipsets supported by the library.

We will do our best to respond to reported issues. If you have a code fix or suggestion, we are only looking at changes submitted as pull requests.

For more information about contributing or reporting an issue, please see CONTRIBUTING.md for more information for what we are looking for and how to get started.

This library is licensed under the MIT License. Please see LICENSE.txt for the complete license.

Copyright 2017, Tyler Technologies. All Rights Reserved. Portions of this library are based on the usb-serial-for-android and XamarinUsbSerial libraries. Their rights remain intact.

The icon used for the demo app was derived from Serial to USB by Bonegolem (CC BY 3.0)

Product Compatible and additional computed target framework versions.
.NET net10.0-android36.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0-android36.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 58 1/1/2026