react-native-urovo-rfid
v1.0.0
Published
DTP50P React Native
Maintainers
Readme
React Native Urovo RFID & Scanner
A robust library for native integration with Urovo data collectors (DT50, RT40 Series, etc.). It provides full control over the UHF RFID radio module and the Barcode Scanner (Laser), allowing for power adjustments, reading modes, and physical trigger interception.
Installation
Install the library directly from GitHub:
npm install git+https://github.com/rafaax/react-native-urovo-rfid.gitMandatory Requirement (Urovo SDK)
Due to copyright issues, Urovo's proprietary drivers are not included in the public repository. You need to provide them:
- Obtain the files
URFIDLibrary-vX.aarandurovo_platform_sdk_vX.jarfrom your supplier. - Create a
libsfolder insidenode_modules/react-native-urovo-rfid/android/and paste both files there. - In your main application, open
android/app/build.gradleand add the following line inside thedependenciesblock:
dependencies {
// ... other dependencies
implementation files("../../node_modules/react-native-urovo-rfid/android/libs/URFIDLibrary-v2.5.1230.aar")
}API Reference: UHF RFID
Import the RFID module in your code:
import { UrovoRfidNative } from 'react-native-urovo-rfid';Available Methods
| Method | Parameters | Return | Description |
|--------|------------|---------|-----------|
| initAntenna() | None | Promise<boolean> | Turns on the RFID board and initializes serial communication. Should be called when opening the app. |
| setPower(power) | power: number (0 to 30) | Promise<boolean> | Sets the antenna power. 0 for short distances, 30 for long distances. |
| setBeep(isEnable) | isEnable: boolean | Promise<boolean> | Enables/Disables the native motherboard beep when reading a TAG. |
| startInventory() | None | Promise<boolean> | Starts continuous reading of multiple TAGs. |
| stopInventory() | None | Promise<boolean> | Stops reading TAGs. |
| startRadar(epc) | epc: string | Promise<boolean> | Starts search mode. Beeps faster and returns RSSI the closer it gets to the TAG. |
| stopRadar() | None | Promise<boolean> | Stops search mode. |
API Reference: Scanner (Laser)
Import the Scanner module in your code:
import { UrovoScannerNative } from 'react-native-urovo-rfid';Available Methods
| Method | Parameters | Return | Description |
|--------|------------|---------|-----------|
| setScannerTriggerMode(mode) | mode: 'HOST' \| 'CONTINUOUS' \| 'PULSE' | Promise<boolean> | Changes the trigger behavior for the barcode reader. |
HOST: Default. Hold the button to keep the laser on. Release to turn it off.PULSE: Toggle. Press the button once and release, the laser stays on until it reads something.CONTINUOUS: Hands-free. The laser stays on continuously.
Listening to Hardware Events
The library triggers native events in real-time to Javascript. Use React Native's DeviceEventEmitter to listen to them:
import { useEffect } from 'react';
import { DeviceEventEmitter } from 'react-native';
useEffect(() => {
// 1. Listen for Read TAGs
const rfidListener = DeviceEventEmitter.addListener('onRfidRead', (epc) => {
console.log("Read TAG: ", epc);
});
// 2. Listen to Signal Strength (For Radar/Search mode)
const radarListener = DeviceEventEmitter.addListener('onRadarRssi', (rssi) => {
console.log("Target TAG signal strength: ", rssi); // from 0 to ~100
});
// 3. Listen to Physical Trigger (Collector's Yellow Button)
const triggerListener = DeviceEventEmitter.addListener('onHardwareTrigger', (isDown) => {
if (isDown === 'true') {
console.log("Finger pressed the trigger!");
// UrovoRfidNative.startInventory()
} else {
console.log("Finger released the trigger!");
// UrovoRfidNative.stopInventory()
}
});
return () => {
rfidListener.remove();
radarListener.remove();
triggerListener.remove();
};
}, []);Complete Usage Example (Custom Hook)
For the best experience, we recommend isolating the logic into a Custom Hook. Here is a practical example of implementing Power Control with debounce:
import { useEffect, useRef } from 'react';
import { DeviceEventEmitter } from 'react-native';
import { UrovoRfidNative } from 'react-native-urovo-rfid';
export const useUrovo = (power = 30) => {
const isReading = useRef(false);
useEffect(() => {
// Turns on the antenna when opening the app
UrovoRfidNative.initAntenna().catch(console.error);
}, []);
useEffect(() => {
// Updates power in real-time (with debounce to prevent freezing the serial port)
const timer = setTimeout(() => {
UrovoRfidNative.setPower(power).catch(console.error);
}, 500);
return () => clearTimeout(timer);
}, [power]);
useEffect(() => {
const trigger = DeviceEventEmitter.addListener('onHardwareTrigger', (isDown) => {
if (isDown === 'true') {
UrovoRfidNative.startInventory();
} else {
UrovoRfidNative.stopInventory();
}
});
return () => trigger.remove();
}, []);
};