去除udp提示信息

This commit is contained in:
lixiao 2025-03-31 17:09:50 +08:00
parent b22af41722
commit e6ba764364

View File

@ -20,9 +20,6 @@ import FileUtil from '../../common/utils/File'
import { fillZero, string2Bytes } from '../utils/tools'
const TAG = '[UdpDemo.UdpClient]'
import hilog from '@ohos.hilog';
import prompt from '@ohos.prompt'
import promptAction from '@ohos.promptAction';
import { getUDP } from './GlobalUdp';
import { dateFormat } from '../utils/tools'
import { getSyncData } from '../service/initable';
@ -50,7 +47,8 @@ export default class UdpClientByCenter {
private isWorking: Boolean = false
private plcUdpError = false;
private initParam
private onMessage_1Callback:Function = ()=>{}
private onMessage_1Callback: Function = () => {
}
public currentValue: string = ''
constructor(udplocalIp: string, udplocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) {
@ -68,8 +66,7 @@ export default class UdpClientByCenter {
return this.isWorking
}
rebindUdp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string)
{
rebindUdp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) {
this.localIp = localIp
this.oppositeIp = oppositeIp
this.localIpPort = localIpPort
@ -171,8 +168,7 @@ export default class UdpClientByCenter {
console.log('getUDPsendHeadMsg exit')
}
sendMsg(msg, sendCallback?)
{
sendMsg(msg, sendCallback?) {
if (!this.isWorking) {
// console.log(`${TAG}getUDPudpCLient sendMsg is closed return `);
// this.writeLog({
@ -195,19 +191,8 @@ export default class UdpClientByCenter {
if (sendCallback) {
sendCallback()
}
// this.writeLog({
// time:dateFormat(new Date()),
// PLC:`${TAG}getUDPudpCLient udp send success: oppositeIp:${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort:${this.localIpPort}`,
// })
}).catch(err => {
// this.writeLog({
// time:dateFormat(new Date()),
// PLC:`${TAG}getUDPudpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}${JSON.stringify(err)}`,
// })
promptAction.showToast({
message:`${TAG}getUDPudpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`,
duration:4000
})
});
}
@ -243,6 +228,7 @@ export default class UdpClientByCenter {
this.stashFn = callback ? callback : () => {
}
}
//中心udp回执
onMessage_2(callback, type?) {
this.udp.on('message', (value, remoteInfo) => {
@ -268,7 +254,6 @@ export default class UdpClientByCenter {
})
// this.interval=setInterval(()=>{
//
// },3000)
@ -354,15 +339,18 @@ export default class UdpClientByCenter {
this.testIfUdpConnetced(callback)
}
async writeLog(param) {
// const fileUtil = new FileUtil(globalThis.context)
// fileUtil.editFile(`${this.folderPath}/plcLog.txt`, JSON.stringify(param)+`\n`)
}
async initPath() {
// const fileUtil = new FileUtil(globalThis.context)
// const date=dateFormat(new Date).split(' ')[0]
// this.folderPath = await fileUtil.initFolder(`/PLC/${date}`);
}
//获取当前UDP信号
getCurrentMessage = () => {
return this.currentValue
@ -425,11 +413,6 @@ export default class UdpClientByCenter {
}
num = 0
}
prompt.showToast({
message: 'plc udp信号丢失',
duration: 2000
});
}
this.plcUdpError = true;