fix:读取串口数据
This commit is contained in:
		
							parent
							
								
									9ba033954b
								
							
						
					
					
						commit
						e2176a5532
					
				| @ -3,9 +3,7 @@ import promptAction from '@ohos.promptAction' | |||||||
| import router from '@ohos.router' | import router from '@ohos.router' | ||||||
| import { dateFormat } from '../utils/tools' | import { dateFormat } from '../utils/tools' | ||||||
| import FileUtil from '../../common/utils/File' | import FileUtil from '../../common/utils/File' | ||||||
| import AccountTable from '../../common/database/tables/AccountTable' | import { deleteAllFileByPiC, takePhoto } from '../../common/service/videoService' | ||||||
| import MA_SYSSET from '../../common/constants/MA_SYSSET' |  | ||||||
| import { takePhoto,deleteAllFileByPiC } from '../../common/service/videoService' |  | ||||||
| 
 | 
 | ||||||
| import { | import { | ||||||
|   delSyncTable, |   delSyncTable, | ||||||
| @ -16,7 +14,8 @@ import { | |||||||
| } from '../../common/service/initable' | } from '../../common/service/initable' | ||||||
| import { GlobalConfig } from '../../config/index' | import { GlobalConfig } from '../../config/index' | ||||||
| import testNapi from '@ohos.hiserialsdk' | import testNapi from '@ohos.hiserialsdk' | ||||||
| import fs from '@ohos.file.fs'; | import fs from '@ohos.file.fs' | ||||||
|  | 
 | ||||||
| let num = 0 | let num = 0 | ||||||
| 
 | 
 | ||||||
| export async function getliushuiNum(context) { | export async function getliushuiNum(context) { | ||||||
| @ -41,19 +40,20 @@ export async function getliushuiNum(context) { | |||||||
|     // return str
 |     // return str
 | ||||||
|   } |   } | ||||||
| } | } | ||||||
| export async function deleteAllFIleLog(path){ | 
 | ||||||
|  | export async function deleteAllFIleLog(path) { | ||||||
|   let options = { |   let options = { | ||||||
|     "recursion": false, |     "recursion": false, | ||||||
|     "listNum": 0, |     "listNum": 0, | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   let filenames = fs.listFileSync(path, options); |   let filenames = fs.listFileSync(path, options); | ||||||
|   console.info("listFile succeed",JSON.stringify(filenames)); |   console.info("listFile succeed", JSON.stringify(filenames)); | ||||||
|   for (let i = 0; i < filenames.length; i++) { |   for (let i = 0; i < filenames.length; i++) { | ||||||
|     console.info("listFile succeed",JSON.stringify(filenames[i])); |     console.info("listFile succeed", JSON.stringify(filenames[i])); | ||||||
| 
 | 
 | ||||||
|     if(isSevenDaysAgo(filenames[i])){ |     if (isSevenDaysAgo(filenames[i])) { | ||||||
|       fs.rmdir(path+filenames[i], (err) => { |       fs.rmdir(path + filenames[i], (err) => { | ||||||
|         if (err) { |         if (err) { | ||||||
|           console.error("rmdir failed with error message: " + err.message + ", error code: " + err.code); |           console.error("rmdir failed with error message: " + err.message + ", error code: " + err.code); | ||||||
|         } else { |         } else { | ||||||
| @ -65,38 +65,41 @@ export async function deleteAllFIleLog(path){ | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| export async function delHilog(){ | 
 | ||||||
|  | export async function delHilog() { | ||||||
|   console.log('kkkkmmm1') |   console.log('kkkkmmm1') | ||||||
| 
 | 
 | ||||||
|   const fileUtil = new FileUtil(globalThis.context) |   const fileUtil = new FileUtil(globalThis.context) | ||||||
|   const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/hilogTime.txt'); |   const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/hilogTime.txt'); | ||||||
|   const folderPath = await fileUtil.initFolder(`/config`); |   const folderPath = await fileUtil.initFolder(`/config`); | ||||||
|   console.log('kkkkmmm2',data) |   console.log('kkkkmmm2', data) | ||||||
|   if(data === '' || data === undefined){ |   if (data === '' || data === undefined) { | ||||||
|     const date=dateFormat(new Date()).split(' ')[0] |     const date = dateFormat(new Date()).split(' ')[0] | ||||||
|     console.log('mm'.date) |     console.log('mm'.date) | ||||||
|     fileUtil.addFile(`${folderPath}/hilogTime.txt`, date) |     fileUtil.addFile(`${folderPath}/hilogTime.txt`, date) | ||||||
|   }else{ |   } else { | ||||||
|     console.log('kkkkmmm2',data) |     console.log('kkkkmmm2', data) | ||||||
|     console.log('datadata',data,isSevenDaysAgo(data)) |     console.log('datadata', data, isSevenDaysAgo(data)) | ||||||
|     if(isSevenDaysAgo(data)){ |     if (isSevenDaysAgo(data)) { | ||||||
|       const date=dateFormat(new Date()).split(' ')[0] |       const date = dateFormat(new Date()).split(' ')[0] | ||||||
|       fileUtil.addFile(`${folderPath}/hilogTime.txt`, date) |       fileUtil.addFile(`${folderPath}/hilogTime.txt`, date) | ||||||
|       deleteAllFileByPiC('pz',1) |       deleteAllFileByPiC('pz', 1) | ||||||
|       // fileUtil.addFile(`${folderPath}/hilogTime.txt`, JSON.stringify(num))
 |       // fileUtil.addFile(`${folderPath}/hilogTime.txt`, JSON.stringify(num))
 | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | 
 | ||||||
| function isSevenDaysAgo(date) { | function isSevenDaysAgo(date) { | ||||||
|   const today = new Date(); // 当前日期
 |   const today = new Date(); // 当前日期
 | ||||||
|   const target = new Date(date); // 需要判断的日期
 |   const target = new Date(date); // 需要判断的日期
 | ||||||
|   console.info("listFile succeed1",JSON.stringify(target)); |   console.info("listFile succeed1", JSON.stringify(target)); | ||||||
|   const diff = today.getTime() - target.getTime(); // 计算两个日期之间的毫秒数差异
 |   const diff = today.getTime() - target.getTime(); // 计算两个日期之间的毫秒数差异
 | ||||||
|   const diffDays = diff / (1000 * 60 * 60 * 24); // 将毫秒转换为天数
 |   const diffDays = diff / (1000 * 60 * 60 * 24); // 将毫秒转换为天数
 | ||||||
|   console.info("listFile succeed2",(diffDays)); |   console.info("listFile succeed2", (diffDays)); | ||||||
|   // 如果差异天数正好是7,则原日期是当前日期的前七天
 |   // 如果差异天数正好是7,则原日期是当前日期的前七天
 | ||||||
|   return diffDays > 7; |   return diffDays > 7; | ||||||
| } | } | ||||||
|  | 
 | ||||||
| //配置流水号
 | //配置流水号
 | ||||||
| export async function setliushuiNum(context) { | export async function setliushuiNum(context) { | ||||||
|   const fileUtil = new FileUtil(context) |   const fileUtil = new FileUtil(context) | ||||||
| @ -162,7 +165,7 @@ export async function getDoubleCeneterTable(param) { | |||||||
|     } |     } | ||||||
|     for (let key in typeObj) { |     for (let key in typeObj) { | ||||||
|       typeObj[key] = await upDateTable({ tableName: key }, param) |       typeObj[key] = await upDateTable({ tableName: key }, param) | ||||||
|       console.log('sqlsqlinsert',key,  typeObj[key]) |       console.log('sqlsqlinsert', key, typeObj[key]) | ||||||
|       if (!typeObj[key]) { |       if (!typeObj[key]) { | ||||||
|         promptAction.showToast({ |         promptAction.showToast({ | ||||||
|           message: `未能查询到${key}表数据, 请先检查网络是否连接正常`, |           message: `未能查询到${key}表数据, 请先检查网络是否连接正常`, | ||||||
| @ -183,10 +186,10 @@ export async function getDoubleCeneterTable(param) { | |||||||
| //单中心存表
 | //单中心存表
 | ||||||
| export async function getSingleCenterTable(param) { | export async function getSingleCenterTable(param) { | ||||||
|   return new Promise((reslove, reject) => { |   return new Promise((reslove, reject) => { | ||||||
|     try{ |     try { | ||||||
|       console.log('teststet0') |       console.log('teststet0') | ||||||
|       upDataZhongxinginitialization(param).then((result) => { |       upDataZhongxinginitialization(param).then((result) => { | ||||||
|         console.log('kkkkkkkkkkk',result) |         console.log('kkkkkkkkkkk', result) | ||||||
| 
 | 
 | ||||||
|         if (result) { |         if (result) { | ||||||
|           reslove(true) |           reslove(true) | ||||||
| @ -222,7 +225,7 @@ export async function getSingleCenterTable(param) { | |||||||
|         reslove(false) |         reslove(false) | ||||||
|         console.log(error) |         console.log(error) | ||||||
|       }) |       }) | ||||||
|     }catch (e){ |     } catch (e) { | ||||||
|       reslove(false) |       reslove(false) | ||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
| @ -291,7 +294,7 @@ export async function takePhotoFn(context) { | |||||||
|       if (param[key1]) { |       if (param[key1]) { | ||||||
|         param.pztd = param[`td${Number(i) + 1}`] |         param.pztd = param[`td${Number(i) + 1}`] | ||||||
|         takePhoto(param, context, 'jt/', 0, (data) => { |         takePhoto(param, context, 'jt/', 0, (data) => { | ||||||
|            if(data.errorCode!=0){ |           if (data.errorCode != 0) { | ||||||
|             console.log('拍照失败') |             console.log('拍照失败') | ||||||
|             return |             return | ||||||
|           } |           } | ||||||
| @ -323,7 +326,8 @@ export async function takePhotoFn(context) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| let fd | let fd | ||||||
| const devPath = "/dev/ttyS3" | // 5 7
 | ||||||
|  | const devPath = "/dev/ttyS5" | ||||||
| 
 | 
 | ||||||
| function openChuankouFn(callback) { | function openChuankouFn(callback) { | ||||||
|   console.log('SerialOpen in indexservice, path=' + devPath) |   console.log('SerialOpen in indexservice, path=' + devPath) | ||||||
| @ -338,6 +342,15 @@ function openChuankouFn(callback) { | |||||||
|   }); |   }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function arrayToBuffer(arr: number[]): ArrayBuffer { | ||||||
|  |   const buffer = new ArrayBuffer(arr.length); | ||||||
|  |   const view = new DataView(buffer); | ||||||
|  |   arr.forEach((value, index) => { | ||||||
|  |     view.setUint8(index, value); | ||||||
|  |   }); | ||||||
|  |   return buffer; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function getChuankouFnMsg() { | function getChuankouFnMsg() { | ||||||
|   let timeout = 50000; // 2秒超时
 |   let timeout = 50000; // 2秒超时
 | ||||||
|   let databuff = [0x61, 0xAA, 0x0A, 0X15, 0X00]; // send ABCDE
 |   let databuff = [0x61, 0xAA, 0x0A, 0X15, 0X00]; // send ABCDE
 | ||||||
| @ -349,6 +362,20 @@ function getChuankouFnMsg() { | |||||||
|     testNapi.SerialRecvAsync(globalThis.fd, timeout, (revTestInfo) => { |     testNapi.SerialRecvAsync(globalThis.fd, timeout, (revTestInfo) => { | ||||||
|       console.log('zzc 4 received msg') |       console.log('zzc 4 received msg') | ||||||
|       console.log('revTestInfo', revTestInfo.recevedBuf.length) |       console.log('revTestInfo', revTestInfo.recevedBuf.length) | ||||||
|  |       // TODO: 读取串口数据
 | ||||||
|  |       // if (revTestInfo.recevedLen > 0) {
 | ||||||
|  |       //   const buffer = this.arrayToBuffer(revTestInfo.recevedBuf);
 | ||||||
|  |       //   console.log(buffer.toString(), 'wzj4')
 | ||||||
|  |       //   let dataView = new DataView(buffer)
 | ||||||
|  |       //   let str = ""
 | ||||||
|  |       //   for (let i = 0; i < dataView?.byteLength; ++i) {
 | ||||||
|  |       //     let c = String.fromCharCode(dataView?.getUint8(i))
 | ||||||
|  |       //     if (c !== "\n") {
 | ||||||
|  |       //       str += c
 | ||||||
|  |       //     }
 | ||||||
|  |       //   }
 | ||||||
|  |       //   console.log(str, 'wzj4')
 | ||||||
|  |       // }
 | ||||||
| 
 | 
 | ||||||
|       const message = revTestInfo?.recevedBuf?.toString() |       const message = revTestInfo?.recevedBuf?.toString() | ||||||
|       console.log('chuankou', message) |       console.log('chuankou', message) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user