TMRAppBle/pages/main/main.stml

182 lines
3.8 KiB
Plaintext
Raw Normal View History

2023-10-19 15:00:17 +08:00
<!-- <template>
<safe-area class="page">
<view class="header">
<text class="title">首页</text>
</view>
<view class="body">
<text class="h1">Hello , APICloud</text>
<img class="img" src="../../image/img.png" />
<text class="p">拖入组件搭建你的第一个 APP</text>
<avm-button :color="avmButtonColor" @click="startSocket()">startSocket</avm-button>
<avm-button :color="avmButtonColor_62" @click="stopSocket()">stop</avm-button>
<avm-button :color="avmButtonColor_62" @click="getAddress()">getAddress</avm-button>
<avm-button :color="avmButtonColor_62" @click="connectSer()">connectSer</avm-button>
</view>
</safe-area>
</template>
<script>
import "../../components/avm-ui/button";
export default {
name: 'main',
apiready() {
this.init();
},
data() {
return {
msg: "Hello APICloud",
demo: null,
SocketServerClient: null,
avmButtonColor: "primary",
avmButtonColor_62: "primary"
};
},
methods: {
init() {
this.data.demo = api.require('serialPortPlus');
this.data.SocketServerClient = api.require('socketServerClient'); // var ret = this.data.demo.getAllDeicesPath();
// console.log(JSON.stringify(ret));
this.listenDev();
},
listenDev() {
this.data.demo.addEventListener(function (ret, err) {
console.log(JSON.stringify(ret));
console.log(JSON.stringify(err));
});
},
openDev() {
console.log("openDev");
this.data.demo.open({
port: '/dev/ttyS0',
baudRate: 9600
}, function (ret, err) {
console.log("err", err);
console.log("ret", ret);
});
},
connectSer() {
var ArgFace = api.require('socketServerClient');
ArgFace.clientConnect({
ip: "192.168.2.58",
port: 50012
}, function (ret, err) {
if (ret.receiveMsg) {
console.log(ret.receiveMsg);
}
});
},
startSocket() {
var that = this;
console.log("startSocket");
this.data.SocketServerClient.startServer({
port: 50012,
//TCP服务端口
heart: {
heartTime: 30000,
heartMsg: 'heart',
receiveMsg: 'heart'
},
send: {
head: '',
end: '16',
outTime: 30000,
sendByLength: {
length: 80
}
},
receive: {
head: '',
end: '16',
outTime: 30000,
sendByLength: {
length: 8
}
},
single: false
}, function (ret, err) {
if (ret.receiveMsg) {
console.log("接收到客户端:" + ret.clientId + "数据:"+ret.receiveMsg);
that.data.SocketServerClient.sendMessage({id:ret.clientId,data:ret.receiveMsg,single:false});
}
// if (ret.status) {
// // TCP服务创建成功
// console.log("TCP服务创建成功");
// }
if (ret.link) {
clientId = ret.clientId;
console.log("客户端:" + clientId + "连接成功!");
}
});
},
getAddress() {
console.log("getAddress");
},
stopSocket() {
console.log("stopSocket");
this.data.SocketServerClient.stopServer(function (ret, err) {
console.log(JSON.stringify(ret));
console.log(JSON.stringify(err));
});
}
}
};
</script>
<style>
.page {
height: 100%;
background: #fff;
}
.header {
height: 44px;
justify-content: center;
align-items: center;
}
.title {
font-size: 16px;
font-weight: bold;
color: #333;
}
.body {
background: #f5f6f7;
flex: 1;
}
.h1 {
font-size: 22px;
font-weight: bold;
color: #333;
text-align: center;
margin: 50px;
}
.img {
max-width: 100%;
}
.p {
color: #aaa;
text-align: center;
font-size: 16px;
margin: 15px;
}
.button_1 {
border-color: #dfdfdf;
border-top-color: #dfdfdf;
border-left-color: #dfdfdf;
border-right-color: #dfdfdf;
border-bottom-color: #dfdfdf;
}
.button_2 {
border-color: #dfdfdf;
border-top-color: #dfdfdf;
border-left-color: #dfdfdf;
border-right-color: #dfdfdf;
border-bottom-color: #dfdfdf;
}
</style> -->