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 { dateFormat } from '../utils/tools' | ||||
| import FileUtil from '../../common/utils/File' | ||||
| import AccountTable from '../../common/database/tables/AccountTable' | ||||
| import MA_SYSSET from '../../common/constants/MA_SYSSET' | ||||
| import { takePhoto,deleteAllFileByPiC } from '../../common/service/videoService' | ||||
| import { deleteAllFileByPiC, takePhoto } from '../../common/service/videoService' | ||||
| 
 | ||||
| import { | ||||
|   delSyncTable, | ||||
| @ -16,7 +14,8 @@ import { | ||||
| } from '../../common/service/initable' | ||||
| import { GlobalConfig } from '../../config/index' | ||||
| import testNapi from '@ohos.hiserialsdk' | ||||
| import fs from '@ohos.file.fs'; | ||||
| import fs from '@ohos.file.fs' | ||||
| 
 | ||||
| let num = 0 | ||||
| 
 | ||||
| export async function getliushuiNum(context) { | ||||
| @ -41,6 +40,7 @@ export async function getliushuiNum(context) { | ||||
|     // return str
 | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export async function deleteAllFIleLog(path) { | ||||
|   let options = { | ||||
|     "recursion": false, | ||||
| @ -65,6 +65,7 @@ export async function deleteAllFIleLog(path){ | ||||
|   } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| export async function delHilog() { | ||||
|   console.log('kkkkmmm1') | ||||
| 
 | ||||
| @ -87,6 +88,7 @@ export async function delHilog(){ | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| function isSevenDaysAgo(date) { | ||||
|   const today = new Date(); // 当前日期
 | ||||
|   const target = new Date(date); // 需要判断的日期
 | ||||
| @ -97,6 +99,7 @@ function isSevenDaysAgo(date) { | ||||
|   // 如果差异天数正好是7,则原日期是当前日期的前七天
 | ||||
|   return diffDays > 7; | ||||
| } | ||||
| 
 | ||||
| //配置流水号
 | ||||
| export async function setliushuiNum(context) { | ||||
|   const fileUtil = new FileUtil(context) | ||||
| @ -323,7 +326,8 @@ export async function takePhotoFn(context) { | ||||
| } | ||||
| 
 | ||||
| let fd | ||||
| const devPath = "/dev/ttyS3" | ||||
| // 5 7
 | ||||
| const devPath = "/dev/ttyS5" | ||||
| 
 | ||||
| function openChuankouFn(callback) { | ||||
|   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() { | ||||
|   let timeout = 50000; // 2秒超时
 | ||||
|   let databuff = [0x61, 0xAA, 0x0A, 0X15, 0X00]; // send ABCDE
 | ||||
| @ -349,6 +362,20 @@ function getChuankouFnMsg() { | ||||
|     testNapi.SerialRecvAsync(globalThis.fd, timeout, (revTestInfo) => { | ||||
|       console.log('zzc 4 received msg') | ||||
|       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() | ||||
|       console.log('chuankou', message) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user