zhaochongyi
2024-08-26 e0301d12be2ba6c04613f23c24734c48a30caad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
    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;
    }
 
    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;
    }
 
}
 
IcrfController.toString = ()=> '[class IcrfController]';
module.exports =IcrfController;