| | |
| | | const {Controller} = require("ee-core"); |
| | | const Ps = require("ee-core/ps"); |
| | | const koffi = require('koffi'); |
| | | const path = require("path"); |
| | | class IcrfController extends Controller{ |
| | | hcicrf =null; |
| | | const Services = require('ee-core/services') |
| | | const {params} = require("debug"); |
| | | |
| | | class IcrfController extends Controller { |
| | | constructor(ctx) { |
| | | super(ctx); |
| | | const dllPath = path.join(Ps.getExtraResourcesDir(),'dll','hc_icrf32.dll'); |
| | | this.hcicrf =koffi.load(dllPath); |
| | | } |
| | | async hc_init(params){ |
| | | const hc_init = this.hcicrf.func('int __stdcall hc_init(short port, uint32_t baud)'); |
| | | let hcInit = hc_init(2, 115200); |
| | | console.log(hcInit); |
| | | if (hcInit <=0){ |
| | | // let errMsg = this.getErrMsg(hcInit); |
| | | //console.log(errMsg) |
| | | } |
| | | return hcInit; |
| | | /** |
| | | * 连接串口读写器 |
| | | * @param {params.number} params.port 端口号, 取值 0 ~ 19, 对应端口 COM1 ~ COM20 |
| | | * @param {params.number} params.baud 波特率, 取值 9600 ~ 115200 |
| | | * @returns {number} 读写器句柄 |
| | | */ |
| | | connectSerialPort(params) { |
| | | return Services.get('icrf').connectSerialPort(params.port,params.baud); |
| | | }; |
| | | |
| | | /** |
| | | * 连接USB读写器 |
| | | * @param params |
| | | * @returns {*} |
| | | */ |
| | | connectUsb(params) { |
| | | return Services.get('icrf').connectUsb(params.number); |
| | | }; |
| | | |
| | | /** |
| | | * 断开读写器 |
| | | * @returns {(function(*, *, ...[*]): {msg: string, code: *})|*} |
| | | */ |
| | | connectExit(){ |
| | | return Services.get('icrf').connectExit(); |
| | | }; |
| | | |
| | | /** |
| | | * 鸣响 |
| | | * @param number 次数 |
| | | */ |
| | | connectBeep(number = 1){ |
| | | Services.get('icrf').beep(); |
| | | } |
| | | /** |
| | | * 开启定时寻卡任务 |
| | | */ |
| | | doJobByPool(){ |
| | | return Services.get('icrf').doJobByPool(); |
| | | } |
| | | |
| | | getErrMsg(st){ |
| | | let getErrMsg = this.hcicrf.func("int getErrMsg(short st,short lg, char errMsg)"); |
| | | let errMsg = getErrMsg(st, 0, 1024); |
| | | console.log(errMsg) |
| | | return errMsg; |
| | | /** |
| | | * 关闭定时寻卡任务 |
| | | * @returns {*} |
| | | */ |
| | | unJobByPool(){ |
| | | return Services.get('icrf').unJobByPool(); |
| | | } |
| | | /** |
| | | * 寻卡 |
| | | */ |
| | | connectRfCard(){ |
| | | return Services.get('icrf').connectRfCard(); |
| | | } |
| | | |
| | | /** |
| | | * 校验密码 |
| | | */ |
| | | connectRfAuthenticationKey(){ |
| | | return Services.get('icrf').connectRfAuthenticationKey(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 读数据 |
| | | */ |
| | | connectRfRead(params){ |
| | | let connectRfAuthenticationKey1 = Services.get('icrf').connectRfAuthenticationKey(params.addr); |
| | | return Services.get('icrf').connectRfRead(params.addr); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 写数据 |
| | | * @param params.data 写入的数据 |
| | | * @param params.addr 写入的区域 3,7,11,15,19密码片区严禁使用 |
| | | */ |
| | | connectRfWrite(params){ |
| | | let connectRfAuthenticationKey1 = Services.get('icrf').connectRfAuthenticationKey(params.addr); |
| | | console.log(connectRfAuthenticationKey1) |
| | | return Services.get('icrf').connectRfWrite(params.data,params.addr); |
| | | } |
| | | |
| | | /** |
| | | * 终止卡(完成所有操作) |
| | | */ |
| | | |
| | | connectRfHalt(){ |
| | | return Services.get('icrf').connectRfHalt(); |
| | | } |
| | | |
| | | } |
| | | |
| | | IcrfController.toString = ()=> '[class IcrfController]'; |
| | | module.exports =IcrfController; |
| | | IcrfController.toString = () => '[class IcrfController]'; |
| | | module.exports = IcrfController; |