@cutos/devices
v3.2.6
Published
CUTOS Devices API is a JavaScript library that provides a unified interface for accessing and controlling hardware devices. Developers can use this interface to send and receive data, configure device parameters, and handle device events.
Downloads
60
Readme
Introduction
CUTOS Devices API is a JavaScript library that provides a unified interface for accessing and controlling hardware devices. Developers can use this interface to send and receive data, configure device parameters, and handle device events.
Devices and drivers communicate for data transmission, command reception, and status updates. Heartbeat monitoring is implemented for drivers to ensure continuous communication.
Table of Contents
Printer API
Installation
npm install @cutos/core
npm install @cutos/devices
Import dependencies
import {CoreAPI} from '@cutos/core';
import {DevicePrinter, PrinterCMD} from '@cutos/devices';
DevicePrinter
Constructor, create a printer instance
let devPrinter = new DevicePrinter();
DevicePrinter.init
Printer initialization
devPrinter.init(callback)
callback: callback function
Example:
devPrinter.init((result, error) => {
if (error) {
console.log(error)
return;
}
console.log(result)
})
- Return result example:
"Driver device-printer loaded"
DevicePrinter.readDeviceInfo
Read printer information
DevicePrinter.readDeviceInfo(callback)
callback: callback function
Example:
DevicePrinter.readDeviceInfo(data => {
console.log(data)
})
- Return result example:
{
"name": "w80",
"shareName": "w80",
"portName": "USB001",
"driverName": "MSW Printer Driver",
"printProcessor": "winprint",
"datatype": "RAW",
"status": [],
"statusNumber": 0,
"attributes": [
"DO-COMPLETE-FIRST",
"LOCAL"
],
"priority": 1,
"defaultPriority": 0,
"averagePPM": 0
}
DevicePrinter.onData
Get printer data
devPrinter.onData(callback)
- callback: callback function
Example:
DevicePrinter.onData(function (data) {
let resp = data.response;
if (!resp.status) {
console.warn('err:', resp.msg);
return;
}
switch (data.cmd) {
case 'print-test': //DevicePrinter.printTestPage(printer);
break
case 'print-pdf-url': //DevicePrinter.printPdfUrl(pdfUrl, printer);
break
}
});
DevicePrinter.printTestPage
Print test page
devPrinter.printTestPage(printer);
- printer: printer name; when this parameter is not passed, the default printer is used for printing.
DevicePrinter.printPdfUrl
Print specified pdf file
devPrinter.printPdfUrl(pdfUrl, printer);
- pdfUrl: URL address. For example: 'https://oss.cut-os.com/resources/developer/examples/printer/print-sample.pdf'
- printer: printer name; when this parameter is not passed, the default printer is used for printing.
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"
}
Fingerprint API
Installation
npm install @cutos/core
npm install @cutos/devices
Import dependencies
import {CoreAPI} from '@cutos/core';
import {DeviceFingerprint} from '@cutos/devices';
DeviceFingerprint
Constructor, create fingerprint device instance
let devFingerprint = new DeviceFingerprint(name);
- name: fingerprint device name
Example:
devFingerprint = new DeviceFingerprint();
DeviceFingerprint.init
Fingerprint initialization
devFingerprint.init(callback);
- callback: callback function
Example:
devFingerprint.init((result, error) => {
if (!error) {
console.log('onDeviceCreate', result)
} else {
console.log(error)
}
});
- Return result example:
Driver device-fingerprint loaded
DeviceFingerprint.connect
Connect fingerprint
DevFingerprint.connect(path, callback);
- path: device port
- callback: callback function
Example:
DevFingerprint.connect('/dev/ttyS1', (result) => {
console.log(result)
});
- Return result example:
{
"status": true,
"msg": "open success"
}
DeviceFingerprint.auth
Fingerprint recognition mode
DevFingerprint.auth(callback)
- callback: callback function
Example:
DevFingerprint.auth((data) => {
console.log('data', data)
})
- Return result example:
{
"status": true,
"msg": "auth mode"
}
DeviceFingerprint.admin
Fingerprint management mode
DevFingerprint.admin(callback)
- callback: callback function
Example:
DevFingerprint.admin((data) => {
console.log(data)
})
- Return result example:
{
"status": true,
"msg": "admin mode"
}
DeviceFingerprint.createUser1
Enter fingerprint step 1
DevFingerprint.createUser1(userID, callback)
- userID: user ID
- callback: callback function
Example:
DevFingerprint.createUser1(1, (data) => {
console.log('data', data)
})
- Return result example:
{
"status": true
}
DeviceFingerprint.createUser2
Enter fingerprint step 2
DevFingerprint.createUser2(userID, callback)
- userID: user ID
- callback: Callback function
Example:
DevFingerprint.createUser2(1, (data) => {
console.log('data', data)
})
- Return result example:
{
"status": true
}
DeviceFingerprint.createUser3
Enter fingerprint step 3
DevFingerprint.createUser3(userID, callback)
- userID: user ID
- callback: callback function
Example:
DevFingerprint.createUser3(1, (data) => {
console.log('data', data)
})
- Return result example:
{
"status": true
}
DeviceFingerprint.deleteUser
Delete user
DevFingerprint.deleteUser(userID, callback)
- userID: user ID
- callback: callback function
Example:
DevFingerprint.deleteUser(1, (data) => {
console.log('data', data)
})
- Return result example:
{
"status": true
}
DeviceFingerprint.onData
Get fingerprint data information
DevFingerprint.onData(callback)
- callback: callback function
Example:
device.onData(data => {
console.log(data)
})
- Return result example:
{
"authorized": 0
}
NFC API
Installation
npm install @cutos/core
npm install @cutos/devices
Import dependencies
import {CoreAPI} from '@cutos/core';
import {DeviceNFC} from '@cutos/devices';
DeviceNFC
Constructor, create NFC device instance
let devNFC = new DeviceNFC(name);
- name: NFC device name
Example:
devNFC = new DeviceNFC('demo-nfc');
DeviceNFC.init
NFC device initialization
devNFC.init(callback);
- callback: callback function
Example:
devNFC.init((result, error) => {
if (!error) {
console.log('onDeviceCreate', result)
} else {
console.log(error)
}
});
DeviceNFC.connect
Connect NFC
devNFC.connect(callback);
- callback: callback function
Example:
devNFC.connect((result) => {
if (result.status) {
console.log('connect success:', result)
} else {
console.log('connect failed:', result.msg)
}
});
DeviceNFC.onData
Receive NFC information
DeviceNFC.onData(callback)
- callback: callback function
Example:
DeviceNFC.onData((data) => {
console.log('data', data)
})
- Return result example:
{
"id": "110111201"
}