UsbSerial for android.
 
 
 
Go to file
StephaneBg 6a75ee3fd8 Add example as a module. 2016-01-11 12:28:22 +01:00
example Add example as a module. 2016-01-11 12:28:22 +01:00
gradle/wrapper Update project to gradle build system. 2015-12-10 10:05:54 +01:00
usbserial Add example as a module. 2016-01-11 12:28:22 +01:00
.gitignore Update project to gradle build system. 2015-12-10 10:05:54 +01:00
LICENSE Initial commit 2014-03-20 04:23:57 -07:00
README.md Add example as a module. 2016-01-11 12:28:22 +01:00
build.gradle Update project to gradle build system. 2015-12-10 10:05:54 +01:00
gradle.properties Add example as a module. 2016-01-11 12:28:22 +01:00
gradlew Update project to gradle build system. 2015-12-10 10:05:54 +01:00
gradlew.bat Update project to gradle build system. 2015-12-10 10:05:54 +01:00
settings.gradle Add example as a module. 2016-01-11 12:28:22 +01:00

README.md

UsbSerial

Usb serial controller for Android. For more information, there is a more complete description.

Devices Supported

CP210X devices Default: 9600,8,1,None,flow off

CDC devices Default 115200,8,1,None,flow off

FTDI devices Default: 9600,8,1,None,flow off

PL2303 devices Default 9600,8,1,None,flow off

CH34x devices Default 9600,8,1,None,flow off

How to use it?

Instantiate a new object of the UsbSerialDevice class

UsbDevice device;
UsbDeviceConnection usbConnection;
...
UsbSerialDevice serial = UsbSerialDevice.createUsbSerialDevice(device, usbConnection); 

Open the device and set it up as desired

serial.open();
serial.setBaudRate(115200);
serial.setDataBits(UsbSerialInterface.DATA_BITS_8);
serial.setParity(UsbSerialInterface.PARITY_ODD);

There is no need to be polling if you want to perform a bulk transaction to a IN endpoint. Define a simply callback

private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() {

		@Override
		public void onReceivedData(byte[] arg0) 
		{
			// Code here :)
		}
		
};

And pass a reference of it

serial.read(mCallback);

Write something

serial.write("DATA".getBytes()); // Async-like operation now! :)

Close the device:

serial.close();

In Android usb api, when a usb device has been close it must be reopened

UsbDevice device;
...
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
manager.openDevice(UsbDevice device)

Gradle

Add the jitpack repo to your your project's build.gradle at the end of repositories

/build.gradle

allprojects {
	repositories {
		jcenter()
		maven { url "https://jitpack.io" }
	}
}

Then add the dependency to your module's build.gradle:

/app/build.gradle

compile 'com.github.felHR85:UsbSerial:3.3'

TO-DO

  • RTS/CTS and DSR/DTR functions needed to raise hardware flow control signals