1# hdc 2 3 4OpenHarmony 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 real devices or simulators. 5 6 7The following describes how to obtain and use hdc. 8 9 10## How to Obtain 11 12**Obtaining hdc** 13 14Obtain hdc from the **toolchains** directory of the OpenHarmony SDK. 15 16**Example** 17 18The following uses the Windows operating system as an example: 19 20Obtain the SDK for Windows, and copy **hdc.exe** from **toolchains** to a directory on the disk. 21 22 23## NOTICE 24 25- If an exception occurs when you are using hdc, run the **hdc kill** command to terminate the hdc service or run the **hdc start -r** command to restart the service process. 26 27- If no device information is obtained after **hdc list targets** is executed, check whether the hdc process exists in the **Task Manager**. If yes, terminate the process. 28 29 30## Option-related Commands 31 32The following commands are available: 33 34 35- **-h/help -v/version** 36 Displays hdc help or version information. 37 38 **Table 1** Command description 39 40 | Return Value| Description| 41 | -------- | -------- | 42 | Required information| hdc help or version information.| 43 44 Example: 45 46 47 ``` 48 hdc -h / hdc help 49 ``` 50 51 52 ``` 53 hdc -v / hdc version 54 ``` 55 56- **-l 0-5** 57 Sets the levels of the logs generated during the running of the tool. The default value is **LOG_INFO**. 58 59 **Table 2** Command description 60 61 | Parameter| Description| 62 | -------- | -------- | 63 | 0 | LOG_OFF | 64 | 1 | LOG_FATAL| 65 | 2 | LOG_WARN | 66 | 3 | LOG_INFO | 67 | 4 | LOG_DEBUG| 68 | 5 | LOG_ALL | 69 70 Example: 71 72 ``` 73 hdc -l5 start 74 ``` 75 76- **-t key** 77 Connects to a device based on the specified key. 78 79 **Table 3** Command description 80 81 | Parameter| Description| 82 | -------- | -------- | 83 | key | Key that identifies the device to connect. The value can be in the *IP address:port number* format or be a USB serial number.| 84 | Return Value| Description| 85 | 1. error: device '\*\*\*' not found<br>2. Nothing to do ...| 1. The device does not exist.<br>2. The command appended to **-t key** does not exist.| 86 87 Example: 88 89 **-t key** must be used with a command. The following uses **shell** as an example: 90 91 **hdc list targets** (Obtain device information.) 92 93 **hdc -t *key* shell** (Replace *key* with the device identifier obtained) 94 95 > **NOTE**<br> 96 > You can connect to multiple devices from the device you use for development. Each device has a unique key. The key can be *IP address:port number* for a device to be connected over the network or the serial number for a device to be connected through USB. A specific command must be used with this command. 97 98- **checkserver** 99 Obtains the client and server version information. 100 101 **Table 4** Command description 102 103 | Return Value| Description| 104 | -------- | -------- | 105 | Client version: server version: | Client and server version information.| 106 107 Example: 108 109 ``` 110 hdc checkserver 111 ``` 112 113 114## Displaying Device Information 115 116Run the following command to display all connected devices: 117 118 119``` 120list targets[-v] 121``` 122 123**Table 5** Command description 124 125| Parameter| Description| 126| -------- | -------- | 127| -v | Displays detailed device information.| 128| Return Value| **Description**| 129| 1. Device information<br>2. [Empty]| 1. A list of connected devices.<br>2. No device information is found.| 130 131 132Example: 133 134 135 136``` 137hdc list targets 138``` 139 140 141 142``` 143hdc list targets -v 144``` 145 146 147## Service Process Commands 148 149The following commands are available: 150 151 152- **target mount** 153 Mounts the **/system** partition in read/write mode. 154 155 **Table 6** Command description 156 157 | Parameter| Description| 158 | -------- | -------- | 159 | –| –| 160 | Return Value| **Description**| 161 | 1. Mount finish<br>2. Error information| 1. The operation is successful.<br>2. The operation fails.| 162 163 Example: 164 165 166 ``` 167 hdc target mount 168 ``` 169 170- **target boot** 171 Boots the device. 172 173 Example: 174 175 176 ``` 177 hdc target boot 178 ``` 179 180- **smode [-r]** 181 Grants the **root** permission to the background hdc service. Use **off** to revoke the granted permissions. 182 183 Example: 184 185 186 ``` 187 hdc smode 188 ``` 189 190 191 ``` 192 hdc smode -r 193 ``` 194 195- **kill [-r]** 196 Terminates the hdc process. 197 198 **Table 7** Command description 199 200 | Parameter| Description| 201 | -------- | -------- | 202 | -r | Restarts the hdc process.| 203 | Return Value| **Description**| 204 | 1. Kill server finish<br>2. Error information| 1. The operation is successful.<br>2. The operation fails.| 205 206 Example: 207 208 ``` 209 hdc kill 210 ``` 211 212- **start [-r]** 213 Starts the hdc process. 214 215 **Table 8** Command description 216 217 | Parameter| Description| 218 | -------- | -------- | 219 | -r | Restarts the hdc process if it has started.| 220 | Return Value| Description| 221 | –| –| 222 223 Example: 224 225 ``` 226 hdc start 227 ``` 228 229 230## Network Commands 231 232The following commands are available: 233 234 235- **tconn host[:port][-remove]** 236 Connects to a device with the specified IP address and port number. 237 238 **Table 9** Command description 239 240 | Parameter| Description| 241 | -------- | -------- | 242 | host[:port] | IP address and port number for the device to connect.| 243 | -remove | Disconnects from the specified device.| 244 | Return Value| Description| 245 | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.| 246 247 Example: 248 249 250 ``` 251 hdc tconn 192.168.0.100:8710 252 ``` 253 254- **tmode usb** 255 Restarts the daemon process and connects to the device using USB preferentially. 256 257 **Table 10** Command description 258 259 | Parameter| Description| 260 | -------- | -------- | 261 | –| –| 262 | Return Value| Description| 263 | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.| 264 265 Example: 266 267 268 ``` 269 hdc tmode usb 270 ``` 271 272- **tmode port port-number** 273 Restarts the daemon process and connects to the device over TCP preferentially. If the TCP connection fails, a USB connection will be initiated. 274 275 **Table 11** Command description 276 277 | Parameter| Description| 278 | -------- | -------- | 279 | port-number | Port used to connect to the device.| 280 | Return Value| Description| 281 | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.| 282 283 Example: 284 285 286 ``` 287 hdc tmode port 8710 288 ``` 289 290 > **NOTE**<br> 291 > After this command is executed, the remote daemon process exits and restarts, and a TCP connection is set up by default. If the port number is not specified in the command, a random port will be used to connect to the device. 292 293- **fport localnode remotenode** 294 Forwards data from a host port to a device port. 295 296 Example: 297 298 299 ``` 300 hdc fport tcp:1234 tcp:1080 301 ``` 302 303- **rport remotenode localnode** 304 Forwards data from a device port to a host port. 305 306 Example: 307 308 309 ``` 310 hdc rport tcp:2080 tcp:2345 311 ``` 312 313- **fport ls** 314 Lists all port forwarding tasks. 315 316 **Table 12** Command description 317 318 | Parameter| Description| 319 | -------- | -------- | 320 | –| –| 321 | Return Value| **Description**| 322 | 'tcp:1234 tcp:1080' [Forward] | Forward port forwarding task.| 323 | 'tcp:2080 tcp:2345' [Reverse] | Reverse port forwarding task.| 324 325 Example: 326 327 328 ``` 329 hdc fport ls 330 ``` 331 332- **fport rm** 333 Deletes a port forwarding task. 334 335 Example: 336 337 338 ``` 339 hdc fport rm tcp:1234 tcp:1080 340 ``` 341 342 343## File Commands 344 345The following commands are available: 346 347 348- **file send local remote** 349 Sends a file to a remote device. 350 351 **Table 13** Command description 352 353 | Parameter| Description| 354 | -------- | -------- | 355 | local | Path of the file to send.| 356 | remote | Destination path on the remote device.| 357 | Return Value| Description| 358 | 1. Error information<br>2. File transfer result| 1. The operation fails.<br>2. The operation is successful.| 359 360 Example: 361 362 363 ``` 364 hdc file send E:\a.txt /data/local/tmp/a.txt 365 ``` 366 367- **file recv [-a] remote local** 368 Receives a file from a remote device. 369 370 **Table 14** Command description 371 372 | Parameter| Description| 373 | -------- | -------- | 374 | -a | Retains the file timestamp.| 375 | local | Destination path on the local device.| 376 | remote | File path on the remote device.| 377 | Return Value| Description| 378 | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.| 379 380 Example: 381 382 383 ``` 384 hdc file recv /data/local/tmp/a.txt ./a.txt 385 ``` 386 387 388## App Commands 389 390The following commands are available: 391 392 393- **install [-r/-d/-g] *package*** 394 Installs an OpenHarmony app. 395 396 **Table 15** Command description 397 398 | Parameter| Description| 399 | -------- | -------- | 400 | package | OpenHarmony app installation package.| 401 | -r | Replaces the existing app.| 402 | -d | Allows downgrade installation.| 403 | -g | Grants permissions dynamically.| 404 | Return Value| Description| 405 | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.| 406 407 Example: 408 409 410 ``` 411 hdc install hwadmin.hap 412 ``` 413 414- **uninstall [-k] package** 415 Uninstalls an OpenHarmony app. 416 417 **Table 16** Command description 418 419 | Parameter| Description| 420 | -------- | -------- | 421 | package | OpenHarmony app installation package.| 422 | -k | Retains **/data/cache**.| 423 | Return Value| Description| 424 | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.| 425 426 Example: 427 428 429 ``` 430 hdc uninstall package 431 ``` 432 433 434## Debugging Commands 435 436The following commands are available: 437 438 439- **hilog** 440 Obtains logs for debugging. 441 442 **Table 17** Command description 443 444 | Parameter| Description| 445 | -------- | -------- | 446 | –| –| 447 | Return Value| **Description**| 448 | Log obtained| Log information obtained.| 449 450 Example: Obtain log information. 451 452 453 ``` 454 hdc hilog 455 ``` 456 457 Clear the cached logs. 458 459 460 ``` 461 hdc shell "hilog -r" 462 ``` 463 464- **shell [_command_]** 465 Executes a command remotely or enters an interactive command environment. 466 467 **Table 18** Command description 468 469 | Parameter| Description| 470 | -------- | -------- | 471 | command | Command to execute.| 472 | Return Value| **Description**| 473 | Returned information| Command execution result.| 474 475 Example: 476 477 478 ``` 479 hdc shell 480 ``` 481 482- **jpid** 483 Obtains the list of processes that can be debugged. 484 485 Example: 486 487 488 ``` 489 hdc jpid 490 ``` 491 492 493## FAQs 494 495 496### Failed to Connect the Target Device 497 498- **Symptom** 499 After the **hdc list targets** command is executed, **[Empty]** is displayed. 500 501- **Solution** 502 - The device cannot be identified. 503 Check whether **HDC Device** exists under the **Universal Serial Bus controllers** in the **Device Manager**. If **HDC Device** does not exist, the device cannot be connected. In this case, disconnect and then reconnect the USB connection between the test PC and the OpenHarmony device, or burn the latest image. 504 - hdc works improperly. 505 Run the **hdc kill** command to terminate the hdc process or run the **hdc start -r** command to restart the hdc service. Then, run the **hdc list targets** command to check whether device information can be obtained. 506 - The hdc version does not match the device. 507 If the latest image is burnt on the device, the latest hdc version must be used. 508 509 510### Failed to Run hdc 511 512- **Symptom** 513 The **hdc.exe** file cannot be executed. 514 515- **Solution** 516 1. Check the running environment. 517 Ubuntu 18.04 64-bit or later is recommended for Linux.<br>If **libc++.so** is incorrectly referenced, run the **ldd** or **readelf** command to check the referenced library. <br>Windows 10 64-bit is recommended for Windows. If the Windows winusb library of an earlier version is missing, use Zadig to update the library. For composite devices, use Zadig tool to install the libusb-win32 driver. 518 2. Run **hdc.exe**. 519 **hdc.exe** requires no installation. You can use it after placing it to a local directory or adding the tool path to environment variables. Run **cmd** and then the **hdc** command to start the tool. 520 521 522### Accessing a hdc Server from the hdc Client 523 524- **Scenario** 525 526 Use hdc to connect to a remote server from the local client. 527 528- **Procedure** 529 1. Shut down the local hdc server. 530 ``` 531 hdc kill 532 ``` 533 2. Run **-s [ip:]port -m** to start the remote server. 534 ``` 535 hdc -s severIP:8710 -m 536 ``` 537 3. Run **-s [ip:]port** *command* to execute a command on the remote server. 538 ``` 539 hdc -s severIP:8710 list targets 540 ``` 541