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