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