This application illustrates how to use the HID HF RFID reader on Coppernic C-One device.
The full documentation for HID HF reader can be found here.
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'}
}
}
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.4.0'
- Implements power listener
public class MainActivity extends AppCompatActivity implements PowerListener {
// [...]
@Override
public void onPowerUp(RESULT res, Peripheral peripheral) {
if (res == RESULT.OK) {
//Peripheral is on
} else {
//Peripehral is undefined
}
}
@Override
public void onPowerDown(RESULT res, Peripheral peripheral) {
//Peripheral is off
}
// [...]
}
- Register the listener
@Override
protected void onCreate(Bundle savedInstanceState) {
PowerManager.get().registerListener(this);
}
- Power reader on
// Powers on HID HF reader
ConePeripheral.RFID_HID_MULTIISO_GPIO.on(context);
// The listener will be called with the result
- Power off when you are done
// Powers off HID HF reader
ConePeripheral.RFID_HID_MULTIISO_GPIO.off(context);
// The listener will be called with the result
- release resources
@Override
protected void onStop() {
PowerManager.get().unregisterAll();
PowerManager.get().releaseResources();
super.onDestroy();
}
Use the SerialCom class in CpcCore.
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) {
}
First open the serialCom object:
serialCom.open(SERIAL_PORT, getBaudrate());
where:
private static final String SERIAL_PORT = "/dev/ttyHSL1";
Then send commands:
byte[] command;
...
serialCom.send(command, command.length);
When powered up, reader is in continuous read mode. Before being able to use it, disable continuous read mode by sending a simple command:
private static final byte[] ABORT_CONTINUOUS_READ_COMMAND = new byte[]{'.'};
serialCom.send(ABORT_CONTINUOUS_READ_COMMAND, ABORT_CONTINUOUS_READ_COMMAND.length);