2.0.2 • Published 5 years ago
react-native-rfid-connector v2.0.2
React-native-rfid-connector
This library helps us listen to the state of Bluetooth and connect it with an RFID reader device. Get data from RFID TAG
Getting started
$ npm install react-native-rfid-connector --save
or
$ yarn add react-native-rfid-connector
Mostly automatic installation
If using react-native < 0.60
$ react-native link react-native-rfid-connector
Usage
import RfidConnector from 'react-native-rfid-connector';
componentDidMount() {
RfidConnector.getCurrentState().then(this.handleConnection)
}
componentWillMount() {
RfidConnector.addEventListener('change', this.handleConnection);
}
componentWillUnmount() {
RfidConnector.removeEventListener('change', this.handleConnection)
}
handleConnection = (resp) => {
const {type} = resp;
switch(type){
case 'BLT_STATE_CHANGE':
//resp: { type:BLT_STATE_CHANGE, status:"on"}
this.setState({connectionState:resp.status});
break;
case 'BLT_DISCOVERY_STARTED':
//resp: { type:"BLT_DISCOVERY_STARTED"}
break;
case 'BLT_DISCOVERY_DEVICE':
//resp: { type:"BLT_DISCOVERY_DEVICE", device_info: {device_address: "6C:40:08:AA:F2:0B", device_name: "Hangnta"}}
const newList = [...this.state.listDevice,resp.device_info];
this.setState({listDevice:newList})
break;
case 'BLT_DISCOVERY_DEVICE_FINISH':
//resp: { type:"BLT_DISCOVERY_DEVICE_FINISH"}
break;
case 'DOTR_EVENT':
//resp: { type:"DOTR_EVENT",status:"",data: any}
break;
}
Start Scan bluetooth devices:
RfidConnector.startScanBlueTooth().then(rsp=>{
console.log("scan rsp",rsp);
}).catch(err=>console.log("err",err));
Stop Scan bluetooth devices:
RfidConnector.stopScanBlueTooth().then(rsp=>{
console.log("stop scan",rsp);
}).catch(err=>console.log("err",err));
Filter bluetooth devices with prefix name:
RfidConnector.setListFilterBlueToothPrefix(["HQ_UHF_READER","TSS91JJ-","DOTR2100-","DOTR2200-","TSS2100","TSS2200","DOTR3100","DOTR3200","TSS3100","TSS3200"]);
Connect to specific devices address to read tag:
RfidConnector.connectToDevice("device address");
Disconnect to current device:
RfidConnector.disConnectToDevice().then(msg=>console.log(msg)).catch(err=>console.log(err));
List status of DOTR_EVENT
:
- onConnected
- onDisconnected
- onLinkLost
- onTriggerChaned
- onInventoryEPC
- onReadTagData
- onWriteTagData
- onUploadTagData
- onTagMemoryLocked
- onScanCode
- onScanTriggerChanged
In this document we will focus on onReadTagData
. This status will receive when we found any RFIDTAG.Structure response form event listener like this:
{
type:"DOTR_EVENT",
status:"onReadTagData",
data:{
tagData:"000",
epc:"100001"
}
}