Skip to content

hid_hf_external_integration

benoistlaforge edited this page Oct 18, 2017 · 1 revision

hidhfsample: external integration

Introduction

This application illustrates how to use the HID HF RFID reader on Coppernic C-One device using a snap-on.

The libraries

Coppernic uses a Maven repository to provide libraries.

In the build.gradle, at project level, add the following lines:

allprojects {
    repositories {                
        maven { url 'https://artifactory.coppernic.fr/artifactory/libs-release'}
    }
}

The basics

Power management

Libraries

CpcCore is the library responsible for power management.

In your build.gradle file, at module level, add the following lines:

compile 'fr.coppernic.sdk.core:CpcCore:1.0.0'

Power on/off RFID reader

Power on/off the reader is performed using the RTS signal of the serial port created. It will be done after open command.

Reader initialization

Libraries

Use the SerialCom class in CpcCore.

Create SerialCom object

First declare a SerialCom object:

private SerialCom serialCom;

Then instantiate it:

SerialFactory.getDirectInstance(this, this);

Where your activity implements InstanceListener:

@Override
public void onCreated(SerialCom serialCom) {
    // Serial instance is obtained
    this.serialCom = serialCom;      
}

@Override
public void onDisposed(SerialCom serialCom) {

}

Open reader and send commands

First open the serialCom object:

serialCom.open(SERIAL_PORT, getBaudrate());
serialCom.setRts(true);

where:

private static final String SERIAL_PORT = "/dev/ttyUSB0";

Then send commands:

byte[] command;
...
serialCom.send(command, command.length);

Initialization

When powered up, reader is in continuous read mode. Before being able to use it, disable contiunous read mode:

private static final byte[] ABORT_CONTINUOUS_READ_COMMAND = new byte[]{'.'};
serialCom.send(ABORT_CONTINUOUS_READ_COMMAND, ABORT_CONTINUOUS_READ_COMMAND.length);