harmony_vehicle_terminal/ohos/dts/@ohos.hiserialsdk.d.ts
2025-04-10 10:41:03 +08:00

159 lines
5.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2022 Archermind Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Callback} from "./basic";
/**
* Provides interfaces to generate system logs.
*
* @namespace HiSerialSDK
* @syscap SystemCapability.HiviewDFX.HiLog
* @crossplatform
* @HONGZOS 2.0
*/
declare namespace HiSerialSDK {
/**
* 接收的数据信息
*/
export interface receiveInfo {
recevedBuf: number[]; // 接收到的数据
recevedLen: number; // 实际接收的数据长度,如果接收出错返回-1
}
/**
* 打开串口
*
* @param hiSerDevice 串口设备路径,如 "/dev/ttyS0"
* @return 串口设备fd句柄如果串口打开失败返回-1
*/
function SerialOpen(hiSerDevice: string): number;
/**
* 打开串口
*
* @param hiSerDevice 串口设备路径,如 "/dev/ttyS0"
* @param callback 串口设备fd句柄如果串口打开失败返回-1
* @HONGZOS 3.0
*/
function SerialOpenAsync(hiSerDevice: string, callback: Callback<number>): void;
/**
* 设置串口
*
* @param fd 串口设备fd句柄
* @param speed 波特率 115200, 57600, 19200, 9600, 4800, 2400, 1200, 300
* @param flow_ctrl 流控制
* @param databits 数据位
* @param stopbits 停止位
* @param parity 奇偶校验位
*
* @return 设置是否成功(0: 成功, -1: 失败)
*/
function SerialSet(fd: number, speed: number, flow_ctrl: number, databits: number, stopbits: number, parity: number): number;
/**
* 设置串口
*
* @param fd 串口设备fd句柄
* @param speed 波特率 115200, 57600, 19200, 9600, 4800, 2400, 1200, 300
* @param flow_ctrl 流控制
* @param databits 数据位
* @param stopbits 停止位
* @param parity 奇偶校验位
* @param callback 设置是否成功(0: 成功, -1: 失败)
* @HONGZOS 3.0
*/
function SerialSetAsync(fd: number, speed: number, flow_ctrl: number, databits: number, stopbits: number, parity: number, callback: Callback<number>): void;
/**
* 设置串口监听回调
*
* @param fd 串口设备fd句柄
* @param callback 监听到数据后执行的回调函数其中参数1: 监听的串口设备fd句柄参数2: 接收的串口数据长度参数3: 接收的串口数据字节数组
*
* @return 设置是否成功(0: 成功, -1: 失败)
*/
function SerialListenCallbackSet(fd: number, callback: Callback<number, number, number[]>): number;
/**
* 取消串口监听
*
* @param fd 串口设备fd句柄
*
* @return 设置是否成功(0: 成功, -1: 失败)
*/
function SerialListenCallbackCancel(fd: number): number;
/**
* 发送数据
*
* @param fd 串口设备fd句柄
* @param sendBuf 发送的数据字节数组
* @return 发送成功返回发送的数据长度,发送失败返回-1
*/
function SerialSend(fd: number, sendBuf: number[]): number;
/**
* 发送数据
*
* @param fd 串口设备fd句柄
* @param sendBuf 发送的数据字节数组
* @param callback 发送成功返回发送的数据长度,发送失败返回-1
* @HONGZOS 3.0
*/
function SerialSendAsync(fd: number, sendBuf: number[], callback: Callback<number>): void;
/**
* 接收数据
*
* @param fd 串口设备fd句柄
* @param timeout 接收数据时的最大等待时间可设置为0单位微秒1000000 为1秒超时
* @param recvLen 可选参数接收的最大字节数不填默认一次最多接收1024字节
*
* @return 接收的数据信息
*/
function SerialRecv(fd: number, timeout: number, recvLen?: number): receiveInfo;
/**
* 接收数据
*
* @param fd 串口设备fd句柄
* @param timeout 接收数据时的最大等待时间可设置为0单位微秒1000000 为1秒超时
* @param callback 接收的数据信息
* @param recvLen 可选参数接收的最大字节数不填默认一次最多接收1024字节
* @HONGZOS 3.0
*/
function SerialRecvAsync(fd: number, timeout: number, callback: Callback<receiveInfo>, recvLen?: number): void;
/**
* 关闭串口
*
* @param fd 串口设备fd句柄
* @return 关闭操作执行结果(0: 成功, 其它: 失败)
*/
function SerialClose(fd: number): number;
/**
* 关闭串口
*
* @param fd 串口设备fd句柄
* @param 关闭操作执行结果(0: 成功, 其它: 失败)
* @HONGZOS 3.0
*/
function SerialCloseAsync(fd: number, callback: Callback<number>): void;
}
export default HiSerialSDK;