|
<script>
export default {
name: "tpl",
apiready() {
var serial = api.require('serialPort');
},
data() {
return {
path:'/dev/ttys1',
device:'',
data:'',
com1:'',
snedText:'020301'
};
},
computed: {
},
methods: {
getDeviceS(){
let that=this;
that.data.device=''
that**.**1.examine(function (ret) {
api.toast({msg: JSON.stringify(ret)});
for (let index = 0; index < ret.data.length; index++) {
const element = ret.data[index];
that.data.device+=element+"\r\n";
}
});
},
open(){
var serial = api.require('serialPort');
serial.openRead(
{
com:"/dev/ttyS1", //串口地址
rate:9600, //波特率
delay:500, //RX接收区延时毫秒
hex:false //text接收还是hex
}, function (ret) {
api.alert(JSON.stringify(ret));
//此处为异步返回RX数据
if(ret.data){
api.alert(ret.data);
}
});
},
send(){
let that=this;
that**.**1.sendPort(
{
data:that.data.snedText//HEX数据或TEXT
}, function (ret) {
api.toast({msg: JSON.stringify(ret)});
});
},
close(){
let that=this;
that**.**1.close(function (ret) {
api.toast({msg: JSON.stringify(ret)});
});
}
}
};
</script>
这是所有js源码,第一次用这个,不知道怎么写;打开的时候就报openRead()方法找不到 |
|