Sample Application for ASK UCM108 RFID reader
This sample application illustrates how to use the ASK UCM108 RFID reader on Coppernic devices.
Coppernic uses a Maven repository to provide libraries.
In the build.gradle, at project level, add the following lines:
allprojects {
repositories {
maven { url "https://nexus.coppernic.fr/repository/libs-release" }
}
}
The javadoc for CpcAsk can be found here.
CpcCore is the library responsible for power management.
In your build.gradle file, at module level, add the following lines:
implementation 'fr.coppernic.sdk.core:CpcCore:2.1.12'
First, implement PowerNotifier:
public class MainActivity extends AppCompatActivity implements PowerListener
...
@Override
public void onPowerUp(CpcResult.RESULT result, Peripheral peripheral) {
// reader instantiation
Reader.getInstance(this, this);
}
@Override
public void onPowerDown(CpcResult.RESULT result, Peripheral peripheral) {
enableUiAfterReaderInstantiation(false);
}
Then register it in Power API, in onCreate for example:
PowerManager.get().registerListener(this);
Use the on/off methods:
if (isChecked) {
if (OsHelper.isAccess()) {
AccessPeripheral.RFID_ASK_UCM108_GPIO.on(MainActivity.this);
} else {
ConePeripheral.RFID_ASK_UCM108_GPIO.on(MainActivity.this);
}
} else {
if (OsHelper.isAccess()) {
AccessPeripheral.RFID_ASK_UCM108_GPIO.off(MainActivity.this);
} else {
ConePeripheral.RFID_ASK_UCM108_GPIO.off(MainActivity.this);
}
}
Finally, release it:
PowerManager.get().unregisterAll();
PowerManager.get().releaseResources();
CpcAsk manages the ASK UCM108 RFID reader:
implementation 'fr.coppernic.sdk.ask:CpcAsk:4.0.2'
First declare a Reader object:
private Reader reader;
Then instantiate it:
Reader.getInstance(this, this);
Where your activity implements InstanceListener:
@Override
public void onCreated(Reader reader) {
this.reader = reader;
}
@Override
public void onDisposed(Reader reader) {
}
On a C-One and Access-ER ASK, by default baudrate is 115200 bauds:
reader.cscOpen(ASK_READER_PORT, 115200, false);
StringBuilder sb = new StringBuilder();
reader.cscVersionCsc(sb);
Reader is fully initialized.