react-native-usb
v0.1.1
Published
A React Native module for USB communication
Downloads
26
Readme
react-native-usb
Getting started
npm install react-native-usb --save
or
yarn add react-native-usb
Mostly automatic installation
react-native link react-native-usb
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import me.andyshea.ReactNativeUsbPackage;
to the imports at the top of the file - Add
new ReactNativeUsbPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-usb' project(':react-native-usb').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-usb/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-usb')
Usage
import usb from 'react-native-usb';
// connect to device
await usb.connect(vendorId, productId);
// setup data event listener
usb.on('data', data => {
console.log(data);
});
// send data to device
usb.write([0x01, 0x02, 0x03]);
// disconnect when finished
usb.disconnect();