This wrapper implementation is totally based on usb-serial-for-android. Thanks mik3y for the awesome project.
npm install react-native-usbserial --save
To integrate react-native-usbserial
with the rest of your react app just execute:
react-native link react-native-usbserial
import { UsbSerial} from 'react-native-usbserial';
const usbs = new UsbSerial();
async function getDeviceAsync() {
try {
const deviceList = await usbs.getDeviceListAsync();
const firstDevice = deviceList[0];
console.log(firstDevice);
if (firstDevice) {
const usbSerialDevice = await usbs.openDeviceAsync(firstDevice);
console.log(usbSerialDevice);
}
} catch (err) {
console.warn(err);
}
}
getDeviceAsync();