润和串口调试
This commit is contained in:
parent
9623750d0b
commit
600dfbe397
@ -259,15 +259,25 @@ export async function takePhotoFn(context) {
|
|||||||
}
|
}
|
||||||
let fd
|
let fd
|
||||||
const devPath="/dev/ttyS3"
|
const devPath="/dev/ttyS3"
|
||||||
function openChuankouFn() {
|
function openChuankouFn(callback) {
|
||||||
console.log('SerialOpen in indexservice, path=' + devPath)
|
console.log('SerialOpen in indexservice, path=' + devPath)
|
||||||
fd = testNapi.SerialOpen(devPath);
|
// fd = testNapi.SerialOpen(devPath);
|
||||||
globalThis.num=0
|
// globalThis.num=0
|
||||||
globalThis.fd=fd
|
// globalThis.fd=fd
|
||||||
console.log('fdfd1111',globalThis.fd)
|
// console.log('fdfd1111',globalThis.fd)
|
||||||
|
//
|
||||||
|
// let parity = 0x4e; // 'N'
|
||||||
|
// let ret = testNapi.SerialSet(globalThis.fd, 115200, 0, 8, 1, parity);
|
||||||
|
|
||||||
let parity = 0x4e; // 'N'
|
|
||||||
let ret = testNapi.SerialSet(globalThis.fd, 115200, 0, 8, 1, parity);
|
testNapi.SerialOpenAsync(devPath, (fd)=> {
|
||||||
|
globalThis.fd = fd;
|
||||||
|
globalThis.num=0
|
||||||
|
let parity = 0x4e; // 'N'
|
||||||
|
let ret = testNapi.SerialSetAsync(globalThis.fd, 115200, 0, 8, 1, parity, (ret) => {
|
||||||
|
callback()
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChuankouFnMsg() {
|
function getChuankouFnMsg() {
|
||||||
@ -327,10 +337,10 @@ export async function getChuankouFn(){
|
|||||||
if(globalThis.fd){
|
if(globalThis.fd){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
openChuankouFn()
|
openChuankouFn(getChuankouFnMsg)
|
||||||
// clearInterval(chuankou)
|
// clearInterval(chuankou)
|
||||||
// chuankou=setInterval(()=>{
|
// chuankou=setInterval(()=>{
|
||||||
getChuankouFnMsg()
|
// getChuankouFnMsg()
|
||||||
// },1000)
|
// },1000)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,95 +1,94 @@
|
|||||||
import TcpClient from './TcpClient';
|
import TcpClient from './TcpClient';
|
||||||
import { getSyncData} from '../service/initable'
|
import { getSyncData } from '../service/initable'
|
||||||
import hilog from '@ohos.hilog';
|
import hilog from '@ohos.hilog';
|
||||||
export async function getTCP(flag=false) {
|
|
||||||
|
|
||||||
getSyncData('IpConfigTable').then(async (result:Array<any>)=>{
|
export async function getTCP(flag?) {
|
||||||
console.log('result222',JSON.stringify(result))
|
|
||||||
if(result.length){
|
|
||||||
if(globalThis.TcpClient&&globalThis.TcpClient.closeTcp){
|
|
||||||
if(!flag){
|
|
||||||
return
|
|
||||||
}
|
|
||||||
globalThis.TcpClient.closeTcp(async ()=>{
|
|
||||||
// const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
|
||||||
// globalThis.TcpClient = tcpClient
|
|
||||||
|
|
||||||
await globalThis.TcpClient.rebindTcp(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
getSyncData('IpConfigTable').then(async (result: Array<any>) => {
|
||||||
await globalThis.TcpClient.connectTcp()
|
console.log('result222', JSON.stringify(result))
|
||||||
await globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo||'402')//1002
|
if (result.length) {
|
||||||
await globalThis.TcpClient.onMessage((val)=>{
|
if (globalThis.TcpClient && globalThis.TcpClient.closeTcp) {
|
||||||
hilog.info(0x0000, 'testTag', "valvalval1" + JSON.stringify(val));
|
globalThis.TcpClient.closeTcp(async () => {
|
||||||
|
if(!flag){
|
||||||
// console.log('valvalval',val)
|
return
|
||||||
setTimeout(()=>{
|
}
|
||||||
globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo||'402')//1002
|
setTimeout(async () => {
|
||||||
if(val&&globalThis.udpClient&&globalThis.udpClient.sendMsg){
|
await globalThis.TcpClient.rebindTcp(result[0].tcplocalIp, result[0].tcplocalIpPort, result[0].tcpOppositeIp, result[0].tcpOppositePort)
|
||||||
// const msg=val.substring(5,val.length-1)
|
|
||||||
globalThis.udpClient?.sendMsg(val)
|
|
||||||
}
|
|
||||||
},1000)
|
|
||||||
|
|
||||||
})
|
|
||||||
globalThis.TcpClient.onError(async()=>{
|
|
||||||
await globalThis.TcpClient.rebindTcp(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
|
||||||
await globalThis.TcpClient.connectTcp()
|
await globalThis.TcpClient.connectTcp()
|
||||||
await globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo||'402')//1002
|
await globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo || '402') //1002
|
||||||
await globalThis.TcpClient.onMessage((val)=>{
|
await globalThis.TcpClient.onMessage((val) => {
|
||||||
hilog.info(0x0000, 'testTag', "valvalval1" + JSON.stringify(val));
|
hilog.info(0x0000, 'testTag', "valvalval1" + JSON.stringify(val));
|
||||||
|
|
||||||
// console.log('valvalval',val)
|
// console.log('valvalval',val)
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo||'402')//1002
|
globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo || '402') //1002
|
||||||
if(val&&globalThis.udpClient&&globalThis.udpClient.sendMsg){
|
if (val && globalThis.udpClient && globalThis.udpClient.sendMsg) {
|
||||||
// const msg=val.substring(5,val.length-1)
|
// const msg=val.substring(5,val.length-1)
|
||||||
globalThis.udpClient?.sendMsg(val)
|
globalThis.udpClient?.sendMsg(val)
|
||||||
}
|
}
|
||||||
},1000)
|
}, 1000)
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
globalThis.TcpClient.onError(async () => {
|
||||||
|
await globalThis.TcpClient.rebindTcp(result[0].tcplocalIp, result[0].tcplocalIpPort, result[0].tcpOppositeIp, result[0].tcpOppositePort)
|
||||||
|
await globalThis.TcpClient.connectTcp()
|
||||||
|
await globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo || '402') //1002
|
||||||
|
await globalThis.TcpClient.onMessage((val) => {
|
||||||
|
hilog.info(0x0000, 'testTag', "valvalval1" + JSON.stringify(val));
|
||||||
|
|
||||||
|
// console.log('valvalval',val)
|
||||||
|
setTimeout(() => {
|
||||||
|
globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo || '402') //1002
|
||||||
|
if (val && globalThis.udpClient && globalThis.udpClient.sendMsg) {
|
||||||
|
// const msg=val.substring(5,val.length-1)
|
||||||
|
globalThis.udpClient?.sendMsg(val)
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},1000)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
// prompt.showToast({
|
// prompt.showToast({
|
||||||
// message:'初始化localIp'+ result[0].localIp+ result[0].localIpPort+'oppositeIp'+result[0].oppositeIp+result[0].oppositeIpPort,
|
// message:'初始化localIp'+ result[0].localIp+ result[0].localIpPort+'oppositeIp'+result[0].oppositeIp+result[0].oppositeIpPort,
|
||||||
// duration: 1000
|
// duration: 1000
|
||||||
// });
|
// });
|
||||||
const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
const tcpClient: TcpClient = new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort, result[0].tcpOppositeIp, result[0].tcpOppositePort)
|
||||||
globalThis.TcpClient = tcpClient
|
globalThis.TcpClient = tcpClient
|
||||||
await globalThis.TcpClient.bindTcp()
|
await globalThis.TcpClient.bindTcp()
|
||||||
await globalThis.TcpClient.connectTcp()
|
await globalThis.TcpClient.connectTcp()
|
||||||
await globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo||'402')//1002
|
await globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo || '402') //1002
|
||||||
|
|
||||||
await globalThis.TcpClient.onMessage((val)=>{
|
await globalThis.TcpClient.onMessage((val) => {
|
||||||
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
|
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo||'402')//1002
|
globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo || '402') //1002
|
||||||
if(val&&globalThis.udpClient&&globalThis.udpClient.sendMsg){
|
if (val && globalThis.udpClient && globalThis.udpClient.sendMsg) {
|
||||||
// const msg=val.substring(5,val.length-1)
|
// const msg=val.substring(5,val.length-1)
|
||||||
globalThis.udpClient?.sendMsg(val)
|
globalThis.udpClient?.sendMsg(val)
|
||||||
}
|
}
|
||||||
},1000)
|
}, 1000)
|
||||||
|
|
||||||
})
|
})
|
||||||
globalThis.TcpClient.onError(async()=>{
|
globalThis.TcpClient.onError(async () => {
|
||||||
const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
const tcpClient: TcpClient = new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort, result[0].tcpOppositeIp, result[0].tcpOppositePort)
|
||||||
globalThis.TcpClient = tcpClient
|
globalThis.TcpClient = tcpClient
|
||||||
await globalThis.TcpClient.bindTcp()
|
await globalThis.TcpClient.bindTcp()
|
||||||
await globalThis.TcpClient.connectTcp()
|
await globalThis.TcpClient.connectTcp()
|
||||||
await globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo||'402')//1002
|
await globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo || '402') //1002
|
||||||
|
|
||||||
await globalThis.TcpClient.onMessage((val)=>{
|
await globalThis.TcpClient.onMessage((val) => {
|
||||||
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
|
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo||'402')//1002
|
globalThis.TcpClient.sendMsg(globalThis.carInfo?.carNo || '402') //1002
|
||||||
if(val&&globalThis.udpClient&&globalThis.udpClient.sendMsg){
|
if (val && globalThis.udpClient && globalThis.udpClient.sendMsg) {
|
||||||
// const msg=val.substring(5,val.length-1)
|
// const msg=val.substring(5,val.length-1)
|
||||||
globalThis.udpClient?.sendMsg(val)
|
globalThis.udpClient?.sendMsg(val)
|
||||||
}
|
}
|
||||||
},1000)
|
}, 1000)
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -97,9 +96,10 @@ export async function getTCP(flag=false) {
|
|||||||
}
|
}
|
||||||
// globalThis.udpClient = new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
// globalThis.udpClient = new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
globalThis.TcpClient={}
|
globalThis.TcpClient = {}
|
||||||
globalThis.TcpClient.onMessage=()=>{}
|
globalThis.TcpClient.onMessage = () => {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,19 +8,21 @@ import {string2Bytes} from '../../common/utils/tools'
|
|||||||
export async function sendMsg(val){
|
export async function sendMsg(val){
|
||||||
// globalThis.udpClient1&&globalThis.udpClient1.sendMsg(val)
|
// globalThis.udpClient1&&globalThis.udpClient1.sendMsg(val)
|
||||||
}
|
}
|
||||||
export async function getUDP(flag:Boolean=false) {
|
export async function getUDP(flag?) {
|
||||||
getSyncData('IpConfigTable').then((result:Array<any>)=>{
|
getSyncData('IpConfigTable').then((result:Array<any>)=>{
|
||||||
if(result.length){
|
if(result.length){
|
||||||
if(!flag){
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if(globalThis.udpClient&&globalThis.udpClient.closeUdp){
|
if(globalThis.udpClient&&globalThis.udpClient.closeUdp){
|
||||||
|
if(!flag){
|
||||||
|
return
|
||||||
|
}
|
||||||
globalThis.udpClient.closeUdp(()=>{
|
globalThis.udpClient.closeUdp(()=>{
|
||||||
globalThis.udpClient.rebindUdp(result[0].udplocalIp, result[0].udplocalIpPort,result[0].udpOppositeIp,result[0].udpOppositeIpPort)
|
setTimeout(()=>{
|
||||||
globalThis.udpClient.sendMsg('111')
|
globalThis.udpClient.rebindUdp(result[0].udplocalIp, result[0].udplocalIpPort,result[0].udpOppositeIp,result[0].udpOppositeIpPort)
|
||||||
globalThis.host=`http://${result[0].centerIp}:${result[0].centerPort}`
|
globalThis.udpClient.sendMsg('111')
|
||||||
globalThis.udpClient.onError(globalThis.udpClient.onMessage?globalThis.udpClient.onMessage:()=>{})
|
globalThis.host=`http://${result[0].centerIp}:${result[0].centerPort}`
|
||||||
|
globalThis.udpClient.onError(globalThis.udpClient.onMessage?globalThis.udpClient.onMessage:()=>{})
|
||||||
|
|
||||||
|
},1000)
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ export async function getUDP(flag:Boolean=false) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUDP2(flag:Boolean=false) {
|
export async function getUDP2(flag?) {
|
||||||
getSyncData('IpConfigTable').then(async (result:Array<any>)=>{
|
getSyncData('IpConfigTable').then(async (result:Array<any>)=>{
|
||||||
if(result.length){
|
if(result.length){
|
||||||
if(globalThis.udpClient2&&globalThis.udpClient2.closeUdp){
|
if(globalThis.udpClient2&&globalThis.udpClient2.closeUdp){
|
||||||
@ -49,11 +51,13 @@ export async function getUDP2(flag:Boolean=false) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
globalThis.udpClient2.closeUdp(async ()=>{
|
globalThis.udpClient2.closeUdp(async ()=>{
|
||||||
globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800',globalThis.carInfo?.udpAddress,globalThis.carInfo?.messagePort)
|
setTimeout(()=>{
|
||||||
globalThis.udpClient2.onMessage((val)=>{
|
globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800',globalThis.carInfo?.udpAddress,globalThis.carInfo?.messagePort)
|
||||||
})
|
globalThis.udpClient2.onMessage((val)=>{
|
||||||
globalThis.udpClient2.onError()
|
})
|
||||||
globalThis.udpClient2.setMsgCallBack=()=>{}
|
globalThis.udpClient2.onError()
|
||||||
|
globalThis.udpClient2.setMsgCallBack=()=>{}
|
||||||
|
},1000)
|
||||||
|
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user