1# @ohos.distributedHardware.hardwareManager (分布式硬件管理)(系统接口)
2
3分布式硬件管理模块提供控制分布式硬件的能力,包括暂停、恢复和停止被控端分布式硬件业务。
4
5> **说明:**
6>
7> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块接口为系统接口。
10
11## 导入模块
12
13```js
14import hardwareManager from '@ohos.distributedHardware.hardwareManager';
15```
16
17## HardwareDescriptor
18
19表示分布式硬件的描述信息。
20
21**系统能力**:SystemCapability.DistributedHardware.DistributedHardwareFWK
22
23| 名称         | 类型                                                | 必填 | 说明                                                         |
24| ------------ | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
25| type         | [DistributedHardwareType](#distributedhardwaretype) | 是   | 分布式硬件类型。<br/>**需要权限**:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE |
26| srcNetworkId | string                                              | 否   | 表示源端设备,缺省时表示所有源端设备。<br/>**需要权限**:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE |
27
28## DistributedHardwareType
29
30表示分布式硬件类型。
31
32**系统能力**:SystemCapability.DistributedHardware.DistributedHardwareFWK
33
34| 名称          | 值   | 说明                         |
35| :------------ | ---- | ---------------------------- |
36| ALL           | 0    | 表示所有分布式应用。         |
37| CAMERA        | 1    | 表示分布式相机。             |
38| SCREEN        | 8    | 表示分布式屏幕。             |
39| MODEM_MIC     | 256  | 表示分布式移动通话的麦克风。 |
40| MODEM_SPEAKER | 512  | 表示分布式移动通话的扬声器。 |
41| MIC           | 1024 | 表示分布式麦克风。           |
42| SPEAKER       | 2048 | 表示分布式扬声器。           |
43
44## DistributedHardwareErrorCode
45
46分布式硬件错误码的枚举。
47
48**系统能力**:SystemCapability.DistributedHardware.DistributedHardwareFWK
49
50| 名称                                      | 值       | 说明                   |
51| ----------------------------------------- | -------- | ---------------------- |
52| ERR_CODE_DISTRIBUTED_HARDWARE_NOT_STARTED | 24200101 | 表示分布式硬件未启动。 |
53| ERR_CODE_DEVICE_NOT_CONNECTED             | 24200102 | 表示源端设备未连接。   |
54
55## hardwareManager.pauseDistributedHardware
56
57pauseDistributedHardware(description: HardwareDescriptor): Promise&lt;void&gt;
58
59暂停被控端分布式硬件业务。使用promise异步回调。
60
61**需要权限**:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE
62
63**系统能力**:SystemCapability.DistributedHardware.DistributedHardwareFWK
64
65**参数:**
66
67| 参数名       | 类型                                       | 必填   | 说明       |
68| --------- | ---------------------------------------- | ---- | -------- |
69| description | [HardwareDescriptor](#hardwaredescriptor) | 是   | 硬件描述信息。 |
70
71**返回值:**
72
73| 类型                  | 说明               |
74| ------------------- | ---------------- |
75| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
76
77**错误码:**
78
79| 错误码ID | 错误信息                                             |
80| -------- | ---------------------------------------------------- |
81| 201      | Permission verification failed.                      |
82| 202      | Permission denied, non-system app called system api. |
83| 401      | Input parameter error.                               |
84| 24200101 | The specified distributed hardware is not started.   |
85| 24200102 | The specified source device is not connected.        |
86
87**示例:**
88
89  ```ts
90  import hardwareManager from '@ohos.distributedHardware.hardwareManager';
91  import { BusinessError } from '@ohos.base';
92
93  try {
94    let description: hardwareManager.HardwareDescriptor = {
95      type: 1,
96      srcNetworkId: '1111'
97    };
98    hardwareManager.pauseDistributedHardware(description).then(() => {
99      console.log('pause distributed hardware successfully');
100    }).catch((error: BusinessError) => {
101      console.error('pause distributed hardware failed, cause:' + error);
102    })
103    console.log('pause distributed hardware successfully');
104  } catch (error) {
105    console.error('pause distributed hardware failed:' + error);
106  }
107  ```
108
109## hardwareManager.resumeDistributedHardware
110
111resumeDistributedHardware(description: HardwareDescriptor): Promise&lt;void&gt;
112
113恢复被控端分布式硬件业务。使用promise异步回调。
114
115**需要权限**:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE
116
117**系统能力**:SystemCapability.DistributedHardware.DistributedHardwareFWK
118
119**参数:**
120
121| 参数名      | 类型                                      | 必填 | 说明           |
122| ----------- | ----------------------------------------- | ---- | -------------- |
123| description | [HardwareDescriptor](#hardwaredescriptor) | 是   | 硬件描述信息。 |
124
125**返回值:**
126
127| 类型                | 说明                      |
128| ------------------- | ------------------------- |
129| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
130
131**错误码:**
132
133| 错误码ID | 错误信息                                             |
134| -------- | ---------------------------------------------------- |
135| 201      | Permission verification failed.                      |
136| 202      | Permission denied, non-system app called system api. |
137| 401      | Input parameter error.                               |
138| 24200101 | The specified distributed hardware is not started.   |
139| 24200102 | The specified source device is not connected.        |
140
141**示例:**
142
143  ```ts
144  import hardwareManager from '@ohos.distributedHardware.hardwareManager';
145  import { BusinessError } from '@ohos.base';
146
147  try {
148    let description: hardwareManager.HardwareDescriptor = {
149      type: 1,
150      srcNetworkId: '1111'
151    };
152    hardwareManager.resumeDistributedHardware(description).then(() => {
153      console.log('resume distributed hardware successfully');
154    }).catch((error: BusinessError) => {
155      console.error('resume distributed hardware failed, cause:' + error);
156    })
157    console.log('resume distributed hardware successfully');
158  } catch (error) {
159    console.error('resume distributed hardware failed:' + error);
160  }
161
162
163  ```
164
165## hardwareManager.stopDistributedHardware
166
167stopDistributedHardware(description: HardwareDescriptor): Promise&lt;void&gt;
168
169停止被控端分布式硬件业务。使用promise异步回调。
170
171**需要权限**:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE
172
173**系统能力**:SystemCapability.DistributedHardware.DistributedHardwareFWK
174
175**参数:**
176
177| 参数名      | 类型                                      | 必填 | 说明           |
178| ----------- | ----------------------------------------- | ---- | -------------- |
179| description | [HardwareDescriptor](#hardwaredescriptor) | 是   | 硬件描述信息。 |
180
181**返回值:**
182
183| 类型                | 说明                      |
184| ------------------- | ------------------------- |
185| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
186
187**错误码:**
188
189| 错误码ID | 错误信息                                             |
190| -------- | ---------------------------------------------------- |
191| 201      | Permission verification failed.                      |
192| 202      | Permission denied, non-system app called system api. |
193| 401      | Input parameter error.                               |
194| 24200101 | The specified distributed hardware is not started.   |
195| 24200102 | The specified source device is not connected.        |
196
197**示例:**
198
199  ```ts
200  import hardwareManager from '@ohos.distributedHardware.hardwareManager';
201  import { BusinessError } from '@ohos.base';
202
203  try {
204    let description: hardwareManager.HardwareDescriptor = {
205      type: 1,
206      srcNetworkId: '1111'
207    };
208    hardwareManager.stopDistributedHardware(description).then(() => {
209      console.log('stop distributed hardware successfully');
210    }).catch((error: BusinessError) => {
211      console.error('stop distributed hardware failed, cause:' + error);
212    })
213    console.log('stop distributed hardware successfully');
214  } catch (error) {
215    console.error('stop distributed hardware failed:' + error);
216  }
217  ```
218