fix: 串口代码优化
This commit is contained in:
		
							parent
							
								
									b9ed251380
								
							
						
					
					
						commit
						fa80b4ca7b
					
				| @ -1,9 +1,10 @@ | |||||||
| import HiSerialSDK from '@ohos.hiserialsdk'; | import HiSerialSDK from '@ohos.hiserialsdk'; | ||||||
| import { SerialPortTag } from '../config'; | import { SerialPortTag } from '../config'; | ||||||
| 
 | 
 | ||||||
| // 打开串口工具 | 
 | ||||||
| /* | /** | ||||||
|   * @param serialPort 串口名称 |  * 打开串口工具 | ||||||
|  |  * @param serialPort 串口名称 | ||||||
|  */ |  */ | ||||||
| export const OpenSerialPort = (serialPort: string) => { | export const OpenSerialPort = (serialPort: string) => { | ||||||
|   return new Promise<number>((resolve, reject) => { |   return new Promise<number>((resolve, reject) => { | ||||||
| @ -18,11 +19,12 @@ export const OpenSerialPort = (serialPort: string) => { | |||||||
|   }) |   }) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //初始化串口数据 | 
 | ||||||
| /* | /** | ||||||
|   * @param fd 串口文件描述符 |  * 初始化串口数据 | ||||||
|   * @param speed 波特率 |  * @param fd 串口文件描述符 | ||||||
|   * @returns Promise<boolean> 成功返回true,失败返回false |  * @param speed 波特率 | ||||||
|  |  * @returns Promise<boolean> 成功返回true,失败返回false | ||||||
|  */ |  */ | ||||||
| export const InitSerialPortData = | export const InitSerialPortData = | ||||||
|   async (fd: number, speed: number) => { |   async (fd: number, speed: number) => { | ||||||
| @ -41,11 +43,11 @@ export const InitSerialPortData = | |||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| //发送数据 | /** | ||||||
| /* |  * 发送数据 | ||||||
|   * @param fd 串口文件描述符 |  * @param fd 串口文件描述符 | ||||||
|   * @param data 要发送的数据数组 |  * @param data 要发送的数据数组 | ||||||
|   * @returns Promise<number> 成功返回发送的字节数,失败返回-1 |  * @returns Promise<number> 成功返回发送的字节数,失败返回-1 | ||||||
|  */ |  */ | ||||||
| export const SendSerialPortData = (fd: number, data: number[]) => { | export const SendSerialPortData = (fd: number, data: number[]) => { | ||||||
|   console.log(SerialPortTag, "wzj-----发送数据") |   console.log(SerialPortTag, "wzj-----发送数据") | ||||||
| @ -61,11 +63,11 @@ export const SendSerialPortData = (fd: number, data: number[]) => { | |||||||
|   }) |   }) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // 接受数据 | /** | ||||||
| /* |  * 接受数据 | ||||||
|   * @param fd 串口文件描述符 |  * @param fd 串口文件描述符 | ||||||
|   * @param timeout 超时时间,单位毫秒 |  * @param timeout 超时时间,单位毫秒 | ||||||
|   * @returns Promise<HiSerialSDK.receiveInfo> 成功返回接收到的数据,失败返回-1 |  * @returns Promise<HiSerialSDK.receiveInfo> 成功返回接收到的数据,失败返回-1 | ||||||
|  */ |  */ | ||||||
| export const ReceiveSerialPortData = (fd: number, timeout: number,) => { | export const ReceiveSerialPortData = (fd: number, timeout: number,) => { | ||||||
|   console.log(SerialPortTag, "wzj-----接受数据") |   console.log(SerialPortTag, "wzj-----接受数据") | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user