TMRAppBle/script/module/serialport.js

39 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-10-19 15:00:17 +08:00
var serialPortPlus = null
var serialPortUtil = {
initSerial:function(){
serialPortPlus = api.require('serialPortPlus');
},
getAllDevices:function(params){
var ret = serialPortPlus.getAllDevices(params);
return ret;
},
getAllDeicesPath:function(params){
var ret = serialPortPlus.getAllDeicesPath(params);
return ret;
},
addEventListener:function(params,callback){
serialPortPlus.addEventListener(params,function(ret, err) {
callback(ret,err)
});
},
openSerial:function(param,callback){
serialPortPlus.open(param,function(ret, err) {
callback(ret,err)
});
},
send:function(params){
params.data = params.data.replace(/\s+/g,"");
var ret = serialPortPlus.send(params);
return ret
},
closeSerial:function(params){
var ret = serialPortPlus.close(params);
return ret
// console.log(JSON.stringify(ret));
}
}
export {
serialPortUtil
}