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