1e41f4b71Sopenharmony_ci# hdc
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciOpenHarmony Device Connector (hdc) is a command line tool used for debugging. You can use it on a Windows, Linux, or macOS system to interact with devices.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Environment Setup
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciObtain hdc from the **toolchains** folder in OpenHarmony SDK. For first-time use, configure the environment variables as follows.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci### Setting the Environment Variable **HDC_SERVER_PORT**
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci**Windows**
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci1. Choose **This PC > Properties >Advanced system settings > Advanced > Environment Variables**, add the variable **HDC_SERVER_PORT**, and set its value to any port number not in use, such as **7035**.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci![Create system variable](figures/hdc_image_001.png)
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci2. Restart DevEco Studio.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**macOS**
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci1. Start the terminal tool and run the following command:
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci   ```shell
24e41f4b71Sopenharmony_ci   echo $SHELL 
25e41f4b71Sopenharmony_ci   ```
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci   - If the command output is **/bin/bash**, open the **.bash_profile** file.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci      ```shell
30e41f4b71Sopenharmony_ci      vi ~/.bash_profile
31e41f4b71Sopenharmony_ci      ```
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci   - If the command output is **/bin/zsh**, open the **.zshrc** file.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci      ```shell
36e41f4b71Sopenharmony_ci      vi ~/.zshrc
37e41f4b71Sopenharmony_ci      ```
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci2. Press **i** to enter **Insert** mode.
40e41f4b71Sopenharmony_ci3. Enter the following content to add **HDC_SERVER_PORT** information to **PATH**.
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci   ```shell
43e41f4b71Sopenharmony_ci   HDC_SERVER_PORT=7035
44e41f4b71Sopenharmony_ci   launchctl setenv HDC_SERVER_PORT $HDC_SERVER_PORT
45e41f4b71Sopenharmony_ci   export HDC_SERVER_PORT
46e41f4b71Sopenharmony_ci   ```
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci4. Press **Esc** to exit **Insert** mode. Then enter **:wq** and press **Enter** to save the settings.
49e41f4b71Sopenharmony_ci5. Run the following command for the environment variable to take effect.
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci   - If the **.bash_profile** file is opened in step 1, run the following command: 
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci      ```shell
54e41f4b71Sopenharmony_ci      source ~/.bash_profile
55e41f4b71Sopenharmony_ci      ```
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci   - If the **.zshrc** file is opened in step 1, run the following command:
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci      ```shell
60e41f4b71Sopenharmony_ci      source ~/.zshrc
61e41f4b71Sopenharmony_ci      ```
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci6. Restart DevEco Studio.
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci### (Optional) Setting Global Environment Variables
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci> **NOTE**
68e41f4b71Sopenharmony_ci> If global environment variables are not set, you can run commands to go to the **toolchains** directory in the SDK and run hdc commands in the directory for debugging.
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**Windows**
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ciChoose **This PC > Properties > Advanced system settings > Advances > Environment Variables**, add the **toolchains** path of the SDK to the value of **Path**.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciIn the following example, the **toolchains** path of the local SDK is <!--RP1-->**/User/username/sdk/openharmony/10/toolchains**<!--RP1End-->.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci![System Variables](figures/hdc_img_002.png)
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci![Edit Environment Variable](figures/hdc_image_003.png)
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**Linux/macOS**
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci1. Start the terminal tool and run the following command:
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci   ```shell
85e41f4b71Sopenharmony_ci   echo $SHELL 
86e41f4b71Sopenharmony_ci   ```
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci   - If the command output is **/bin/bash**, open the **.bash_profile** file.
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci      ```shell
91e41f4b71Sopenharmony_ci      vi ~/.bash_profile
92e41f4b71Sopenharmony_ci      ```
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci   - If the command output is **/bin/zsh**, open the **.zshrc** file.
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci      ```shell
97e41f4b71Sopenharmony_ci      vi ~/.zshrc
98e41f4b71Sopenharmony_ci      ```
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci2. Press **i** to enter **Insert** mode.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci3. Enter the following content and  add the SDK path to the **PATH**.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci   In the following example, the **toolchains** path of the local SDK is <!--RP1-->**/User/*username*/sdk/openharmony/10/toolchains**<!--RP1End-->.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci   ```shell
107e41f4b71Sopenharmony_ci   HDC_SDK_PATH=/User/username/sdk/openharmony/10/toolchains
108e41f4b71Sopenharmony_ci   launchctl setenv HDC_SDK_PATH $HDC_SDK_PATH # This command needs to be executed only on macOS.
109e41f4b71Sopenharmony_ci   export PATH=$PATH:$HDC_SDK_PATH
110e41f4b71Sopenharmony_ci   ```
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci4. Press **Esc** to exit **Insert** mode. Then enter **:wq** and press **Enter** to save the settings.
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci5. Run the following command for the environment variable to take effect.
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci   - If the **.bash_profile** file is opened in step 1, run the following command: 
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci      ```shell
119e41f4b71Sopenharmony_ci      source ~/.bash_profile
120e41f4b71Sopenharmony_ci      ```
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci   - If the **.zshrc** file is opened in step 1, run the following command:
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci      ```shell
125e41f4b71Sopenharmony_ci      source ~/.zshrc
126e41f4b71Sopenharmony_ci      ```
127e41f4b71Sopenharmony_ci<!--Del-->
128e41f4b71Sopenharmony_ci**(Optional for Linux) Granting USB Operation Permission for Non-root Users**
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci- To temporarily grant the full operation permission on a USB device, run the following command:
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci   ```shell
133e41f4b71Sopenharmony_ci   sudo chmod -R 777 /dev/bus/usb/
134e41f4b71Sopenharmony_ci   ```
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci- To permanently change the operation permission on a USB device, do as follows:
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci   1. Run the **lsusb** command to obtain the **vendorID** and **productID** of the USB device.
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci   2. Create an **udev** rule.
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci      Edit the **udev** loading rule and replace the default **idVendor** and **idProduct** values of the device with the values obtained in the previous step.
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci      **MODE="0666"** indicates the permissions of **GROUP** (the user group) for the USB device. Ensure that the login user is in the user group.
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci        ```shell
147e41f4b71Sopenharmony_ci        sudo vim /etc/udev/rules.d/90-myusb.rules
148e41f4b71Sopenharmony_ci        SUBSYSTEMS=="usb", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", GROUP="users", MODE="0666"
149e41f4b71Sopenharmony_ci        ```
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci   3. Restart the computer or reload the **udev** rule.
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci        ```shell
154e41f4b71Sopenharmony_ci        sudo udevadm control --reload
155e41f4b71Sopenharmony_ci        ```
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci> **NOTE**
158e41f4b71Sopenharmony_ci> A non-root user cannot find the device using hdc in Linux. Granting USB operation permission for non-root users can solve this problem. However, granting the full permission may pose potential security risks. You need to determine whether to grant the permission based on actual requirements.
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci## Precautions
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci- If an exception occurs, run the **hdc kill -r** command to kill the hdc process and restart the hdc service.
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci- If no device information is obtained after the **hdc list targets** command is executed, check whether the hdc process exists in the **Task Manager**. If the process exists, run the **hdc kill -r** command to kill the process and restart the hdc service.
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci## How to Use
168e41f4b71Sopenharmony_ci> **NOTE**
169e41f4b71Sopenharmony_ci>
170e41f4b71Sopenharmony_ci> - The parameters enclosed in [] in a command are optional.
171e41f4b71Sopenharmony_ci> - The parameters in italics are variables. Replace them with actual values when running the command. 
172e41f4b71Sopenharmony_ci<!--DelEnd-->
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci### Global Option Commands
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci| Option | Description|
177e41f4b71Sopenharmony_ci| -------- | -------- |
178e41f4b71Sopenharmony_ci| -h/help | Displays hdc help information.|
179e41f4b71Sopenharmony_ci| -v/version | Displays hdc version information.|
180e41f4b71Sopenharmony_ci| -t [connect-key] [command] | Connects to the specified device. You can run the **hdc list targets** command to obtain the **connect-key**.|
181e41f4b71Sopenharmony_ci| -l [level] | Sets the levels of the logs generated during the running of the tool. The default value is **LOG_INFO**.|
182e41f4b71Sopenharmony_ci| checkserver | Obtains the **client-server** version.|
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci1. Display hdc help information.
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci   ```shell
187e41f4b71Sopenharmony_ci   hdc -h/help
188e41f4b71Sopenharmony_ci   ```
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci   **Return value**
191e41f4b71Sopenharmony_ci   | Return Value| Description|
192e41f4b71Sopenharmony_ci   | -------- | -------- |
193e41f4b71Sopenharmony_ci   | OpenHarmony device connector(HDC) ...<br>---------------------------------global commands:----------------------------------<br>-h/help [verbose]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Print hdc help, 'verbose' for more other cmds<br>..._(Detailed information is omitted here.)_| Help information for hdc commands.|
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci   **Usage**
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci   ```shell
198e41f4b71Sopenharmony_ci   hdc -h or hdc help
199e41f4b71Sopenharmony_ci   ```
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci2. Display hdc version information.
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci   ```shell
204e41f4b71Sopenharmony_ci   hdc -v/version
205e41f4b71Sopenharmony_ci   ```
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci   **Return value**
208e41f4b71Sopenharmony_ci   | Return Value| Description|
209e41f4b71Sopenharmony_ci   | -------- | -------- |
210e41f4b71Sopenharmony_ci   | Ver: X.X.Xa | hdc (SDK) version information.|
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci   **Usage**
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ci   ```shell
215e41f4b71Sopenharmony_ci   hdc -v or hdc version
216e41f4b71Sopenharmony_ci   ```
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci3. Connect to a device. If there is only one device connected, you do not need to specify **connect-key**. If there are multiple devices connected, you must specify **connect-key** each time.
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci   ```shell
221e41f4b71Sopenharmony_ci   hdc -t [connect-key] [command]
222e41f4b71Sopenharmony_ci   ```
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci   **Parameters**
225e41f4b71Sopenharmony_ci   | Name| Description|
226e41f4b71Sopenharmony_ci   | -------- | -------- |
227e41f4b71Sopenharmony_ci   | connect-key| Device ID.|
228e41f4b71Sopenharmony_ci   | command | Command to be executed.|
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci> **NOTE**
231e41f4b71Sopenharmony_ci   > The **connect-key** uniquely identifies a device. If the device is connected over the network, the **connect-key** is the IP address. If the device is connected through USB, the **connect-key** is the USB SN.
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci   **Return value**
234e41f4b71Sopenharmony_ci| Return Value| Description|
235e41f4b71Sopenharmony_ci| -------- | -------- |
236e41f4b71Sopenharmony_ci| Command output| Command execution result, which may vary with the command.|
237e41f4b71Sopenharmony_ci| [Fail]Not match target founded, check connect-key please | No device matches the *connect-key*.|
238e41f4b71Sopenharmony_ci| [Fail]Device not founded or connected | The device is not found or connected.|
239e41f4b71Sopenharmony_ci| [Fail]ExecuteCommand need connect-key? please confirm a device by help info | You must specify one device if there are multiple devices available.|
240e41f4b71Sopenharmony_ci| Unknown operation command... | The command is not supported.|
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci   **Usage**
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci   This option must be used with a command. The following uses the **shell** command as an example.
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci   ```shell
247e41f4b71Sopenharmony_ci   hdc list targets  // Display connect-key of all connected devices.
248e41f4b71Sopenharmony_ci   hdc -t [connect-key] shell // Replace connect-key with the specified device ID.
249e41f4b71Sopenharmony_ci   ```
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci4. Specify the runtime log level. The default value is **LOG_INFO**. 
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci   ```shell
254e41f4b71Sopenharmony_ci   hdc -l [level] [command]
255e41f4b71Sopenharmony_ci   ```
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci   **Parameters**
258e41f4b71Sopenharmony_ci   | Parameter| Description|
259e41f4b71Sopenharmony_ci   | -------- | -------- |
260e41f4b71Sopenharmony_ci   | [level] | Log level.<br>0: LOG_OFF<br>1: LOG_FATAL<br>2: LOG_WARN<br>3: LOG_INFO<br>4: LOG_DEBUG<br>5: LOG_ALL|
261e41f4b71Sopenharmony_ci   | command | Command to be executed.|
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci   **Return value**
264e41f4b71Sopenharmony_ci   | Return Value| Description|
265e41f4b71Sopenharmony_ci   | -------- | -------- |
266e41f4b71Sopenharmony_ci   | Command output| Command execution result, which may vary with the command.|
267e41f4b71Sopenharmony_ci   | Log information| Logs of the specified level.|
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci   **Usage**
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci   ```shell
272e41f4b71Sopenharmony_ci   hdc -l 5 shell ls
273e41f4b71Sopenharmony_ci   ```
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci5. Obtain the client-server version information.
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci   ```shell
278e41f4b71Sopenharmony_ci   hdc checkserver
279e41f4b71Sopenharmony_ci   ```
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ci   **Return value**
282e41f4b71Sopenharmony_ci   | Return Value| Description|
283e41f4b71Sopenharmony_ci   | -------- | -------- |
284e41f4b71Sopenharmony_ci   | Client version: Ver: X.X.Xa, Server version: Ver: X.X.Xa | Client-server version information.|
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci   **Usage**
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci   ```shell
289e41f4b71Sopenharmony_ci   hdc checkserver
290e41f4b71Sopenharmony_ci   ```
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ci### Commands for Viewing Device List
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci| Command| Description|
295e41f4b71Sopenharmony_ci| -------- | -------- |
296e41f4b71Sopenharmony_ci| list targets [-v] | Displays all connected devices. Use **-v** to display detailed device information.|
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ciDisplay all connected devices.
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci```shell
301e41f4b71Sopenharmony_cihdc list targets[-v]
302e41f4b71Sopenharmony_ci```
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci**Return value**
305e41f4b71Sopenharmony_ci| Return Value| Description|
306e41f4b71Sopenharmony_ci| -------- | -------- |
307e41f4b71Sopenharmony_ci| Device information| A list of connected devices.|
308e41f4b71Sopenharmony_ci| [Empty] | No device is found.|
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci**Usage**
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci```shell
313e41f4b71Sopenharmony_cihdc list targets
314e41f4b71Sopenharmony_cihdc list targets -v
315e41f4b71Sopenharmony_ci```
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci### Service Process Commands
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci| Command| Description|
320e41f4b71Sopenharmony_ci| -------- | -------- |
321e41f4b71Sopenharmony_ci| target mount | Mounts the system partition in read/write mode(unavailable to user).|
322e41f4b71Sopenharmony_ci| target boot | Restarts the target device.|
323e41f4b71Sopenharmony_ci| smode [-r] | Grants the **root** permission to the background hdc service running on the device. You can use the **-r** option to revoke the granted permission(unavailable to user).|
324e41f4b71Sopenharmony_ci| kill [-r] | Terminates the hdc process. You can use the **-r** option to restart the process.|
325e41f4b71Sopenharmony_ci| start [-r] | Starts the hdc process. You can use the **-r** option to restart the process.|
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ci1. Mount the system partition in read/write mode.
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci   ```shell
330e41f4b71Sopenharmony_ci   hdc target mount
331e41f4b71Sopenharmony_ci   ```
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci   **Return value**
334e41f4b71Sopenharmony_ci   | Return Value| Description|
335e41f4b71Sopenharmony_ci   | -------- | -------- |
336e41f4b71Sopenharmony_ci   | Mount finish | Mounting succeeded.|
337e41f4b71Sopenharmony_ci   | [Fail]Mount failed | Mounting failed.|
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci   **Usage**
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci   ```shell
342e41f4b71Sopenharmony_ci   hdc target mount
343e41f4b71Sopenharmony_ci   ```
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci2. Grant the **root** permission to the background hdc service running on the device.
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci   ```shell
348e41f4b71Sopenharmony_ci   hdc smode [-r]
349e41f4b71Sopenharmony_ci   ```
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci   **Return value**
352e41f4b71Sopenharmony_ci   | Return Value| Description|
353e41f4b71Sopenharmony_ci   | -------- | -------- |
354e41f4b71Sopenharmony_ci   | No return value| Permission granted.|
355e41f4b71Sopenharmony_ci   | [Fail]Error information| Failed to grant the permission.|
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci   **Usage**
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci   ```shell
360e41f4b71Sopenharmony_ci   hdc smode  
361e41f4b71Sopenharmony_ci   hdc smode -r  // Revoke the root permission.
362e41f4b71Sopenharmony_ci   ```
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ci3. Terminate the hdc service.
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci   ```shell
367e41f4b71Sopenharmony_ci   hdc kill [-r]
368e41f4b71Sopenharmony_ci   ```
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci   **Return value**
371e41f4b71Sopenharmony_ci   | Return Value| Description|
372e41f4b71Sopenharmony_ci   | -------- | -------- |
373e41f4b71Sopenharmony_ci   | Kill server finish | The service is terminated successfully.|
374e41f4b71Sopenharmony_ci   | [Fail]Error information| Failed to terminate the service.|
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ci   **Usage**
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci   ```shell
379e41f4b71Sopenharmony_ci   hdc kill
380e41f4b71Sopenharmony_ci   hdc kill -r // Restart and terminate the service process. 
381e41f4b71Sopenharmony_ci   ```
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ci4. Start the hdc service.
384e41f4b71Sopenharmony_ci
385e41f4b71Sopenharmony_ci   ```shell
386e41f4b71Sopenharmony_ci   hdc start [-r]
387e41f4b71Sopenharmony_ci   ```
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci   **Return value**
390e41f4b71Sopenharmony_ci   | Return Value| Description|
391e41f4b71Sopenharmony_ci   | -------- | -------- |
392e41f4b71Sopenharmony_ci   | No return value| The service is started successfully.|
393e41f4b71Sopenharmony_ci   | [Fail]Error information| Failed to start the service process.|
394e41f4b71Sopenharmony_ci
395e41f4b71Sopenharmony_ci   **Usage**
396e41f4b71Sopenharmony_ci
397e41f4b71Sopenharmony_ci   ```shell
398e41f4b71Sopenharmony_ci   hdc start
399e41f4b71Sopenharmony_ci   hdc start -r // Restart the service.
400e41f4b71Sopenharmony_ci   ```
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci### Network Commands
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ci| Command| Description|
405e41f4b71Sopenharmony_ci| -------- | -------- |
406e41f4b71Sopenharmony_ci| fport ls | Lists all port forwarding tasks.|
407e41f4b71Sopenharmony_ci| fport _localnode remotenode_ | Sets up a local port forwarding, which forwards data from a local port to a remote port.|
408e41f4b71Sopenharmony_ci| rport _remotenode localnode_ | Sets up a remote port forwarding, which forwards data from a remote port to a local port.|
409e41f4b71Sopenharmony_ci| fport rm _taskstr_ | Removes a port forwarding task.|
410e41f4b71Sopenharmony_ci| tmode usb | This command cannot be used to enable the USB connection channel. You need to enable it on the device setting page.|
411e41f4b71Sopenharmony_ci| tmode port [port-number] | Enable the network connection channel of the device. Then the daemon process on the device restarts, and the USB connection is interrupted. You need to reconnect the device.|
412e41f4b71Sopenharmony_ci| tmode port close | Disable the network connection channel of the device. Then the daemon process on the device restarts, and the USB connection is interrupted. You need to reconnect the device.|
413e41f4b71Sopenharmony_ci| tconn [IP]:[port] [-remove] | Specifies a connection to a device in *IP address: port number* format. Use the **-remove** option to disconnect from the specified device.|
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci1. List all port forwarding tasks.
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci   ```shell
418e41f4b71Sopenharmony_ci   hdc fport ls
419e41f4b71Sopenharmony_ci   ```
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci   **Return value**
422e41f4b71Sopenharmony_ci   | Return Value| Description|
423e41f4b71Sopenharmony_ci   | -------- | -------- |
424e41f4b71Sopenharmony_ci   | tcp:1234 tcp:1080 [Forward] | Local port forwarding.|
425e41f4b71Sopenharmony_ci   | tcp:2080 tcp:2345 [Reverse] | Remote port forwarding.|
426e41f4b71Sopenharmony_ci   | [empty] | No port forwarding.|
427e41f4b71Sopenharmony_ci
428e41f4b71Sopenharmony_ci   **Usage**
429e41f4b71Sopenharmony_ci
430e41f4b71Sopenharmony_ci   ```shell
431e41f4b71Sopenharmony_ci   hdc fport ls
432e41f4b71Sopenharmony_ci   ```
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_ci2. Set up a local port forwarding, which forwards data from a local port to a remote port.
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_ci   ```shell
437e41f4b71Sopenharmony_ci   hdc fport localnode remotenode
438e41f4b71Sopenharmony_ci   ```
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ci   **Return value**
441e41f4b71Sopenharmony_ci   | Return Value| Description|
442e41f4b71Sopenharmony_ci   | -------- | -------- |
443e41f4b71Sopenharmony_ci   | Forwardport result:OK | The port forwarding is set up properly.|
444e41f4b71Sopenharmony_ci   | [Fail]Incorrect forward command | Failed to set up the port forwarding due to parameter errors.|
445e41f4b71Sopenharmony_ci   | [Fail]TCP Port listen failed at XXXX | Failed to set up the port forwarding because the local port is in use.|
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci   **Usage**
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci   ```shell
450e41f4b71Sopenharmony_ci   hdc fport tcp:1234 tcp:1080
451e41f4b71Sopenharmony_ci   ```
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci
454e41f4b71Sopenharmony_ci3. Set up a remote port forwarding, which forwards data from a remote port to a local port.
455e41f4b71Sopenharmony_ci
456e41f4b71Sopenharmony_ci   ```shell
457e41f4b71Sopenharmony_ci   hdc rport remotenode localnode
458e41f4b71Sopenharmony_ci   ```
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ci   **Return value**
461e41f4b71Sopenharmony_ci   | Return Value| Description|
462e41f4b71Sopenharmony_ci   | -------- | -------- |
463e41f4b71Sopenharmony_ci   | Forwardport result:OK | The port forwarding is set up properly.|
464e41f4b71Sopenharmony_ci   | [Fail]Incorrect forward command | Failed to set up the port forwarding due to parameter errors.|
465e41f4b71Sopenharmony_ci   | [Fail]TCP Port listen failed at XXXX | Failed to set up the port forwarding because the local port is in use.|
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ci   **Usage**
468e41f4b71Sopenharmony_ci
469e41f4b71Sopenharmony_ci   ```shell
470e41f4b71Sopenharmony_ci   hdc rport tcp:1234 tcp:1080
471e41f4b71Sopenharmony_ci   ```
472e41f4b71Sopenharmony_ci4. Remove the specified port forwarding.
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci   ```shell
475e41f4b71Sopenharmony_ci   hdc fport rm taskstr
476e41f4b71Sopenharmony_ci   ```
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci   **Parameters**
479e41f4b71Sopenharmony_ci   | Parameter| Description|
480e41f4b71Sopenharmony_ci   | -------- | -------- |
481e41f4b71Sopenharmony_ci   | _taskstr_ | Port forwarding task, in the format of tcp:XXXX tcp:XXXX.|
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ci   **Return value**
484e41f4b71Sopenharmony_ci   | Return Value| Description|
485e41f4b71Sopenharmony_ci   | -------- | -------- |
486e41f4b71Sopenharmony_ci   | Remove forward ruler success, ruler:tcp:XXXX tcp:XXXX | The port forwarding is removed successfully.|
487e41f4b71Sopenharmony_ci   | [Fail]Remove forward ruler failed, ruler is not exist tcp:XXXX tcp:XXXX | Failed to remove the port forwarding because the specified forwarding does not exist.|
488e41f4b71Sopenharmony_ci
489e41f4b71Sopenharmony_ci   **Usage**
490e41f4b71Sopenharmony_ci
491e41f4b71Sopenharmony_ci   ```shell
492e41f4b71Sopenharmony_ci   hdc fport rm tcp:1234 tcp:1080
493e41f4b71Sopenharmony_ci   ```
494e41f4b71Sopenharmony_ci
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci5. Enable the USB connection channel of the device.
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci   ```shell
499e41f4b71Sopenharmony_ci   hdc tmode usb
500e41f4b71Sopenharmony_ci   ```
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_ci   **Usage**
503e41f4b71Sopenharmony_ci
504e41f4b71Sopenharmony_ci   ```shell
505e41f4b71Sopenharmony_ci   hdc tmode usb
506e41f4b71Sopenharmony_ci   ```
507e41f4b71Sopenharmony_ci   > **NOTE**
508e41f4b71Sopenharmony_ci   > This command cannot be used to enable the USB connection channel. You need to enable it on the device setting page.
509e41f4b71Sopenharmony_ci
510e41f4b71Sopenharmony_ci6. Enable the network connection channel of the device.
511e41f4b71Sopenharmony_ci
512e41f4b71Sopenharmony_ci   ```shell
513e41f4b71Sopenharmony_ci   hdc tmode port [port-number]
514e41f4b71Sopenharmony_ci   ```
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_ci   **Parameters**
517e41f4b71Sopenharmony_ci   | Parameter| Description|
518e41f4b71Sopenharmony_ci   | -------- | -------- |
519e41f4b71Sopenharmony_ci   | port-number | Port number of the connection. The value ranges from 1 to 65536.|
520e41f4b71Sopenharmony_ci
521e41f4b71Sopenharmony_ci   **Return value**
522e41f4b71Sopenharmony_ci   | Return Value| Description|
523e41f4b71Sopenharmony_ci   | -------- | -------- |
524e41f4b71Sopenharmony_ci   | Set device run mode successful. | The network connection channel is enabled successfully.|
525e41f4b71Sopenharmony_ci   | [Fail]ExecuteCommand need connect-key | Failed to enable the network connection channel because no device exists in the list. |
526e41f4b71Sopenharmony_ci   | [Fail]Incorrect port range | The port number is out of range (1 to 65536).|
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_ci   **Usage**
529e41f4b71Sopenharmony_ci
530e41f4b71Sopenharmony_ci   ```shell
531e41f4b71Sopenharmony_ci   hdc tmode port 1234
532e41f4b71Sopenharmony_ci   ```
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ci   > **NOTE**
535e41f4b71Sopenharmony_ci   > Before changing the connection mode, ensure that the remote device and the local executor are on the same network, and the executor can ping the IP address of the remote device.
536e41f4b71Sopenharmony_ci   >
537e41f4b71Sopenharmony_ci   > Otherwise, do not run this command.
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ci   > **NOTE**
540e41f4b71Sopenharmony_ci   > After the command is executed, the remote daemon process exits and restarts, and the USB connection is disconnected. You need to reconnect the USB connection.
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci7. Disable the network connection channel of the device.
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci   ```shell
545e41f4b71Sopenharmony_ci   hdc tmode port close
546e41f4b71Sopenharmony_ci   ```
547e41f4b71Sopenharmony_ci
548e41f4b71Sopenharmony_ci   **Return value**
549e41f4b71Sopenharmony_ci   | Return Value| Description|
550e41f4b71Sopenharmony_ci   | -------- | -------- |
551e41f4b71Sopenharmony_ci   | [Fail]ExecuteCommand need connect-key | Failed to disable the network connection channel because no device exists in the list.|
552e41f4b71Sopenharmony_ci
553e41f4b71Sopenharmony_ci   **Usage**
554e41f4b71Sopenharmony_ci
555e41f4b71Sopenharmony_ci   ```shell
556e41f4b71Sopenharmony_ci   hdc tmode port close
557e41f4b71Sopenharmony_ci   ```
558e41f4b71Sopenharmony_ci   > **NOTE**
559e41f4b71Sopenharmony_ci   > After the command is executed, the remote daemon process exits and restarts, and the USB connection is disconnected. You need to reconnect the USB connection.
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_ci8. Connect to the specified device through TCP.
562e41f4b71Sopenharmony_ci
563e41f4b71Sopenharmony_ci   ```shell
564e41f4b71Sopenharmony_ci   hdc tconn [IP]:[port] [-remove]
565e41f4b71Sopenharmony_ci   ```
566e41f4b71Sopenharmony_ci
567e41f4b71Sopenharmony_ci   **Parameters**
568e41f4b71Sopenharmony_ci   | Parameter| Description|
569e41f4b71Sopenharmony_ci   | -------- | -------- |
570e41f4b71Sopenharmony_ci   | [IP]:[port]  | Device IP address and port number.|
571e41f4b71Sopenharmony_ci   | -remove | (Optional) Disconnects from the specified device.|
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci   **Return value**
574e41f4b71Sopenharmony_ci   | Return Value| Description|
575e41f4b71Sopenharmony_ci   | -------- | -------- |
576e41f4b71Sopenharmony_ci   | Connect OK | Device connected.|
577e41f4b71Sopenharmony_ci   | [Info]Target is connected, repeat opration | The device is already connected.|
578e41f4b71Sopenharmony_ci   | [Fail]Connect failed | Failed to connect the specified device.|
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_ci   **Usage**
581e41f4b71Sopenharmony_ci
582e41f4b71Sopenharmony_ci   ```shell
583e41f4b71Sopenharmony_ci   hdc tconn 192.168.0.1:8888
584e41f4b71Sopenharmony_ci   hdc tconn 192.168.0.1:8888 -remove  // Disconnect from the specified device.
585e41f4b71Sopenharmony_ci   ```
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci### File Commands
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci| Command| Description|
590e41f4b71Sopenharmony_ci| -------- | -------- |
591e41f4b71Sopenharmony_ci| file send _localpath remotepath_ | Sends a local file to a remote device.|
592e41f4b71Sopenharmony_ci| file recv _remotepath localpath_ | Sends a file from a remote device to the local device.|
593e41f4b71Sopenharmony_ci
594e41f4b71Sopenharmony_ci1. Send a local file to a remote device.
595e41f4b71Sopenharmony_ci
596e41f4b71Sopenharmony_ci   ```shell
597e41f4b71Sopenharmony_ci   hdc file send localpath remotepath
598e41f4b71Sopenharmony_ci   ```
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ci   **Parameters**
601e41f4b71Sopenharmony_ci   | Name| Description|
602e41f4b71Sopenharmony_ci   | -------- | -------- |
603e41f4b71Sopenharmony_ci   | _localpath_ | Path of the file to send on the local device.|
604e41f4b71Sopenharmony_ci   | _remotepath_ | Destination path on the remote device.|
605e41f4b71Sopenharmony_ci
606e41f4b71Sopenharmony_ci   **Return value**
607e41f4b71Sopenharmony_ci
608e41f4b71Sopenharmony_ci   A success message is displayed if the file is sent successfully. Error information is displayed if the file fails to be sent.
609e41f4b71Sopenharmony_ci
610e41f4b71Sopenharmony_ci   **Usage**
611e41f4b71Sopenharmony_ci
612e41f4b71Sopenharmony_ci   ```shell
613e41f4b71Sopenharmony_ci   hdc file send E:\example.txt /data/local/tmp/example.txt
614e41f4b71Sopenharmony_ci   ```
615e41f4b71Sopenharmony_ci
616e41f4b71Sopenharmony_ci2. Send a file from a remote device to the local device.
617e41f4b71Sopenharmony_ci
618e41f4b71Sopenharmony_ci   ```shell
619e41f4b71Sopenharmony_ci   hdc file recv remotepath localpath
620e41f4b71Sopenharmony_ci   ```
621e41f4b71Sopenharmony_ci
622e41f4b71Sopenharmony_ci   **Parameters**
623e41f4b71Sopenharmony_ci   | Name| Description|
624e41f4b71Sopenharmony_ci   | -------- | -------- |
625e41f4b71Sopenharmony_ci   | _localpath_ | Destination path on the local device.|
626e41f4b71Sopenharmony_ci   | _remotepath_ | Path of the file to send on the remote device.|
627e41f4b71Sopenharmony_ci
628e41f4b71Sopenharmony_ci   **Return value**
629e41f4b71Sopenharmony_ci
630e41f4b71Sopenharmony_ci   A success message is displayed if the file is received successfully. Error information is displayed if the file fails to be received.
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_ci   **Usage**
633e41f4b71Sopenharmony_ci
634e41f4b71Sopenharmony_ci   ```shell
635e41f4b71Sopenharmony_ci   hdc file recv  /data/local/tmp/a.txt   ./a.txt
636e41f4b71Sopenharmony_ci   ```
637e41f4b71Sopenharmony_ci
638e41f4b71Sopenharmony_ci### App Commands
639e41f4b71Sopenharmony_ci
640e41f4b71Sopenharmony_ci| Command| Description|
641e41f4b71Sopenharmony_ci| -------- | -------- |
642e41f4b71Sopenharmony_ci| install _src_ | Installs an app.|
643e41f4b71Sopenharmony_ci| uninstall _packageName_ | Uninstalls an app.|
644e41f4b71Sopenharmony_ci
645e41f4b71Sopenharmony_ci1. Install an app.
646e41f4b71Sopenharmony_ci
647e41f4b71Sopenharmony_ci   ```shell
648e41f4b71Sopenharmony_ci   hdc install [-r|-s] src
649e41f4b71Sopenharmony_ci   ```
650e41f4b71Sopenharmony_ci
651e41f4b71Sopenharmony_ci   **Parameters**
652e41f4b71Sopenharmony_ci   | Name| Description|
653e41f4b71Sopenharmony_ci   | -------- | -------- |
654e41f4b71Sopenharmony_ci   | src| Installation package name.|
655e41f4b71Sopenharmony_ci   | -r | Replaces the existing app (.hap).|
656e41f4b71Sopenharmony_ci   | -s | Install a shared package (.hsp).|
657e41f4b71Sopenharmony_ci
658e41f4b71Sopenharmony_ci   **Return value**
659e41f4b71Sopenharmony_ci   | Return Value| Description|
660e41f4b71Sopenharmony_ci   | -------- | -------- |
661e41f4b71Sopenharmony_ci   | AppMod finish | The installation is successful.|
662e41f4b71Sopenharmony_ci   | Error information| The installation fails.|
663e41f4b71Sopenharmony_ci
664e41f4b71Sopenharmony_ci   **Usage**
665e41f4b71Sopenharmony_ci
666e41f4b71Sopenharmony_ci   For example, install **example.hap**.
667e41f4b71Sopenharmony_ci
668e41f4b71Sopenharmony_ci   ```shell
669e41f4b71Sopenharmony_ci   hdc install E:\example.hap
670e41f4b71Sopenharmony_ci   ```
671e41f4b71Sopenharmony_ci
672e41f4b71Sopenharmony_ci2. Uninstall the app.
673e41f4b71Sopenharmony_ci
674e41f4b71Sopenharmony_ci   ```shell
675e41f4b71Sopenharmony_ci   hdc uninstall [-k|-s] packageName
676e41f4b71Sopenharmony_ci   ```
677e41f4b71Sopenharmony_ci
678e41f4b71Sopenharmony_ci   **Parameters**
679e41f4b71Sopenharmony_ci   | Name| Description|
680e41f4b71Sopenharmony_ci   | -------- | -------- |
681e41f4b71Sopenharmony_ci   | packageName | App installation package.|
682e41f4b71Sopenharmony_ci   | -k | Retains **/data** and **/cache**.|
683e41f4b71Sopenharmony_ci   | -s | Uninstalls a shared package.|
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci   **Return value**
686e41f4b71Sopenharmony_ci   | Return Value| Description|
687e41f4b71Sopenharmony_ci   | -------- | -------- |
688e41f4b71Sopenharmony_ci   | AppMod finish | The uninstallation is successful.|
689e41f4b71Sopenharmony_ci   | Error information| The uninstallation fails.|
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci   **Usage**
692e41f4b71Sopenharmony_ci
693e41f4b71Sopenharmony_ci   For example, uninstall **com.example.hello**.
694e41f4b71Sopenharmony_ci
695e41f4b71Sopenharmony_ci   ```shell
696e41f4b71Sopenharmony_ci   hdc uninstall com.example.hello
697e41f4b71Sopenharmony_ci   ```
698e41f4b71Sopenharmony_ci
699e41f4b71Sopenharmony_ci### Debugging Commands
700e41f4b71Sopenharmony_ci
701e41f4b71Sopenharmony_ci| Command| Description|
702e41f4b71Sopenharmony_ci| -------- | -------- |
703e41f4b71Sopenharmony_ci| jpid | Displays the apps that can be debugged.|
704e41f4b71Sopenharmony_ci| hilog [options] | Obtains the log information of the device. **options** indicates the parameters supported by HiLog. You can run the **hdc hilog -h** command to obtain the parameter information. |
705e41f4b71Sopenharmony_ci| shell [command] | Runs a debugging command specified by *command*. The supported commands vary with the system type or version. You can run the **hdc shell ls /system/bin** command to view the supported commands. |
706e41f4b71Sopenharmony_ci
707e41f4b71Sopenharmony_ci1. Obtain log information about the device.
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ci   ```shell
710e41f4b71Sopenharmony_ci   hdc hilog [options]
711e41f4b71Sopenharmony_ci   ```
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci   **Parameters**
714e41f4b71Sopenharmony_ci   | Parameter| Description|
715e41f4b71Sopenharmony_ci   | -------- | -------- |
716e41f4b71Sopenharmony_ci   | [options] | Parameters supported by HiLog. You can run the **hdc hilog -h** command to obtain the parameter list.|
717e41f4b71Sopenharmony_ci
718e41f4b71Sopenharmony_ci   **Return value**
719e41f4b71Sopenharmony_ci   | Return Value| Description|
720e41f4b71Sopenharmony_ci   | -------- | -------- |
721e41f4b71Sopenharmony_ci   | Returned information| Log information obtained.|
722e41f4b71Sopenharmony_ci
723e41f4b71Sopenharmony_ci   **Usage**
724e41f4b71Sopenharmony_ci
725e41f4b71Sopenharmony_ci   ```shell
726e41f4b71Sopenharmony_ci   hdc hilog 
727e41f4b71Sopenharmony_ci   hdc shell "hilog -r" // Clear the cached logs.
728e41f4b71Sopenharmony_ci   ```
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci2. Display apps that can be debugged.
731e41f4b71Sopenharmony_ci
732e41f4b71Sopenharmony_ci   ```shell
733e41f4b71Sopenharmony_ci   hdc jpid
734e41f4b71Sopenharmony_ci   ```
735e41f4b71Sopenharmony_ci
736e41f4b71Sopenharmony_ci   **Return value**
737e41f4b71Sopenharmony_ci   | Return Value| Description|
738e41f4b71Sopenharmony_ci   | -------- | -------- |
739e41f4b71Sopenharmony_ci   | Apps| List of apps that can be debugged.|
740e41f4b71Sopenharmony_ci   | [empty] | No apps can be debugged.|
741e41f4b71Sopenharmony_ci
742e41f4b71Sopenharmony_ci   **Usage**
743e41f4b71Sopenharmony_ci
744e41f4b71Sopenharmony_ci   ```shell
745e41f4b71Sopenharmony_ci   hdc jpid
746e41f4b71Sopenharmony_ci   ```
747e41f4b71Sopenharmony_ci
748e41f4b71Sopenharmony_ci3. Run a command.
749e41f4b71Sopenharmony_ci
750e41f4b71Sopenharmony_ci   ```shell
751e41f4b71Sopenharmony_ci   hdc shell [command]
752e41f4b71Sopenharmony_ci   ```
753e41f4b71Sopenharmony_ci
754e41f4b71Sopenharmony_ci   **Parameters**
755e41f4b71Sopenharmony_ci   | Parameter| Description|
756e41f4b71Sopenharmony_ci   | -------- | -------- |
757e41f4b71Sopenharmony_ci   | [command] | Debugging command to be executed. You can run the **help** command to obtain all debugging commands.|
758e41f4b71Sopenharmony_ci
759e41f4b71Sopenharmony_ci   **Return value**
760e41f4b71Sopenharmony_ci   | Return Value| Description|
761e41f4b71Sopenharmony_ci   | -------- | -------- |
762e41f4b71Sopenharmony_ci   | Command execution result| Execution result of the debugging command.|
763e41f4b71Sopenharmony_ci   | /bin/sh: XXX : inaccessible or not found | The specified command is not supported.|
764e41f4b71Sopenharmony_ci
765e41f4b71Sopenharmony_ci   **Usage**
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci   ```shell
768e41f4b71Sopenharmony_ci   hdc shell ps -ef  
769e41f4b71Sopenharmony_ci   hdc shell help -a // List all available commands.
770e41f4b71Sopenharmony_ci   ```
771e41f4b71Sopenharmony_ci
772e41f4b71Sopenharmony_ci## When to Use
773e41f4b71Sopenharmony_ci
774e41f4b71Sopenharmony_ci### USB Connection
775e41f4b71Sopenharmony_ci
776e41f4b71Sopenharmony_ci**Checking the Environment**
777e41f4b71Sopenharmony_ci| Item| Normal| Exception Handling|
778e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
779e41f4b71Sopenharmony_ci| USB debugging| USB debugging is enabled.| If the USB debugging mode is not automatically enabled, restart the device.|
780e41f4b71Sopenharmony_ci| USB data cable connection| The PC used for debugging is connected to the device USB port using a USB cable.| If you use a USB cable with low bandwidth and no data communication function, the device may fail to be identified. You are advised to use an officially recommended USB cable.|
781e41f4b71Sopenharmony_ci| USB port| A USB port on the mainboard (USB port on the rear panel of a desktop computer or USB port on a laptop computer) is used.| If you use a conversion adapter, docking station, or USB port on the front panel of a desktop computer, issues such as low bandwidth and USB sync problems may occur, which results in frequent disconnections. Therefore, direct connection between the PC and the device is recommended.|
782e41f4b71Sopenharmony_ci| hdc environment variable| The help information is displayed after the **hdc -h** command is executed.| For details, see "Environment Setup".|
783e41f4b71Sopenharmony_ci| Driver| After the device is connected via hdc, **HDC Device** or **HDC Interface** is displayed in **Device Manager**.| Install the driver.|
784e41f4b71Sopenharmony_ci
785e41f4b71Sopenharmony_ci**Procedure**
786e41f4b71Sopenharmony_ci
787e41f4b71Sopenharmony_ci```shell
788e41f4b71Sopenharmony_cihdc shell // For USB direct connection, ensure that the device is not in TCP connection mode.
789e41f4b71Sopenharmony_ci```
790e41f4b71Sopenharmony_ci
791e41f4b71Sopenharmony_ci### TCP Connection
792e41f4b71Sopenharmony_ci
793e41f4b71Sopenharmony_ci**Checking the Environment**
794e41f4b71Sopenharmony_ci| Item| Normal| Exception Handling|
795e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
796e41f4b71Sopenharmony_ci| Network connection| The PC and the device are on the same network.| Connect the PC and device to the same Wi-Fi network or enable the Wi-Fi hotspot on your device.|
797e41f4b71Sopenharmony_ci| Network Status| Use **telnet IP:port** to check that the network connection between the PC and the device is normal.| Connect the PC and the device over a stable network.|
798e41f4b71Sopenharmony_ci| hdc environment variable| The help information is displayed after the **hdc** command is executed.| For details, see "Environment Setup".|
799e41f4b71Sopenharmony_ci
800e41f4b71Sopenharmony_ci**Procedure**
801e41f4b71Sopenharmony_ci
802e41f4b71Sopenharmony_ci1. Connect the PC to the device through a USB port.
803e41f4b71Sopenharmony_ci
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_ci2. Change the connection mode from USB mode to the TCP mode.
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_ci   ```shell
808e41f4b71Sopenharmony_ci   hdc tmode port 8710// Add a port number after port. The default port number is 8710.
809e41f4b71Sopenharmony_ci   ```
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci3. Connect to the device over TCP (the device IP address must be obtained in advance).
812e41f4b71Sopenharmony_ci
813e41f4b71Sopenharmony_ci   ```shell
814e41f4b71Sopenharmony_ci   hdc tconn IP:8710
815e41f4b71Sopenharmony_ci   ```
816e41f4b71Sopenharmony_ci
817e41f4b71Sopenharmony_ci   You can view the IP address on the device. The port number is the one specified in the previous step. The default port number is 8710.
818e41f4b71Sopenharmony_ci
819e41f4b71Sopenharmony_ci4. Check the connection.
820e41f4b71Sopenharmony_ci
821e41f4b71Sopenharmony_ci   ```shell
822e41f4b71Sopenharmony_ci   hdc list targets
823e41f4b71Sopenharmony_ci   ```
824e41f4b71Sopenharmony_ci
825e41f4b71Sopenharmony_ci   If the return value is in the *IP:port* format, the connection is successful.
826e41f4b71Sopenharmony_ci
827e41f4b71Sopenharmony_ci5. (Optional) Change the TCP mode to the USB mode.
828e41f4b71Sopenharmony_ci
829e41f4b71Sopenharmony_ci   ```shell
830e41f4b71Sopenharmony_ci   hdc tmode usb
831e41f4b71Sopenharmony_ci   ```
832e41f4b71Sopenharmony_ci
833e41f4b71Sopenharmony_ci   The USB mode is restored.
834e41f4b71Sopenharmony_ci
835e41f4b71Sopenharmony_ci### Remote Connection
836e41f4b71Sopenharmony_ci
837e41f4b71Sopenharmony_ciThe following figure illustrates a remote connection.
838e41f4b71Sopenharmony_ci
839e41f4b71Sopenharmony_ci![Remote connection structure](figures/hdc_image_004.PNG)
840e41f4b71Sopenharmony_ci
841e41f4b71Sopenharmony_ci**Server Configuration**
842e41f4b71Sopenharmony_ci
843e41f4b71Sopenharmony_ciConnect the server to the device using a USB cable and run the following commands:
844e41f4b71Sopenharmony_ci
845e41f4b71Sopenharmony_ci```shell
846e41f4b71Sopenharmony_cihdc kill          // Terminate the local hdc service.
847e41f4b71Sopenharmony_cihdc -s IP:8710 -m // Enable the hdc service for network forwarding.
848e41f4b71Sopenharmony_ci                  // In the command, IP indicates the IP address of the server. To query the IP address, you can run the ipconfig command on Windows and run the ifconfig command on Unix.
849e41f4b71Sopenharmony_ci                  // 8710 is the default port number. You can also set it to another port number, for example, 18710.
850e41f4b71Sopenharmony_ci                  // After startup, the server prints logs.
851e41f4b71Sopenharmony_ci```
852e41f4b71Sopenharmony_ci
853e41f4b71Sopenharmony_ci**Client Connection**
854e41f4b71Sopenharmony_ci
855e41f4b71Sopenharmony_ciEnsure that the client can connect to the server IP address, and then run the following command:
856e41f4b71Sopenharmony_ci```shell
857e41f4b71Sopenharmony_cihdc -s IP:8710 [command] // IP indicates the IP address of the server,
858e41f4b71Sopenharmony_ci                         // and command can be any available hdc command, for example, list targets.
859e41f4b71Sopenharmony_ci```
860e41f4b71Sopenharmony_ci
861e41f4b71Sopenharmony_ci### Obtaining Logs
862e41f4b71Sopenharmony_ci
863e41f4b71Sopenharmony_ci**Server logs**
864e41f4b71Sopenharmony_ci
865e41f4b71Sopenharmony_ciObtain server logs.
866e41f4b71Sopenharmony_ci
867e41f4b71Sopenharmony_ci```shell
868e41f4b71Sopenharmony_cihdc kill ​
869e41f4b71Sopenharmony_cihdc -l5 start
870e41f4b71Sopenharmony_ci```
871e41f4b71Sopenharmony_ci
872e41f4b71Sopenharmony_ciThe collected logs are stored in the following path.
873e41f4b71Sopenharmony_ci
874e41f4b71Sopenharmony_ci| OS| Path| Remarks|
875e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
876e41f4b71Sopenharmony_ci| Windows | %temp%\hdc.log | The following is an example. Replace *Username* with the actual one.<br>C:\Users\Username\AppData\Local\Temp\hdc.log|
877e41f4b71Sopenharmony_ci| Linux | /tmp/hdc.log | - |
878e41f4b71Sopenharmony_ci| MacOS | $TMPDIR/hdc.log | - |
879e41f4b71Sopenharmony_ci
880e41f4b71Sopenharmony_ci**Device Logs**
881e41f4b71Sopenharmony_ci
882e41f4b71Sopenharmony_ciEnable HiLog to obtain the corresponding logs.
883e41f4b71Sopenharmony_ci
884e41f4b71Sopenharmony_ci```shell
885e41f4b71Sopenharmony_cihdc shell hilog -w start                             // Enable the function of storing HiLog logs.
886e41f4b71Sopenharmony_cihdc shell ls /data/log/hilog                     // View the stored HilLog logs.
887e41f4b71Sopenharmony_cihdc file recv /data/log/hilog                  // Obtain the stored HilLog logs (including kernel logs).
888e41f4b71Sopenharmony_ci```
889e41f4b71Sopenharmony_ci
890e41f4b71Sopenharmony_ci## FAQs
891e41f4b71Sopenharmony_ci
892e41f4b71Sopenharmony_ci### Failed to Identify the Target Device
893e41f4b71Sopenharmony_ci
894e41f4b71Sopenharmony_ci**Symptom**
895e41f4b71Sopenharmony_ci
896e41f4b71Sopenharmony_ciAfter the **hdc list targets** command is executed, the command output is **[empty]**.
897e41f4b71Sopenharmony_ci
898e41f4b71Sopenharmony_ciPerform the following operations to locate the fault.
899e41f4b71Sopenharmony_ci
900e41f4b71Sopenharmony_ci- Case 1: Check whether the target device is displayed in **Device Manager**.
901e41f4b71Sopenharmony_ci
902e41f4b71Sopenharmony_ci  Windows:
903e41f4b71Sopenharmony_ci
904e41f4b71Sopenharmony_ci  Check whether **HDC Device** (for a single-port device) or **HDC Interface** (for a composite device) exists under **Universal Serial Bus Controllers** in **Device Manager**.
905e41f4b71Sopenharmony_ci
906e41f4b71Sopenharmony_ci  Linux:
907e41f4b71Sopenharmony_ci
908e41f4b71Sopenharmony_ci  Run the **lsusb** command. Check whether **HDC Device** or **HDC Interface** is displayed in the command output.
909e41f4b71Sopenharmony_ci
910e41f4b71Sopenharmony_ci  macOS:
911e41f4b71Sopenharmony_ci
912e41f4b71Sopenharmony_ci  View USB devices in **System Information** or **System Overview**.
913e41f4b71Sopenharmony_ci
914e41f4b71Sopenharmony_ci  1. Press and hold the **Option** key, and click **Menu**.
915e41f4b71Sopenharmony_ci
916e41f4b71Sopenharmony_ci  2. Choose **System Information** or **System Overview**.
917e41f4b71Sopenharmony_ci
918e41f4b71Sopenharmony_ci  3. Select **USB** on the left.
919e41f4b71Sopenharmony_ci
920e41f4b71Sopenharmony_ci  4. Check whether **HDC Device** or **HDC Interface** exists in the device tree.
921e41f4b71Sopenharmony_ci
922e41f4b71Sopenharmony_ci  **Solution**
923e41f4b71Sopenharmony_ci
924e41f4b71Sopenharmony_ci  If the device is not displayed, it fails to be identified. You can use any of the following methods to resolve the problem:
925e41f4b71Sopenharmony_ci
926e41f4b71Sopenharmony_ci  - Use another physical USB port.
927e41f4b71Sopenharmony_ci  - Replace the USB cable.
928e41f4b71Sopenharmony_ci  - Use another PC for debugging.
929e41f4b71Sopenharmony_ci  - Enable the USB debugging mode.
930e41f4b71Sopenharmony_ci  - Click **OK** to allow USB debugging.
931e41f4b71Sopenharmony_ci  - If a TCP connection can be set up, run the **hdc tmode usb** command to switch to the USB connection.
932e41f4b71Sopenharmony_ci  - Restore the factory settings of the device.
933e41f4b71Sopenharmony_ci
934e41f4b71Sopenharmony_ci- Case 2: A USB device exists, but the driver is damaged. **HDC Device** with a warning icon in yellow is displayed.
935e41f4b71Sopenharmony_ci
936e41f4b71Sopenharmony_ci  This problem usually occurs in Windows. In **Device Manager/Universal Serial Bus Device**, **HDC Device** is displayed with a yellow warning icon, indicating that the device cannot work properly. To resolve the problem, reinstall the driver. If the problem persists, use another USB cable, docking station, or USB port.
937e41f4b71Sopenharmony_ci
938e41f4b71Sopenharmony_ci  **Reinstalling the Driver**
939e41f4b71Sopenharmony_ci
940e41f4b71Sopenharmony_ci  1. Open **Device Manager**, and right-click the **HDC Device** with a warning icon.
941e41f4b71Sopenharmony_ci
942e41f4b71Sopenharmony_ci  2. In the displayed menu, choose **Update driver**.
943e41f4b71Sopenharmony_ci
944e41f4b71Sopenharmony_ci  3. In the first prompt window, select **Browse my computer for drivers**.
945e41f4b71Sopenharmony_ci
946e41f4b71Sopenharmony_ci  4. In the second prompt window, select **Let me pick from a list of available drivers on my computer**.
947e41f4b71Sopenharmony_ci
948e41f4b71Sopenharmony_ci  5. In the third prompt window, deselect **Show compatible hardware**, select **WinUsb Device** for **Manufacture** and **WinUsb Device** for **Model**, and click **Next**.
949e41f4b71Sopenharmony_ci
950e41f4b71Sopenharmony_ci- Case 3: "[Fail]Failed to communicate with daemon" is displayed when the device is connected. 
951e41f4b71Sopenharmony_ci
952e41f4b71Sopenharmony_ci  When "[Fail]Failed to communicate with daemon" is displayed after a hdc command is executed, possible causes are as follows:
953e41f4b71Sopenharmony_ci
954e41f4b71Sopenharmony_ci
955e41f4b71Sopenharmony_ci  - The hdc or SDK does not match the device. If the device is the latest version, update the hdc or SDK tool to the latest version.
956e41f4b71Sopenharmony_ci  - The port is occupied.
957e41f4b71Sopenharmony_ci
958e41f4b71Sopenharmony_ci    This problem usually occurs when hdc and hdc_std use the same **HDC_SERVER_PORT** or the same default port **8710**. Ensure that either hdc or hdc_std is running. This problem also occurs when other software occupies the default hdc port.
959e41f4b71Sopenharmony_ci
960e41f4b71Sopenharmony_ci- Case 4: "Connect server failed" is displayed when the device is connected.
961e41f4b71Sopenharmony_ci
962e41f4b71Sopenharmony_ci  The possible causes are as follows:
963e41f4b71Sopenharmony_ci
964e41f4b71Sopenharmony_ci  - **Port Preemption**
965e41f4b71Sopenharmony_ci
966e41f4b71Sopenharmony_ci    Solution:
967e41f4b71Sopenharmony_ci    1. Check the software processes that come with hdc, including software with built-in hdc, such as DevEco Studio and DevEco Testing.
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_ci       Stop these software processses and run hdc commands.
970e41f4b71Sopenharmony_ci
971e41f4b71Sopenharmony_ci    2. Check hdc port status.
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ci       For example, if **HDC_SERVER_PORT** is set to **8710**, run the following command to check the port status.
974e41f4b71Sopenharmony_ci
975e41f4b71Sopenharmony_ci       Unix:
976e41f4b71Sopenharmony_ci
977e41f4b71Sopenharmony_ci       ```shell
978e41f4b71Sopenharmony_ci       netstat -an |grep 8710
979e41f4b71Sopenharmony_ci       ```
980e41f4b71Sopenharmony_ci
981e41f4b71Sopenharmony_ci       Windows:
982e41f4b71Sopenharmony_ci
983e41f4b71Sopenharmony_ci       ```shell
984e41f4b71Sopenharmony_ci       netstat -an |findstr 8710
985e41f4b71Sopenharmony_ci       ```
986e41f4b71Sopenharmony_ci
987e41f4b71Sopenharmony_ci       If the port is used by another software, stop the software process or change the **HDC_SERVER_PORT** environment variable to another port number.
988e41f4b71Sopenharmony_ci
989e41f4b71Sopenharmony_ci    3. Check for and stop the hdc server of another version.
990e41f4b71Sopenharmony_ci
991e41f4b71Sopenharmony_ci       Windows:
992e41f4b71Sopenharmony_ci
993e41f4b71Sopenharmony_ci       Choose **Task Manager** > **Details**, right-click  the **hdc.exe** process and choose **Open file location**. Check whether the location is the same as that configured in the environment variable. If not, stop the **hdc.exe** process by running the **hdc kill** command or terminating the process in **Task Manager**. Then, run the hdc command again. (The hdc server will be restarted by running the hdc command.)
994e41f4b71Sopenharmony_ci
995e41f4b71Sopenharmony_ci       Unix:
996e41f4b71Sopenharmony_ci
997e41f4b71Sopenharmony_ci       Run the **ps -ef |grep hdc** command to query the hdc server process running in the background and check whether the process startup location is the hdc file location set by the environment variable **Path**. If not, stop the hdc process by running the **hdc kill** or **kill -9 hdc** *PID* command, and run the hdc command again. (The hdc server will be restarted by running the hdc command.)
998e41f4b71Sopenharmony_ci
999e41f4b71Sopenharmony_ci  - **Registry Exception**
1000e41f4b71Sopenharmony_ci
1001e41f4b71Sopenharmony_ci    Solution: Clear the registry. The procedure is as follows:
1002e41f4b71Sopenharmony_ci
1003e41f4b71Sopenharmony_ci    1. Press **Win+R** to open the **Run** dialog box, and enter **regedit** to open the registry.
1004e41f4b71Sopenharmony_ci    2. Enter the following address in the address bar, and press **Enter** to access the registry of the USB device driver.
1005e41f4b71Sopenharmony_ci
1006e41f4b71Sopenharmony_ci       ```shell
1007e41f4b71Sopenharmony_ci       Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{88bae032-5a81-49f0-bc3d-a4ff138216d6}
1008e41f4b71Sopenharmony_ci       ```
1009e41f4b71Sopenharmony_ci
1010e41f4b71Sopenharmony_ci    3. Right-click **UpperFilters** and choose **Edit**. Back up and clear the value data. The backup data can be used to restore the value data if the problem persists.
1011e41f4b71Sopenharmony_ci    4. Refresh the **Device Manager**, remove and reconnect the USB cable to the USB port, or restart the PC.
1012e41f4b71Sopenharmony_ci
1013e41f4b71Sopenharmony_ci### Failed to Run hdc
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_ci**Symptom**
1016e41f4b71Sopenharmony_ci
1017e41f4b71Sopenharmony_ciThe **hdc.exe**/hdc binary file cannot be executed using the CLI.
1018e41f4b71Sopenharmony_ci
1019e41f4b71Sopenharmony_ci**Possible Causes and Solution**
1020e41f4b71Sopenharmony_ci
1021e41f4b71Sopenharmony_ci- Incorrect runtime environment.
1022e41f4b71Sopenharmony_ci
1023e41f4b71Sopenharmony_ci  Linux: Ubuntu 18.04 64-bit or later is recommended. If **libc++.so** reference errors are reported, run the **ldd** or **readelf** command to check library reference.
1024e41f4b71Sopenharmony_ci
1025e41f4b71Sopenharmony_ci  macOS: macOS 11 or later is recommended.
1026e41f4b71Sopenharmony_ci
1027e41f4b71Sopenharmony_ci  Windows: Windows 10 or Windows 11 64-bit is recommended. If the WinUSB library or driver is missing in an earlier version, use [Zadig](https://github.com/pbatard/libwdi/releases) to update it. For Windows 10 or Windows 11 64-bit, use [Zadig](https://github.com/pbatard/libwdi/releases) to install the libusb-win32 driver.
1028e41f4b71Sopenharmony_ci
1029e41f4b71Sopenharmony_ci- Improper running mode: Use the correct command to run the hdc tool instead of double-clicking the file.
1030e41f4b71Sopenharmony_ci
1031e41f4b71Sopenharmony_ci### Common Procedure for Troubleshooting Other Problems
1032e41f4b71Sopenharmony_ci
1033e41f4b71Sopenharmony_ci1. Run the **hdc list targets** command.
1034e41f4b71Sopenharmony_ci2. Check whether **HDC Device** exists in **Device Manager**.
1035e41f4b71Sopenharmony_ci3. Run the **hdc kill** command to terminate the server, and then run the **hdc -l5 start** command to collect logs. The **hdc.log** file is stored in the **TEMP** directory on the execution end. The specific directory varies with the OS. For details, see [Obtaining Logs](#obtaining-logs).
1036e41f4b71Sopenharmony_ci4. Locate the problem based on the **hdc.log** file.
1037