Giter VIP home page Giter VIP logo

c72-rfid-scanner's Introduction

c72-rfid-scanner

Getting started

$ npm install c72-rfid-scanner --save

Mostly automatic installation

$ react-native link c72-rfid-scanner

Usage

import C72RfidScanner from "c72-rfid-scanner";
const App = () => {


  const [isReading, setIsReading] = React.useState();

  const [powerState, setPowerState] = React.useState('');

  const [tags, setTags] = React.useState([]);

  const showAlert = (title, data) => {
    Alert.alert(
      title,
      data,
      [
        { text: 'OK', onPress: () => console.log('OK Pressed') },
      ],
      { cancelable: false },
    );
  }

  const powerListener = (data) => {
    //console.log(data);
    setPowerState(data);
  }

  const tagListener = (data) => {
    //rssi = data[1] epc = data[0] //Iam only interested in the EPC tag
    setTags(tags => tags.concat(data[0]));
  }

  React.useEffect(() => {
    const scanner = C72RFIDScanner;
    scanner.initializeReader();
    scanner.powerListener(powerListener);
    scanner.tagListener(tagListener);
    return () => scanner.deInitializeReader();
  }, []);

  const readPower = async () => {
    try {
      let result = await C72RFIDScanner.readPower();
      showAlert('SUCCESS', `The result is ${result}`);
      console.log(result);
    } catch (error) {
      showAlert('FAILED', error.message);
    }
  }

  const scanSingleTag = async () => {
    try {
      let result = await C72RFIDScanner.readSingleTag();
      showAlert('SUCCESS', `The result is ${result}`);
      console.log(result);
    } catch (error) {
      showAlert('FAILED', error.message);
    }
  }

  const startReading = () => {
    C72RFIDScanner.startReadingTags(function success(message) {
      setIsReading(message);
    })
  }

  const stopReading = () => {
    C72RFIDScanner.stopReadingTags(function success(message) {
      setIsReading(false);
    });

    /**
     * When I stop scanning I immediately return the tags in my state 
     * (You could render a view or do whatever you want with the data)
     */
    console.log(tags);
  }

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>

      <View>
        <Text>{powerState}</Text>
      </View>

      <View style={{ marginVertical: 20 }}>
        <Button style={{ margin: 10 }} onPress={() => readPower()} title='Read Power' />
      </View>

      <View style={{ marginVertical: 20 }}>
        <Button style={{ margin: 10 }} onPress={() => scanSingleTag()} title='Read Single Tag' />
      </View>

      <View style={{ marginVertical: 20 }}>
        <Button disabled={isReading} style={{ margin: 10 }} onPress={() => startReading()} title='Start Bulk Scan' />
      </View>

      <View style={{ marginVertical: 20 }}>
        <Button disabled={!isReading} style={{ margin: 10 }} onPress={() => stopReading()} title='Stop Bulk Scan' />
      </View>

    </View>
  );

}

export default App;

c72-rfid-scanner's People

Contributors

dependabot[bot] avatar paulobunga avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

c72-rfid-scanner's Issues

Attempt to invoke virtual method 'java.lang.String com.rscja.deviceapi.entity.UHFTAGInfo.getEPC()' on a null object reference

"react-native": "0.71.3"

Test Android device is Google Pixel 6 (Android 13)

I don't have the c72 device yet, but I want to test it can be work first.
I use sample code will show the error.

If click fun scanSingleTag show error:
Attempt to invoke virtual method 'java.lang.String com.rscja.deviceapi.entity.UHFTAGInfo.getEPC()' on a null object reference

on a null object reference means it can be work ? Or just because I don't have the c72 device for testing ?

Here is part of the code from sample code:

import C72RfidScanner from 'c72-rfid-scanner';

  useEffect(() => {
    const scanner = C72RfidScanner;
    scanner.initializeReader();
    scanner.powerListener(powerListener);
    scanner.tagListener(tagListener);
    return () => scanner.deInitializeReader();
  }, []);

  const scanSingleTag = async () => {
    try {
      let result = await C72RfidScanner.readSingleTag();
      showAlert('SUCCESS', `The result is ${result}`);
      console.log(result);
    } catch (error) {
     // show object is null error
      console.log(error.message);
      showAlert('FAILED', error.message);
    }
  };

  return (
        <View style={{marginVertical: 20}}>
            <Button
              style={{margin: 10}}
              onPress={() => scanSingleTag()}
              title="Read Single Tag"
            />
          </View>
  );

Here is what I try step flow:

Step1:
Can't install the package.

npm install c72-rfid-scanner --save

It will show error
ERESOLVE unable to resolve dependency tree

截圖 2023-02-22 下午6 42 56

Step2:
If use yarn

yarn add c72-rfid-scanner

build the project on Android will show error

Plugin with id 'maven' not found.

then change the code apply plugin: 'maven' to apply plugin: 'maven-publish'
on node_modules/c72-rfid-scanner/android/build.gradle

build the project will show error

A problem occurred configuring project ':c72-rfid-scanner'.
> Configuration with name 'compile' not found.

Step3:
then paste the code subprojects on android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    subprojects { subproject ->
        if(project['name'] == 'c72-rfid-scanner'){    
            project.configurations { compile { } }
    }
}
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

build project will show error
Could not find method mavenDeployer() for arguments

Step4:
commented out the code on node_modules/c72-rfid-scanner/android/build.grade

task installArchives(type: Upload) {
    configuration = configurations.archives
    repositories.mavenDeployer {
        // Deploy to react-native-event-bridge/maven, ready to publish to npm
        repository url: "file://${projectDir}/../android/maven"
        configureReactNativePom pom
    }
}

then build the project successfully and test the code.

Issue while reading Tag

i have this issue while reading a Tag. I don't know if the repo is still maintained, but here's the error i'm getting:

[Error: Attempt to invoke virtual method 'java.lang.String com.rscja.deviceapi.entity.UHFTAGInfo.getEPC()' on a null object reference]

Looking for android api handbook for c72

Hello, I'm working as a flutter developer, I can't find handbook with andorid API for this device, containing Strings with Intents and actions, to send messages between my flutter app and native-code barcode plugin.
I saw you did repo with RFID for this device but java code is JARed. maybe you could share handbook if you have one please?
I asked Chainway themself, but they provided full java doc with chineese comments for whole their scanners code, can't really find what I'm looking for..

Can't find variable: C72RfidScanner

I followed both the below commands:

$ npm install c72-rfid-scanner --save

$ react-native link c72-rfid-scanner

When I run the app after build, it gives an error "Can't find variable: C72RfidScanner".

startReading(), stopReading()

Thank you for creating this repo,
I followed the process Usage when i click startReading() i got False, and stopReading i got 0.

Thank you
Screen Shot 2020-05-04 at 11 36 18 AM

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency eslint to v8.57.0
  • Update dependency @tsconfig/react-native to v3
  • Update dependency eslint to v9
  • Update dependency prettier to v3
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

gradle
android/build.gradle
  • com.android.tools.build:gradle 7.2.1
npm
package.json
  • @babel/core ^7.20.0
  • @babel/preset-env ^7.20.0
  • @babel/runtime ^7.20.0
  • @react-native-community/eslint-config ^3.2.0
  • @tsconfig/react-native ^2.0.2
  • @types/jest ^29.2.1
  • @types/react ^18.0.24
  • @types/react-test-renderer ^18.0.0
  • babel-jest ^29.2.1
  • eslint ^8.19.0
  • jest ^29.2.1
  • metro-react-native-babel-preset 0.75.0
  • prettier ^2.4.1
  • react-test-renderer 18.2.0
  • typescript 4.9.5
  • react 18.2.0
  • react-native 0.71.3

  • Check this box to trigger a request for Renovate to run again on this repository

Lock Tag

Hello Mr. @paulobunga
I want to implement lock RFID tag functionality but facing issues
here is my code :
@ReactMethod
public void uhfBlockPermalock(String targetEpc,String pwdStr, final Promise promise) {
// epc += password;
// epc += "00000000"; //old
// Access Password, Bank Enum (EPC(1), TID(2),...), Pointer, Count, Data
//Boolean uhfWriteState = mReader.writeData_Ex("00000000", BankEnum.valueOf("UII"), 2, 6, epc);
// boolean result=mContext.mReader.uhfBlockPermalock(pwdStr,filter_bank,filter_ptr,filter_len,filter_data,readLock,bank,prt,uRange,mastBuff);
// targetEpc += pwdStr;

    try {

        byte[] maskBytes = StringUtility.hexString2Bytes(targetEpc);

        Boolean result=mReader.uhfBlockPermalock(pwdStr,IUHF.Bank_EPC,0,0,targetEpc,1,IUHF.Bank_EPC,2,1,maskBytes); //,readLock,bank,prt,uRange,mastBuff
        // Boolean result=mReader.lockMem(targetEpc,1,2,3,pwdStr,""); 

        promise.resolve(result);
        // Log.d("UHF_SCANNER", String.valueOf(uhfPower));

    } catch (Exception ex) {
        Log.d("UHF_SCANNER", ex.getLocalizedMessage());
        promise.reject(UHF_READER_OTHER_ERROR, ex.getLocalizedMessage());
    }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.