Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

c72-rfid-scanner

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

c72-rfid-scanner

Chainway C72 RFID UHF Barcode Scanner

  • 1.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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;

Keywords

FAQs

Package last updated on 24 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc