npm package: @simplymobile/capacitor-zebra-rfid
Description: Use Zebra's API3 to read data from RFID.
Author: SimplyMobile
Latest version: 8.0.3

# @simplymobile/capacitor-zebra-rfid

Use Zebra's API3 to read TagId and locate it using RFID.
Tested on MC3300X.

## Install

```bash
npm install @simplymobile/capacitor-zebra-rfid
npx cap sync
```

Update your `android\app\build.gradle` file to include the following:

```aiignore
dependencies {
    ...
    implementation fileTree(include: ['*.aar'], dir: 'libs')
    ...
}
```

Plugin automatically copies the required native libraries to your Android project after running `npx cap sync`.

## API

<docgen-index>

* [`connectToReader()`](#connecttoreader)
* [`disconnectFromReader()`](#disconnectfromreader)
* [`isConnected()`](#isconnected)
* [`getReadersInfo()`](#getreadersinfo)
* [`getReaderModel()`](#getreadermodel)
* [`startScanning()`](#startscanning)
* [`startLocatingTag(...)`](#startlocatingtag)
* [`stop()`](#stop)
* [`getCurrentMode()`](#getcurrentmode)
* [`addListener('onTagRead', ...)`](#addlistenerontagread-)
* [`addListener('onTagProximity', ...)`](#addlistenerontagproximity-)
* [`addListener('triggerState', ...)`](#addlistenertriggerstate-)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
* [Enums](#enums)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### connectToReader()

```typescript
connectToReader() => Promise<ConnectedState>
```

**Returns:** <code>Promise&lt;<a href="#connectedstate">ConnectedState</a>&gt;</code>

--------------------


### disconnectFromReader()

```typescript
disconnectFromReader() => Promise<ConnectedState>
```

**Returns:** <code>Promise&lt;<a href="#connectedstate">ConnectedState</a>&gt;</code>

--------------------


### isConnected()

```typescript
isConnected() => Promise<ConnectedState>
```

**Returns:** <code>Promise&lt;<a href="#connectedstate">ConnectedState</a>&gt;</code>

--------------------


### getReadersInfo()

```typescript
getReadersInfo() => Promise<ReadersInfo>
```

**Returns:** <code>Promise&lt;<a href="#readersinfo">ReadersInfo</a>&gt;</code>

--------------------


### getReaderModel()

```typescript
getReaderModel() => Promise<getReaderModel>
```

**Returns:** <code>Promise&lt;<a href="#getreadermodel">getReaderModel</a>&gt;</code>

--------------------


### startScanning()

```typescript
startScanning() => Promise<ScanningState>
```

**Returns:** <code>Promise&lt;<a href="#scanningstate">ScanningState</a>&gt;</code>

--------------------


### startLocatingTag(...)

```typescript
startLocatingTag(options: LocateOptions) => Promise<ScanningState>
```

| Param         | Type                                                    |
| ------------- | ------------------------------------------------------- |
| **`options`** | <code><a href="#locateoptions">LocateOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#scanningstate">ScanningState</a>&gt;</code>

--------------------


### stop()

```typescript
stop() => Promise<StopResult>
```

**Returns:** <code>Promise&lt;<a href="#stopresult">StopResult</a>&gt;</code>

--------------------


### getCurrentMode()

```typescript
getCurrentMode() => Promise<ScanningState>
```

**Returns:** <code>Promise&lt;<a href="#scanningstate">ScanningState</a>&gt;</code>

--------------------


### addListener('onTagRead', ...)

```typescript
addListener(eventName: 'onTagRead', listenerFunc: (tagData: TagData) => void) => Promise<PluginListenerHandle>
```

| Param              | Type                                                              |
| ------------------ | ----------------------------------------------------------------- |
| **`eventName`**    | <code>'onTagRead'</code>                                          |
| **`listenerFunc`** | <code>(tagData: <a href="#tagdata">TagData</a>) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onTagProximity', ...)

```typescript
addListener(eventName: 'onTagProximity', listenerFunc: (tagData: TagProximity) => void) => Promise<PluginListenerHandle>
```

| Param              | Type                                                                        |
| ------------------ | --------------------------------------------------------------------------- |
| **`eventName`**    | <code>'onTagProximity'</code>                                               |
| **`listenerFunc`** | <code>(tagData: <a href="#tagproximity">TagProximity</a>) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('triggerState', ...)

```typescript
addListener(eventName: 'triggerState', listenerFunc: (state: TriggerState) => void) => Promise<PluginListenerHandle>
```

| Param              | Type                                                                      |
| ------------------ | ------------------------------------------------------------------------- |
| **`eventName`**    | <code>'triggerState'</code>                                               |
| **`listenerFunc`** | <code>(state: <a href="#triggerstate">TriggerState</a>) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### removeAllListeners()

```typescript
removeAllListeners() => Promise<void>
```

--------------------


### Interfaces


#### ConnectedState

| Prop            | Type                 |
| --------------- | -------------------- |
| **`connected`** | <code>boolean</code> |


#### ReadersInfo

| Prop          | Type                        |
| ------------- | --------------------------- |
| **`readers`** | <code>ReaderDevice[]</code> |


#### ReaderDevice

| Prop       | Type                |
| ---------- | ------------------- |
| **`name`** | <code>string</code> |


#### getReaderModel

| Prop                  | Type                |
| --------------------- | ------------------- |
| **`name`**            | <code>string</code> |
| **`model`**           | <code>string</code> |
| **`manufacturer`**    | <code>string</code> |
| **`serialNumber`**    | <code>string</code> |
| **`firmwareVersion`** | <code>string</code> |


#### ScanningState

| Prop       | Type                                                  |
| ---------- | ----------------------------------------------------- |
| **`mode`** | <code><a href="#scanningmode">ScanningMode</a></code> |


#### LocateOptions

| Prop        | Type                |
| ----------- | ------------------- |
| **`tagId`** | <code>string</code> |


#### StopResult

| Prop     | Type                 |
| -------- | -------------------- |
| **`ok`** | <code>boolean</code> |


#### PluginListenerHandle

| Prop         | Type                                      |
| ------------ | ----------------------------------------- |
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


#### TagData

| Prop       | Type                |
| ---------- | ------------------- |
| **`id`**   | <code>string</code> |
| **`rssi`** | <code>number</code> |


#### TagProximity

| Prop            | Type                |
| --------------- | ------------------- |
| **`id`**        | <code>string</code> |
| **`proximity`** | <code>number</code> |


#### TriggerState

| Prop            | Type                 |
| --------------- | -------------------- |
| **`pressed`**   | <code>boolean</code> |
| **`errorCode`** | <code>string</code>  |


### Enums


#### ScanningMode

| Members        | Value                 |
| -------------- | --------------------- |
| **`SCANNING`** | <code>'scan'</code>   |
| **`LOCATING`** | <code>'locate'</code> |

</docgen-api>

## Example usage

```typescript
@Injectable({
  providedIn: 'root',
})
export class RFIDService {
  public async init(): Promise<void> {
    await this.configScanner();
  }

  public async destroy(): Promise<void> {
    await ZebraRfid.removeAllListeners();
    await ZebraRfid.disconnectFromReader();
  }

  public async locateTag(tagId: string): Promise<void> {
    await ZebraRfid.startLocatingTag({ tagId });
  }

  public async scanForNewTags(): Promise<void> {
    await ZebraRfid.startScanning();
  }

  public async getReaderMode(): Promise<void> {
    const result = await ZebraRfid.getCurrentMode();
     console.log('current mode', result.mode);
  }

  private async configScanner(): Promise<void> {
    const res = await ZebraRfid.connectToReader();
    await ZebraRfid.startScanning();

    await ZebraRfid.addListener('triggerState', async (data) => {
      console.log('is trigger pressed', data.pressed);
      if (data.errorCode != null) {
        console.warn(`Error accessing reader: ${data.errorCode}`);
      }
    });

    await ZebraRfid.addListener('onTagRead', (data) => {
      console.log('found new tag', data.id);
    });

    await ZebraRfid.addListener('onTagProximity', (data) => {
       console.log(`proximity to tag: ${data.id}`, data.proximity);
    });
  }
}
```

## Changelog

### 7.1.2

- Fix errors


### 7.1.1

- Fix `disconnectFromReader`

### 7.1.0

- Restructured plugin, added option to locate TAG

### 7.0.3

- Fix running on a non-Zebra device

### 7.0.2

- Added script to copy libs folder
- Updated README with instructions for Android build

### 7.0.1

- Fixed missing libs folder

### 7.0.0

- Initial release