This is a library for connect rfid using native module in React Native app
npm install react-native-rfid-connectorThis library helps us listen to the state of Bluetooth and connect it with an RFID reader device. Get data from RFID TAG
$ npm install react-native-rfid-connector --save
or$ yarn add react-native-rfid-connector
If using react-native < 0.60$ react-native link react-native-rfid-connector
javascript
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;
}
`
$3
`javascript
RfidConnector.startScanBlueTooth().then(rsp=>{
console.log("scan rsp",rsp);
}).catch(err=>console.log("err",err));
`$3
`javascript
RfidConnector.stopScanBlueTooth().then(rsp=>{
console.log("stop scan",rsp);
}).catch(err=>console.log("err",err));
`$3
`javascript
RfidConnector.setListFilterBlueToothPrefix(["HQ_UHF_READER","TSS91JJ-","DOTR2100-","DOTR2200-","TSS2100","TSS2200","DOTR3100","DOTR3200","TSS3100","TSS3200"]);
`$3
`javascript
RfidConnector.connectToDevice("device address");
`
$3
`javascript
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
- onScanTriggerChangedIn this document we will focus on
`onReadTagData `. This status will receive when we found any RFIDTAG.Structure response form event listener like this:
`javascript
{
type:"DOTR_EVENT",
status:"onReadTagData",
data:{
tagData:"000",
epc:"100001"
}
}
``