capacitor-cardreader
v0.0.4
Published
Capacitor plugin to integrate PDA card reader SDK
Downloads
15
Readme
capacitor-cardreader
Capacitor plugin to integrate PDA card reader SDK (via serial port and GPIO).
Install
npm install capacitor-cardreader
npx cap syncUsage
import { Cardreader } from 'capacitor-cardreader';
// Initialize the reader
const result = await Cardreader.initReader();
if (result.success) {
console.log('Reader initialized');
} else {
console.error('Failed to initialize:', result.message);
}
// Listen for card reads
const listener = await Cardreader.addListener('cardRead', (data: { cardId: string }) => {
console.log('Card detected:', data.cardId);
});
// Send raw command (optional, low-level)
const response = await Cardreader.sendCommand({ command: 'AA' });
console.log('Response:', response);
// Destroy the reader
await Cardreader.destroyReader();
await listener.remove();API
initReader()
initReader() => Promise<{ success: boolean; message?: string }>Initializes the PDA card reader hardware and starts the background reading loop.
Returns:
success: whether initialization was successfulmessage: optional error message
destroyReader()
destroyReader() => Promise<void>Stops the reading loop, closes the serial port, and powers down the device.
sendCommand(...)
sendCommand(options: { command: string }) => Promise<{ response: string }>Send a raw hex command directly to the reader (advanced usage).
| Param | Type |
| ------------- | ----------------------------------- |
| options | { command: string } |
Returns: { response: string }
Listener: cardRead
Cardreader.addListener('cardRead', (data: { cardId: string }) => {
console.log('Card UID:', data.cardId);
});Fires whenever a card is detected by the reader.
cardId: hex string representing the card UID.
Notes
- Currently only Android is supported (PDA devices with serial
/dev/ttyS0). - Web and iOS implementations are stubs and return "Not available".
- Make sure your project’s
minSdkVersionis set to 23 or higher.
Changelog
- 0.0.2 – First working Android version with
initReader,destroyReader,sendCommand, andcardReadlistener. - 0.0.1 – Initial Capacitor plugin scaffold.
