electricControl/script/serialPortUtil.js

39 lines
1.0 KiB
JavaScript

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
}