This module allows reading NFC tags using a serial connection to an RFID reader.
npm install nfc-box-readerThis module allows reading NFC tags using a serial connection to an RFID reader.
To install run:
``bash`
pnpm add nfc-box-reader
or
`bash`
npm install nfc-box-reader
or
`bash`
yarn add nfc-box-reader
NFC serial reader module provides the following API:
This connects to the NFC 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.
`typescript
import { connectNFCSerialReader } from "nfc-box-reader";
const connected = await connectNFCSerialReader("/dev/ttyS0", 9600);
`
> Note: This function should be called after connectNFCSerialReader has been called.
This adds a listener to the NFC reader, the listener will be called every time a new tag is read.
`typescript
import { addNFCReadListener } from "nfc-box-reader";
addNFCReadListener((card) => {
console.log(Card Type: ${card.cardType});Card ID: ${card.cardId}
console.log();`
});
The payload of the listener is an object with the following properties:
- cardType: The type of the card, this is either "TAG" and "WORKER". These are the only twocardId
supported card types, if the card type is not one of these two values, then the card type
is returned as "UNKNOWN".
- : The ID of the card which is an integer value.
This returns a function that can be called to remove the listener.
This disconnects the NFC reader, stops reading and returns a boolean indicating if the
disconnection was successful.
`typescript
import { disconnectNFCSerialReader } from "nfc-box-reader";
const disconnected = await disconnectNFCSerialReader();
`
This returns a list of available serial ports on the device (the options that can be passed to
connectNFCSerialReader).
`typescript
import { listSerialPorts } from "nfc-box-reader";
const ports = await listSerialPorts();
`
This returns a list of available baud rates that can be passed to connectNFCSerialReader.[9600, 19200, 38400, 57600, 115200]
The baud rates are hardcoded to the following values: .
`typescript
import { listBaudRates } from "nfc-box-reader";
const baudRates = listBaudRates();
``