UHF RFID reader module through UART interface designed for rk3128_box
device.
To install run:
pnpm add uhf-uart-reader
or
npm install uhf-uart-reader
or
yarn add uhf-uart-reader
This module contains an Expo Config Plugin that will automatically add the changes to gradle configuration files when the module is installed. If you are not using Expo, you will need to manually add the changes to the gradle configuration files.
Add uhf-uart-reader
to the plugins
in app.json
or app.config.ts
:
{
"expo": {
"plugins": ["uhf-uart-reader"]
}
}
Update the minSdkVersion and targetSdkVersion to 21:
Add the following:
...
android {
...
defaultConfig {
...
ndk {
abiFilters "armeabi-v7a", "armeabi"
}
}
}
...
This connects to the UHF reader on the given serial port and specified baud rate, starts reading in the background and returns a boolean indicating if the connection was successful.
import UhfUartReader from "uhf-uart-reader";
const connected = UhfUartReader.connect("/dev/ttyS0");
This sets the power of the UHF reader, the power should be a number between 0 and 100.
import UhfUartReader from "uhf-uart-reader";
UhfUartReader.setPower(50);
Note: This function should be called after
connectUhfReader
has been called.
This adds a listener to the UHF reader, the listener will be called every time a new tag is read.
import UhfUartReader from "uhf-uart-reader";
UhfUartReader.addListener("onRead", (tag) => {
console.log(`Tag EPC: ${tag.epc}`);
});
This returns a function that can be called to remove the listener.
This disconnects the UHF reader, it should be called when the reader is no longer needed.
import UhfUartReader from "uhf-uart-reader";
UhfUartReader.disconnect();
This returns a boolean indicating if the UHF reader is connected.
import UhfUartReader from "uhf-uart-reader";
const connected = UhfUartReader.isConnected();
This returns a list of available serial ports on the device (the options that can be passed to
connectUhfReader
).
import UhfUartReader from "uhf-uart-reader";
const ports = UhfUartReader.listSerialPorts();