```typescript
/*
* Copyright (C) 2021-2022 Huawei 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 {AsyncCallback, Callback} from "basic";
/**
* Provides methods related to serialport services.
*
* @since 7
* @syscap SystemCapability.Miscservices.SerialportService
*/
declare namespace serialHelper {
/**
* Set serial port options.
* @param dev Indicates the serial port dev.
* @param speeds baud rate.
* @param bits 7/8.
* @param events 'O'/'E'/'N'
* @param stops 1/2
*/
function setOptions(dev:string, speeds:number, bits:number, events:number, stops: number, callback: AsyncCallback<void>): void;
function setOptions(dev:string, speeds:number, bits:number, events:number, stops: number): Promise<void>;
/**
* Open serial port.
* @param dev Indicates the serial port dev.
*/
function openSerial(dev:string, callback: AsyncCallback<void>): void;
function openSerial(dev:string): Promise<void>;
/**
* Close serial port.
* @param dev Indicates the serial port dev.
*/
function closeSerial(dev:string, callback: AsyncCallback<void>): void;
function closeSerial(dev:string): Promise<void>;
/**
* tcflush serial port.
* @param dev Indicates the serial port dev.
* @param selector 0 in 1 out 2 in&out.
*/
function clearBuffer(dev:string, selector:number, callback: AsyncCallback<void>): void;
function clearBuffer(dev:string, selector:number): Promise<void>;
/**
* Send data to serial port.
* @param dev Indicates the serial port dev.
* @param data.
*/
function sendData(dev:string, data:Uint8Array, callback: AsyncCallback<void>): void;
function sendData(dev:string, data:Uint8Array): Promise<void>;
/**
* read data from serial port.
* @param dev Indicates the serial port dev.
* @param timeout
*/
function recvData(dev:string, timeout:number, callback: AsyncCallback<Uint8Array>): void;
function recvData(dev:string, timeout:number): Promise<Uint8Array>;
/**
* transmit Send and Read data
* @param dev Indicates the serial port dev.
* @param cmd Indicates the command.
* @param timeout
* @param callback Returns the Uint8Array
*/
function transmit(dev:string, cmd: Uint8Array, timeout: number, callback: AsyncCallback<Uint8Array>): void;
function transmit(dev:string, cmd: Uint8Array, timeout: number): Promise<Uint8Array>;
/**
* on/off serial data
* @param type Indicates the serial port dev.
* @param callback serial data
*/
function on(type: '/dev/ttyXRUSB0', callback: Callback<Uint8Array>): void;
function on(type: '/dev/ttyXRUSB1', callback: Callback<Uint8Array>): void;
function on(type: '/dev/ttyXRUSB2', callback: Callback<Uint8Array>): void;
function on(type: '/dev/ttyXRUSB3', callback: Callback<Uint8Array>): void;
function off(type: '/dev/ttyXRUSB0'): void;
function off(type: '/dev/ttyXRUSB1'): void;
function off(type: '/dev/ttyXRUSB2'): void;
function off(type: '/dev/ttyXRUSB3'): void;
/**
* Set GPIO Direction.
*
* @param portNo Gpio number.
* @param dirIn Is it an input port.
* @permission None
*/
function setGPIODirection(portNo:number, dirIn:boolean, callback: AsyncCallback<void>): void;
function setGPIODirection(portNo:number, dirIn:boolean): Promise<void>;
/**
* Set GPIO Value.
*
* @param portNo Gpio number.
* @param value Gpio value, 0 or 1.
* @permission None
*/
function setGPIOValue(portNo:number, value:number, callback: AsyncCallback<void>): void;
function setGPIOValue(portNo:number, value:number): Promise<void>;
/**
* Get GPIO Value.
*
* @param portNo Gpio number.
* @param callback Returns gpio value of portNo, 0 or 1.
* @permission None
*/
function getGPIOValue(portNo:number, callback: AsyncCallback<number>): void;
function getGPIOValue(portNo:number): Promise<number>;
}
- 因为在编写接口时已经将d.ts文件加入so库中,所以需要加入 `// @ts-ignore` 防止编译失败
- 编写完成后点击右上角头像进行登陆,然后选择file>Project Structure>Signing configs>Automatically generate signature进行自动签名
- 连接开发板,点击右上角的debug按钮
- 点击下方log按钮,在搜索栏内设置过滤白名单,点击设备上显示的open按钮,查看返回信息
[/md]作者: fome122 时间: 2025-1-20 20:05
我是小白。请教一下3.4节创建类型声明文件,我要放在哪,依据动态库名称怎么命名。作者: fome122 时间: 2025-1-20 20:21
最后编译完报错了
The variable "device_config_path" was set as a build argument
[OHOS INFO] but never appeared in a declare_args() block in any buildfile.
[OHOS INFO]
[OHOS INFO] To view all possible args, run "gn args --list <out_dir>"
[OHOS INFO]
[OHOS INFO] The build continued as if that argument was unspecified.
[OHOS INFO]
[OHOS INFO] ERROR at //build/config/BUILDCONFIG.gn:824:5: Duplicate output file.
[OHOS INFO] target(_target_type, target_name) {
[OHOS INFO] ^----------------------------------
[OHOS INFO] Two or more targets generate the same output:
[OHOS INFO] applications/prebuilt_hap/serialdebug
[OHOS INFO]
[OHOS INFO] This is can often be fixed by changing one of the target names, or by
[OHOS INFO] setting an output_name on one of them.
[OHOS INFO]
[OHOS INFO] Collisions:
[OHOS INFO] //applications/standard/hap/uart:serialdebug
[OHOS INFO] //device/soc/thead/th1520/hardware/napi_demo:serialdebug
[OHOS INFO]
[OHOS INFO] See //build/config/BUILDCONFIG.gn:824:5: Collision.
[OHOS INFO] target(_target_type, target_name) {
[OHOS INFO] ^----------------------------------
[OHOS INFO] --------------------------------------------- 作者: 润开鸿_闻飞 时间: 2025-1-21 17:52
回复 fome122: 放到interface/sdk-js/api/目录下作者: 润开鸿_闻飞 时间: 2025-1-21 17:55
回复 fome122: 你源代码怎么下载的?编译的命令是什么?