cordova-plugin-ubx-rfid/www/ubx-rfid.js
2023-10-15 15:06:06 +08:00

125 lines
2.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var cordova = require('cordova');
var exec = require('cordova/exec');
var UbxRfid = function () {};
/**
* 读到卡信息EPC/ID时的回调
*
* @param {Object} epc info
*/
UbxRfid.prototype._epcs = function (info) {
if (info) {
cordova.fireWindowEvent('ubxrfid', info);
}
};
/**
* Error callback for error
*/
// UbxRfid.prototype._error = function (e) {
// console.log('Error : ' + e);
// };
/**
* 巡一次卡
*
* @returns 卡信息
*/
UbxRfid.prototype.searchCard = async function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'searchCard', []));
};
/**
* 开始巡卡
*/
UbxRfid.prototype.startSearchCard = async function () {
return new Promise((resolve, reject) => {
exec(ubxRfid._epcs, reject, 'UbxRfid', 'startSearchCard', []);
resolve();
});
};
/**
* 停止巡卡
*/
UbxRfid.prototype.stopSearchCard = async function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'stopSearchCard', []));
};
/**
* 获取天线功率
*
* @returns 天线功率
*/
UbxRfid.prototype.getPower = async function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'getPower', []));
};
/**
* 设置天线功率
*
* @param {*} data 功率值长距功率范围0-33短距版功率范围0-26
*/
UbxRfid.prototype.setPower = async function (data) {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'setPower', [data]));
};
/**
* 获取巡卡时的间隔
*
* @returns 间隔值,应该在 0-60 之间
*/
UbxRfid.prototype.getScanInterval = async function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'getScanInterval', []));
};
/**
* 设置巡卡间隔
*
* @param {*} data 间隔值,应该在 0-60 之间
*/
UbxRfid.prototype.setScanInterval = async function (data) {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'setScanInterval', [data]));
};
/**
* 获取设备信息
*
* @returns 设备信息
*/
UbxRfid.prototype.getDeviceInfo = async function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'getDeviceInfo', []));
};
/**
* 设置读卡响铃
*/
UbxRfid.prototype.beepOn = async function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'beepOn', []));
};
/**
* 关闭读卡响铃
*/
UbxRfid.prototype.beepOff = async function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'beepOff', []));
};
UbxRfid.prototype.setBeep = async function (data) {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'setBeep', [data]));
};
/**
* 获取是否响铃
*
* @returns 是否响铃
*/
UbxRfid.prototype.getBeep = async function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'UbxRfid', 'getBeep', []));
};
var ubxRfid = new UbxRfid();
module.exports = ubxRfid;