IDCardReader API
Installation
npm install @cutos/core
npm install @cutos/devices
Import dependencies
import {CoreAPI} from '@cutos/core';
import {DeviceIDCardReader} from '@cutos/devices';
DeviceIDCardReader
Constructor, create ID card instance
var devIDCardReader = new DeviceIDCardReader();
DeviceIDCardReader.init
ID card reader initialization
devIDCardReader.init(callback);
- callback: callback function
Example:
devIDCardReader.init((result, error) => {
if (!error) {
console.log('onDeviceCreate', result)
} else {
console.log(error)
}
});
- Return result example:
Driver device-id-card-reader loaded
DeviceIDCardReader.connect
Connect ID card reader
devIDCardReader.connect(callback);
- callback: callback function
Example:
devIDCardReader.connect((result) => {
if (result.status) {
console.log('connect success:', result)
} else {
console.log('connect failed:', result.msg)
}
});
DeviceIDCardReader.disconnect
Disconnect ID card reader
devIDCardReader.disconnect();
DeviceIDCardReader.startRead
The card reader starts searching for the card
devIDCardReader.startRead([image], callback);
- image: optional parameter, whether to read the ID card photo, the default is false. true means read, false means not read.
- callback: callback function
Example:
devIDCardReader.startRead(result => console.log(result))
- Return result example:
{
"status": true,
"msg": "reading"
}
DeviceIDCardReader.readDeviceInfo
Read ID card reader device information
devIDCardReader.readDeviceInfo(callback);
- callback: callback function
Example:
devIDCardReader.readDeviceInfo(result => {
console.log('device info:', result)
})
- Return result example:
{
"status": true,
"msg": {
"SAMID": "5-3-20220810-11478877-3979136230"
}
}
DeviceIDCardReader.onData
Receive ID card information
devIDCardReader.onData(callback)
- callback: callback function
Example:
devIDCardReader.onData((data) => {
console.log('data', data)
})
- Return result example:
{
"code": 110111201607101234,
"name": "Si Pu",
"sex": "Male",
"birthday": 20160710,
"address": "No. 1705, Beihuan Center, No. 18 Yumin Road, Xicheng District, Beijing",
"nation": "China",
"department": "Xicheng District, Beijing",
"startDate": 20160710,
"endDate": 20260710,
"certType": "ID card"
}