# @e-is/capacitor-bluetooth-serial 中文文档

规范地址：https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/

版本：6\.0\.3
npm 元数据更新时间：2026-06-24T09:44:30.968Z
中文译文更新时间：2026-11-13T03:02:46.266Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40e-is/capacitor-bluetooth-serial
原文对照：https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/?lang=original
项目主页：https://github.com/e-is/capacitor-bluetooth-serial#readme
源码仓库：https://github.com/e-is/capacitor-bluetooth-serial

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：104 kB，35 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2023-04-17T17:08:14.748Z
- 最新版本发布：2024-12-31T18:32:57.312Z
- 近 30 天下载量：10732（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：34（近 12 个月 0 个）

## 中文简介

电容蓝牙串行插件

## 安装

```sh
npm install @e-is/capacitor-bluetooth-serial
```

也可以使用：`pnpm add @e-is/capacitor-bluetooth-serial`、`yarn add @e-is/capacitor-bluetooth-serial`、`bun add @e-is/capacitor-bluetooth-serial`

## README

# 电容蓝牙串行插件

从 [电容-蓝牙相继](https://github.com/agro1desenvolvimento/capacitor-bluetooth-serial) (存档)

使用 Capacitor 与 Bluetooth (serial) 互动的客户端执行 .

支持的平台

-   [ ] 网页
-   [x] 机器人
-   [ ] iOS系统

支持的电容版本 :

-   电容 6: 使用版本 6.x
-   电容 5 : 使用版本 5.x
-   电容器4:使用0.6.x版本
-   请使用 [电容-蓝牙相继](https://github.com/agro1desenvolvimento/capacitor-bluetooth-serial) 页:1

## 使用量

通过 npm 安装插件

```
npm install --save @e-is/capacitor-bluetooth-serial
```

```typescript
import {BluetoothSerial} from "@e-is/capacitor-bluetooth-serial";

//...do something with plugin

```

## API 文档

可找到接口和类型定义 [这里](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/src/definitions.ts)。 。 。 .

# API 密码

## 方法

-   [蓝牙序列。 已启用](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-isEnabled)
-   [蓝牙序列。 可启用](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-canEnable)
-   [蓝牙系列可操作](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-enable)
-   [蓝牙Serial](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-disable)
-   [蓝牙系列. 启动](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-startEnabledNotifications)
-   [蓝牙系列 停止使用](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-stopEnabledNotifications)
-   [蓝牙Serial.scan](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-scan)
-   [蓝牙系列. connect](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-connect)
-   [蓝牙串行. 连接不安全](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-connectInsecure)
-   [蓝牙串行. 断接](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-disconnect)
-   [蓝牙Serial.is已连接](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-isConnected)
-   [蓝牙系列. read](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-read)
-   [蓝牙Serial. read Until](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-readUntil)
-   [蓝牙系列. start 通知](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-startNotifications)
-   [蓝牙系列 停止 通知](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-stopNotifications)
-   [蓝牙Serial.write](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-write)

## 可启用

如果启用了蓝牙报告 .

`isEnabled(): Promise<BluetoothState>;`

### 说明

函数 `isEnabled` 将成功称为无论蓝牙是否启用。 承诺将包含一个属性 `enabled` 显示是否启用了蓝牙或 _没有_ 启用 。 只有在出现错误时才会调用失败回调 .

如果您想在之后启用蓝牙, 您可以直接使用 #enable, 一旦 #enable 也可以检查蓝牙是否被切入 .

### 参数

无.

### 快速示例

```typescript
BluetoothSerial
  .isEnabled()
  .then((response: BluetoothState) => {
    const status = response.enabled ? 'enabled' : 'disabled';
    console.log(`Bluetooth is ${status}`);
  })
  .catch(() => {
    console.log('Error checking bluetooth status');
  });
```

## 可启用

如果能够启用蓝牙, 则报告 .

`canEnable(): Promise<BluetoothState>;`

### 说明

函数 `canEnable` 将成功称为无论蓝牙能否启用。 承诺将包含一个属性 `enabled` 表示是否可以启用蓝牙或 _没有_。只有在错误发生时,才会调用失败回调.

### 参数

无.

### 快速示例

```typescript
BluetoothSerial
  .canEnable()
  .then((response: BluetoothState) => {
    const canEnable = response.enabled;
    console.log(`Bluetooth can be enabled ? ${canEnable}`);
  })
  .catch(() => {
    console.log('Error checking if bluetooth can be enabled');
  });
```

## 启用

未启用时启用蓝牙 。 如有必要,还请求蓝牙访问权限.

`enable(): Promise<BluetoothState>;`

### 说明

函数 `enable` 调用成功与否的蓝牙。 承诺将包含一个属性 `enabled` 显示是否启用了蓝牙或 _没有_ 进程后启用。 只有在出现错误时才会调用失败回调 .

如果该应用没有使用蓝牙的许可,它会请求.

### 参数

无.

### 快速示例

```typescript
BluetoothSerial
  .enable()
  .then((response: BluetoothState) => {
    const status = response.enabled ? 'enabled' : 'disabled';
    console.log(`Bluetooth is ${status}`);
  })
  .catch(() => {
    console.log('Error enabling bluetooth');
  });
```

## 禁用

启用时禁用蓝牙 。 如有必要,还请求蓝牙访问权限.

`disable(): Promise<BluetoothState>;`

### 说明

函数 `disable` 将成功称为蓝牙是否成功禁用. 承诺将包含一个属性 `enabled` 显示是否启用了蓝牙或 _没有_ 进程后启用. 只有在出现错误时才会调用失败回调 .

如果该应用没有使用蓝牙的许可,它会请求.

### 参数

无.

### 快速示例

```typescript
BluetoothSerial
  .disable()
  .then((response: BluetoothState) => {
    const status = response.enabled ? 'enabled' : 'disabled';
    console.log(`Bluetooth is ${status}`);
  })
  .catch(() => {
    console.log('Error disabling bluetooth');
  });
```

## 启动

蓝牙状态改变时通知 .

`startEnabledNotifications(): Promise<void>`· ;

### 说明

函数 `startEnabledNotifications` 启用状态通知 。 为了获取这些值, 使用“ 无法更改的” 事件倾听器作为事件名称 .

```typescript
const eventListener = BluetoothSerial.addListener('onEnabledChanged' , (response: BluetoothState) => {

    const { enabled } = response;
    //Do something with enabled variable
});
```

### 参数

无.

### 快速示例

```typescript
BluetoothSerial
  .startEnabledNotifications()
  .then(() => {
      eventListener = BluetoothSerial.addListener('onEnabledChanged', (data: BluetoothState) => {
        console.log('Bluetooth state changed to ' + (data.enabled ? 'Enabled' : 'Disabled'));
      });
  })
  .catch(() => {
    console.log('Error starting enabled listener');
  });
```

## 停止启用通知

停止价值变化的传播.

`stopEnabledNotifications(): Promise<void>`· ;

### 说明

函数 `stopEnabledNotifications` 禁用蓝牙状态通知 。 此外,事件听众必须删除.

```typescript
eventListener.remove();
```

### 参数

无.

### 快速示例

```typescript
BluetoothSerial
  .stopEnabledNotifications()
  .then(() => {
      eventListener.remove();
  })
  .catch(() => {
    console.log('Error disabling listener for device');
  });
```

## 扫描

发现设备可见并接近设备

`scan(): Promise<BluetoothScanResult>;`

### 说明

#### 机器人

函数 `scan` 发现靠近设备并可见的蓝牙设备. 成功回调被调用一个类似对象列表 `list`,或者如果找不到设备,则列表为空.

示例列表传递给成功回调.

```json
[{
    "class": 0,
    "id": "00:11:22:33:44:55",
    "address": "00:11:22:33:44:55",
    "name": "Device 1"
}, {
    "class": 7936,
    "id": "01:23:6645:4D67:89:00",
    "address": "01:23:6645:4D67:89:00",
    "name": "Device 2"
}]
```

发现过程需要一段时间. 您可能想要在等待发现的 proces 完成时显示进度指标, 并引用 supess 回调 .

通话 `connect` 在未发作的蓝牙设备上,应该开始Android配对过程.

### 参数

无.

### 快速示例

```typescript
BluetoothSerial
  .scan()
  .then((result: BluetoothScanResult) => {
    result.devices.forEach((device: BluetoothDevice) {
        console.log(device.id);
    });
  })
  .catch(() => {
    console.log('Error scanning devices');
  });
```

## 连接

连接到蓝牙设备 .

`connect(options: BluetoothConnectOptions): Promise<void>`· ;

### 说明

函数 `connect` 连接到蓝牙设备。 连接成功时, 调用成功将被调用 。 如果连接失败, 则称为失败 .

#### 机器人

对于Android, `connect` 使用远程设备的MAC地址.

### 参数

-   { **地址** }: 远程设备的标识符.

### 快速示例

```typescript
BluetoothSerial
  .connect({
    address: '00:11:22:33:44:55',
  })
  .then(() => {
    console.log('Successfully connected')
  })
  .catch(() => {
    console.log('Error connecting...');
  });
```

## 连接不安全

连接到蓝牙设备.

`connectInsecure(options: BluetoothConnectOptions): Promise<void>`· ;

### 说明

函数 `connectInsecure` 连接到蓝牙设备。 连接成功时, 调用成功将被调用 。 如果连接失败, 则称为失败 . 函数 `connectInsecure` 喜欢 [蓝牙系列. connect](https://npmcn.com/package/%40e-is/capacitor-bluetooth-serial/#readme-connect),但与蓝牙设备产生不安全的连接。 见 [Android 文档](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createInsecureRfcommSocketToServiceRecord\(java.util.UUID\)) 更多信息.

#### 机器人

对于Android, `connectInsecure` 使用远程设备的MAC地址.

### 参数

-   { **地址** }: 远程设备的标识符.

### 快速示例

```typescript
BluetoothSerial
  .connectInsecure({
    address: '00:11:22:33:44:55',
  })
  .then(() => {
    console.log('Successfully connected')
  })
  .catch(() => {
    console.log('Error connecting...');
  });
```

## 断开

断开蓝牙设备 .

`disconnect(options: BluetoothConnectOptions): Promise<void>`· ;

### 说明

函数 `disconnect` 断开蓝牙设备。 断开成功时将调用回调成功 。 如果断开失败, 则称为失败 .

#### 机器人

对于Android, `disconnect` 使用远程设备的MAC地址.

**3⁄4 ̄ ̧漯B**:如果不通过地址,所有设备都将被断开.

### 参数

-   { **地址** }: 远程设备的标识符.

### 快速示例

```typescript
BluetoothSerial
  .disconnect({
    address: '00:11:22:33:44:55',
  })
  .then(() => {
    console.log('Successfully disconnected')
  })
  .catch(() => {
    console.log('Error disconnecting...');
  });
```

## 已连接

报告联系情况.

`isConnected(options: BluetoothConnectOptions): Promise<BluetoothConnectResult>`· ;

### 说明

函数 `isConnected` 调用连接状态下的成功回调(连接或未连接)。 只有在错误发生时才会称为失败 .

#### 机器人

对于Android, `isConnected` 使用远程设备的MAC地址.

### 参数

-   { **地址** }: 远程设备的标识符.

### 快速示例

```typescript
BluetoothSerial
  .isConnected({
    address: '00:11:22:33:44:55',
  })
  .then((result: BluetoothConnectResult) => {
    const status = result.connected ? 'connected' : 'disconnected';
    console.log(`Device is ${status}`);
  })
  .catch(() => {
    console.log('Error checking connection status');
  });
```

## 读取

从缓冲器读取数据.

`read(options: BluetoothReadOptions): Promise<BluetoothReadResult>`· ;

### 说明

函数 `read` 读取缓冲器中的数据。 数据作为字符串传递给成功的回调. 通话 `read` 当没有数据可用时,会将空字符串传递到回调中.

### 参数

-   { **地址** }: 远程设备的标识符.

### 快速示例

```typescript
BluetoothSerial
  .read({
    address: '00:11:22:33:44:55',
  })
  .then((result: BluetoothReadResult) => {
    console.log(result.data);
  })
  .catch(() => {
    console.log('Error reading data from device');
  });
```

## 读取直到

从缓冲器读取数据,直到其到达分隔器.

`readUntil(options: BluetoothReadUntilOptions): Promise<BluetoothReadResult>`· ;

### 说明

函数 `readUntil` 从缓冲器读取数据,直到它到达了分隔器。 数据作为字符串传递给成功的回调. 如果缓冲器不包含分隔符,则将空字符串传递给回调符.

### 参数

-   { **地址** }: 远程设备的标识符.
-   { **分隔符** }:分界线.

### 快速示例

```typescript
BluetoothSerial
  .readUntil({
    address: '00:11:22:33:44:55',
    delimiter: '\n',
  })
  .then((result: BluetoothReadResult) => {
    console.log(result.data);
  })
  .catch(() => {
    console.log('Error reading data from device');
  });
```

## 开始通知

收到任何数据时启用并通知.

`startNotifications(options: BluetoothEnableNotificationsOptions): Promise<void>`· ;

### 说明

函数 `startNotifications` 启用通知。 为了取回这些值, 使用以“ 读取” 为事件名的事件倾听器 .

```typescript
const eventListener = BluetoothSerial.addListener('onRead' , (response: BluetoothReadResult) => {

    const { value } = response;
    //Do something with the value
});
```

### 参数

-   { **地址** }: 远程设备的标识符.
-   { **分隔符** }: 通知的界限.

### 快速示例

```typescript
BluetoothSerial
  .startNotifications({
    address: '00:11:22:33:44:55',
    delimiter: '\n',
  })
  .then((result: BluetoothEnableNotificationsResult) => {
      eventListener = BluetoothSerial.addListener('onRead', (data: BluetoothReadResult) => {
      console.log("Received value: " + data.value);
    });
  })
  .catch(() => {
    console.log('Error enabling listener for device');
  });
```

## 通知

停止价值变化的传播.

`stopNotifications(options: BluetoothDisableNotificationsOptions): Promise<void>`· ;

### 说明

函数 `stopNotifications` 禁用通知 。 此外,事件听众必须删除.

```typescript
eventListener.remove();
```

### 参数

-   { **地址** }: 远程设备的标识符.

### 快速示例

```typescript
BluetoothSerial
  .stopNotifications({
    address: '00:11:22:33:44:55',
  })
  .then(() => {
    eventListener.remove();
  })
  .catch(() => {
    console.log('Error disabling listener for device');
  });
```

## 写入

将数据写入缓冲器 .

`write(options: BluetoothWriteOptions): Promise<void>`· ;

### 说明

函数 `write` 将数据写入缓冲器.

### 参数

-   { **地址** }: 远程设备的标识符.
-   { **价值** }: 要发送字符串 .

### 快速示例

```typescript
BluetoothSerial
  .write({
    address: '00:11:22:33:44:55',
    value: 'Hello world',
  })
  .then(() => {
    console.log('Value sent to device');
  })
  .catch(() => {
    console.log('Error writing data to device');
  });
```

## 常见问题

### @e-is/capacitor-bluetooth-serial 是什么？

电容蓝牙串行插件

### 如何安装 @e-is/capacitor-bluetooth-serial？

在项目目录运行 npm install @e-is/capacitor-bluetooth-serial，或使用 pnpm add / yarn add / bun add。

### @e-is/capacitor-bluetooth-serial 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @e-is/capacitor-bluetooth-serial 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @e-is/capacitor-bluetooth-serial 可以商用吗？

@e-is/capacitor-bluetooth-serial 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @e-is/capacitor-bluetooth-serial 的下载量有多少？

根据 npm 官方下载统计，@e-is/capacitor-bluetooth-serial 在 2026/10/13 – 2026/11/11 这 30 天内被下载 10,732 次，日均约 358 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @e-is/capacitor-bluetooth-serial 还在维护吗？

最新版本 6\.0\.3 发布于 2025/01/01（1\.9 年前）；至今共发布 34 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/04/18。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

