未验证 提交 408825b8 编写于 作者: O openharmony_ci 提交者: Gitee

!10585 [翻译完成】#I5RQ2G

Merge pull request !10585 from Annie_wang/PR9453
# hdc\_std<a name="EN-US_TOPIC_0000001080478129"></a> # hdc_std
hdc\_std \(OpenHarmony Device Connector\) is a command line tool provided by OpenHarmony for debugging. With this tool, you can interact with real devices or simulators from a Windows or Linux OS.
This section describes how to set up the hdc\_std environment and use its common commands. OpenHarmony Device Connector (hdc_std) 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.
## Preparations<a name="section05992022154916"></a>
**Obtaining hdc\_std:** The following describes how to obtain and use hdc_std.
Obtain **hdc\_std** from the **prebuilt** directory at [developtools\_hdc\_standard](https://gitee.com/openharmony/developtools_hdc_standard).
**Example:** ## How to Obtain
To obtain hdc\_std on Windows, obtain the executable file **hdc\_std.exe** from **prebuilt/windows** and place it in a directory on the disk. Obtain hdc_std from the **toolchains** directory of the OpenHarmony SDK.
## Important Notes<a name="section19543134915210"></a> **Example**
- If an exception occurs when you are using hdc\_std, run the **hdc\_std kill** command to kill the hdc\_std service or run the **hdc\_std start -r** command to restart the service process. If you use hdc_std on Windows, obtain the SDK for Windows and copy **hdc_std.exe** from **toolchains** to a directory on the disk.
- If no device information is obtained after **hdc\_std list targets** is executed, use the task manager to check whether the **hdc.exe** process exists. If it exists, kill the process.
## Option-related Commands<a name="section618522925119"></a>
The following commands are available: ## NOTICE
### -h/help -v/version<a name="section51533527212"></a>
Obtains hdc help and version information.
**Table 1** Command description
| Return Value | Description |
| -------- | -------- |
| Required information | hdc help or version information. |
Examples: - If an exception occurs when you are using hdc_std, run the **hdc_std kill** command to terminate the hdc_std service or run the **hdc_std start -r** command to restart the service process.
hdc\_std -h / hdc\_std help - If no device information is obtained after **hdc_std list targets** is executed, check whether the hdc_std process exists in the **Task Manager**. If yes, terminate it.
hdc\_std -v / hdc\_std version
### -t key<a name="section1180555115159"></a> ## Option-related Commands
Connects to a device with a specified key. The following commands are available:
**Table 2** Command description
| Parameter | Description | - **-h/help -v/version**
Displays hdc_std help or version information.
**Table 1** Command description
| **Return Value**| **Description**|
| -------- | -------- | | -------- | -------- |
| key | Key that identifies the device. The value is in the *IP address:Port* format or is a USB serial number. | | Required information| hdc_std help or version information.|
| **Return Value** | **Description** |
| 1. error: device '***' not found<br/>2. Nothing&nbsp;to&nbsp;do... | 1. The device does not exist<br>2. The command appended to **-t key** does not exist. | Example:
Examples: ```
hdc_std -h / hdc_std help
This option must be used together with a specific operation command. The following uses the shell command as an example: ```
**hdc\_std list targets** \(obtain device information\) ```
hdc_std -v / hdc_std version
**hdc\_std -t _key_ shell** \(replace _key_ with the device information obtained\) ```
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>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 connected through a network or the serial number for a device connected through USB.
- **-l 0-5**
## Querying the Device List<a name="section174891132104218"></a>
Sets the levels of the logs generated during the running of the tool. The default value is **LOG_INFO**.
The following command is used to query the device list:
**Table 2** Command description
### list targets\[-v\]<a name="section12911142313168"></a>
| Parameter| Description|
Displays all the connected devices. | -------- | -------- |
| 0 | LOG_OFF |
**Table 3** Command description | 1 | LOG_FATAL|
| 2 | LOG_WARN |
| Parameter | Description | | 3 | LOG_INFO |
| -------- | -------- | | 4 | LOG_DEBUG|
| -v | Prints detailed device information. | | 5 | LOG_ALL |
| **Return Value** | **Description** |
| 1. Device information<br/>2. [Empty] | 1. A list of connected devices.<br/>2. No device information is found. | Example:
Examples: ```
hdc_std -l5 start
hdc\_std list targets ```
- **-t key**
Connects to a device based on the specified key.
**Table 3** Command description
| Parameter| Description|
| -------- | -------- |
| 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.|
| **Return Value** | **Description** |
| 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.|
hdc\_std list targets -v Example:
## Service Process Commands<a name="section680531510497"></a> **-t key** must be used with a command. The following uses **shell** as an example:
The following commands are available: **hdc_std list targets** (obtain device information)
### target mount<a name="section396717571168"></a> **hdc_std -t *key* shell** (replace *key* with the device identifier obtained)
Mounts a partition, such as **/system**, with the read and write permissions. > **NOTE**<br>
> 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.
**Table 4** Command description - **checkserver**
Obtains the client and server version information.
**Table 4** Command description
| Parameter | Description | | Return Value| Description|
| -------- | -------- | | -------- | -------- |
| None | None | | Client version: server version: | Client and server version information.|
| **Return Value** | **Description** |
| 1. Mount&nbsp;finish<br/>2. Returned information | 1. Information returned when the operation is successful.<br/>2. Information returned when the operation fails. |
Example: Example:
hdc\_std target mount
### smode \[off\]<a name="section179951621713"></a>
Grants the root permission to a background service process. The **off** option is used to revoke the granted permission. ```
hdc_std checkserver
```
Examples:
hdc\_std smode ## Displaying Device Information
hdc\_std smode off Run the following command to display all connected devices:
### kill \[-r\]<a name="section419144621712"></a>
Stops a service process. ```
list targets[-v]
```
**Table 5** Command description **Table 5** Command description
| Parameter | Description | | Parameter| Description|
| -------- | -------- | | -------- | -------- |
| -r | Triggers the service restart. | | -v | Displays detailed device information.|
| **Return Value** | **Description** | | **Return Value** | **Description**|
| 1. Kill&nbsp;server&nbsp;finish<br/>2. Error information | 1. Information returned when the operation is successful.<br/>2. The operation fails. | | 1. Device information<br>2. [Empty]| 1. A list of connected devices.<br>2. No device information is found.|
Example:
hdc\_std kill
### start \[-r\]<a name="section184811812183"></a>
Starts a service process. Example:
**Table 6** Command description ```
hdc_std list targets
```
| Parameter | Description | ```
| -------- | -------- | hdc_std list targets -v
| -r | Restarts the service process if it has started. | ```
| **Return Value** | **Description** |
| None | None |
Examples:
hdc\_std start ## Service Process Commands
## Network Commands<a name="section71176123212"></a>
The following commands are available: The following commands are available:
### tconn _host_\[:_port_\]\[-remove\]<a name="section191911334206"></a> - **target mount**
Connects to a device with a specified IP address and port number. Mounts the **/system** partition in read/write mode.
**Table 7** Command description **Table 6** Command description
| Parameter | Description | | Parameter| Description|
| -------- | -------- | | -------- | -------- |
| host[:port] | IP address and port number of the device to be connected. | | –| –|
| -remove | Disconnects from the specified device. | | **Return Value**| **Description**|
| **Return Value** | **Description** | | 1. Mount&nbsp;finish<br>2. Error information| 1. The operation is successful.<br>2. The operation fails.|
| 1. Error information<br/>2. None | 1. The operation fails.<br/>2. The operation is successful. |
Example:
Example:
```
hdc\_std tconn 192.168.0.100:8710 hdc_std target mount
```
### tmode usb<a name="section17840182562015"></a>
Restarts the daemon process and connects to the device using USB.
**Table 8** Command description - **target boot**
| Parameter | Description | Boots the device.
Example:
```
hdc_std target boot
```
- **smode [-r]**
Grants the **root** permission to the background hdc service. Use **off** to revoke the granted permissions.
Example:
```
hdc_std smode
```
```
hdc_std smode -r
```
- **kill [-r]**
Terminates the hdc process.
**Table 7** Command description
| Parameter| Description|
| -------- | -------- | | -------- | -------- |
| None | None | | -r | Restarts the hdc process.|
| **Return Value** | **Description** | | **Return Value**| **Description**|
| 1. Error information<br/>2. None | 1. The operation fails.<br/>2. The operation is successful. | | 1. Kill&nbsp;server&nbsp;finish<br>2. Error information| 1. The operation is successful.<br>2. The operation fails.|
Example: Example:
hdc\_std tmode usb ```
hdc_std kill
```
### tmode port _port-number_<a name="section101113462113"></a> - **start [-r]**
Starts the hdc process.
**Table 8** Command description
Restarts the daemon process and connects to the device over TCP. | Parameter| Description|
| -------- | -------- |
| -r | Restarts the hdc process if it has started.|
| **Return Value**| **Description**|
| –| –|
**Table 9** Command description Example:
| Parameter | Description | ```
| -------- | -------- | hdc_std start
| port-number | Port number used to connect to the device. | ```
| **Return Value** | **Description** |
| 1. Error information<br/>2. None | 1. The operation fails.<br/>2. The operation is successful. |
Example:
hdc\_std tmode port 8710
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>After this command is executed, the remote daemon process exits and restarts, and the TCP connection is enabled by default. If you do not include **port-number** in this command, a random port will be used to connect to the device.
## File Commands<a name="section173133523013"></a> ## Network Commands
The following commands are available: The following commands are available:
### file send _local remote_<a name="section126223231307"></a>
Sends a file to a remote device.
**Table 10** Command description
| Parameter | Description | - **tconn host[:port][-remove]**
| -------- | -------- |
| local | Path of the file to send. |
| remote | Destination path on the remote device. |
| **Return Value** | **Description** |
| 1. Error information<br/>2. File transfer result | 1. The operation fails.<br/>2. The operation is successful. |
Example:
hdc\_std file send E:\\a.txt /data/local/tmp/a.txt
### file recv \[-a\] _remote local_<a name="section26966541304"></a> Connects to a device with the specified IP address and port number.
Receives a file from a remote device. **Table 9** Command description
**Table 11** Command description | Parameter| Description|
| Parameter | Description |
| -------- | -------- | | -------- | -------- |
| -a | File retention timestamp mode. | | host[:port] | IP address and port number for the device to connect.|
| local | Path on the local device to receive the file. | | -remove | Disconnects from the specified device.|
| remote | File path on the remote device. | | **Return Value**| **Description**|
| **Return Value** | **Description** | | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|
| 1. Error information<br/>2. None | 1. The operation fails.<br/>2. The operation is successful. |
Example:
Example:
```
hdc\_std file recv /data/local/tmp/a.txt ./a.txt hdc_std tconn 192.168.0.100:8710
```
## App Commands<a name="section2072647133819"></a>
- **tmode usb**
Restarts the daemon process and connects to the device using USB preferentially.
**Table 10** Command description
| Parameter| Description|
| -------- | -------- |
| –| –|
| **Return Value**| **Description**|
| 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|
Example:
```
hdc_std tmode usb
```
- **tmode port port-number**
Restarts the daemon process and connects to the device over TCP preferentially. If the TCP connection fails, a USB connection will be initiated.
**Table 11** Command description
| Parameter| Description|
| -------- | -------- |
| port-number | Port used to connect to the device.|
| **Return Value**| **Description**|
| 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|
Example:
```
hdc_std tmode port 8710
```
> **NOTE**<br>
> 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.
- **fport localnode remotenode**
Forwards data from a host port to a device port.
Example:
```
hdc_std fport tcp:1234 tcp:1080
```
- **rport remotenode localnode**
Forwards data from a device port to a host port.
Example:
```
hdc_std rport tcp:2080 tcp:2345
```
- **fport ls**
Lists all port forwarding tasks.
**Table 12** Command description
| Parameter| Description|
| -------- | -------- |
| –| –|
| **Return Value**| **Description**|
| 'tcp:1234 tcp:1080' [Forward] | Forward port forwarding task.|
| 'tcp:2080 tcp:2345' [Reverse] | Reverse port forwarding task.|
Example:
```
hdc_std fport ls
```
- **fport rm**
Deletes a port forwarding task.
Example:
```
hdc_std fport rm tcp:1234 tcp:1080
```
## File Commands
The following commands are available: The following commands are available:
### install \[-r/-d/-g\] _package_<a name="section49615195111"></a>
Installs the OpenHarmony application.
**Table 12** Command description - **file send local remote**
Sends a file to a remote device.
**Table 13** Command description
| Parameter | Description | | Parameter| Description|
| -------- | -------- | | -------- | -------- |
| package | OpenHarmony application installation package. | | local | Path of the file to send.|
| -r | Replaces an existing application. | | remote | Destination path on the remote device.|
| -d | Allows downgraded installation. | | **Return Value**| **Description**|
| -g | Grants permission dynamically. | | 1. Error information<br>2. File transfer result| 1. The operation fails.<br>2. The operation is successful.|
| **Return Value** | **Description** |
| 1. Error information<br/>2. None | 1. The operation fails.<br/>2. The operation is successful. | Example:
```
hdc_std file send E:\a.txt /data/local/tmp/a.txt
```
- **file recv [-a] remote local**
Receives a file from a remote device.
**Table 14** Command description
| Parameter| Description|
| -------- | -------- |
| -a | Retains the file timestamp.|
| local | Destination path on the local device.|
| remote | File path on the remote device.|
| **Return Value**| **Description**|
| 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|
Example: Example:
```
hdc_std file recv /data/local/tmp/a.txt ./a.txt
```
hdc\_std install _hwadmin.hap_
### uninstall \[-k\] _package_<a name="section167618461814"></a> ## App Commands
Uninstalls the OpenHarmony application. The following commands are available:
**Table 13** Command description
| Parameter | Description | - **install [-r/-d/-g]** *package*
Installs an OpenHarmony app.
**Table 15** Command description
| Parameter| Description|
| -------- | -------- | | -------- | -------- |
| package | OpenHarmony application installation package. | | package | OpenHarmony app installation package.|
| -k | Retains **/data/cache**. | | -r | Replaces the existing app.|
| **Return Value** | **Description** | | -d | Allows downgrade installation.|
| 1. Error information<br/>2. None | 1. The operation fails.<br/>2. The operation is successful. | | -g | Grants permissions dynamically.|
| **Return Value**| **Description**|
| 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|
Example:
```
hdc_std install hwadmin.hap
```
- **uninstall [-k] package**
Uninstalls an OpenHarmony app.
**Table 16** Command description
| Parameter| Description|
| -------- | -------- |
| package | OpenHarmony app installation package.|
| -k | Retains **/data/cache**.|
| **Return Value**| **Description**|
| 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|
Example: Example:
```
hdc_std uninstall package
```
hdc\_std uninstall _package_
## Debugging Commands<a name="section112861250195015"></a> ## Debugging Commands
The following commands are available: The following commands are available:
### hilog<a name="section32171612221"></a>
Obtains logs for debugging. - **hilog**
**Table 14** Command description Obtains logs for debugging.
| Parameter | Description | **Table 17** Command description
| -------- | -------- |
| None | None |
| **Return Value** | **Description** |
| Returned information | Obtained logs. |
Example: | Parameter| Description|
| -------- | -------- |
hdc\_std hilog | –| –|
| **Return Value**| **Description**|
| Log obtained| Log information obtained.|
Example: Obtain log information.
```
hdc_std hilog
```
Clear the cached logs.
```
hdc_std shell "hilog -r"
```
- **shell** [*command*]
Executes a command remotely or enters an interactive command environment.
**Table 18** Command description
| Parameter| Description|
| -------- | -------- |
| command | Command to execute.|
| **Return Value**| **Description**|
| Returned information| Command execution result.|
### shell \[_command_\]<a name="section524235625"></a> Example:
```
hdc_std shell
```
Executes a command remotely or enters an interactive command environment. - **jpid**
Obtains the list of processes that can be debugged.
Example:
```
hdc_std jpid
```
**Table 15** Command description
| Parameter | Description | ## FAQs
| -------- | -------- |
| command | Command to be executed. |
| **Return Value** | **Description** |
| Returned information | Execution result of the command. |
Examples:
hdc\_std shell ### Failed to Connect to a Device from hdc_std
## Troubleshooting<a name="section592920255582"></a> - **Symptom**
After the **hdc_std list targets** command is executed, **[Empty]** is displayed.
### hdc\_std Fails to Connect to a Device<a name="section74019384588"></a> - **Solution**
- The device cannot be identified.
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.
- hdc_std works improperly.
Run the **hdc kill** command to terminate the hdc_std 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.
- hdc_std does not match the device.
If the latest image is burnt on the device, the latest hdc_std version must be used.
- **Symptom**
**\[Empty\]** is displayed in the output after the **hdc\_std list targets** command is executed. ### hdc_std Fails to Run
- **Solutions** - **Symptom**
1. The device cannot be identified.
After you click **hdc_std.exe**, the file fails to execute.
- **Solution**
**hdc_std.exe** requires no installation. You can use it after placing it to a local directory or adding the tool path to environment variables. Run the **cmd** command and then run the **hdc_std** command to start the tool.
Check whether **HDC Device** exists in the universal serial bus device of the device manager. If **HDC Device** does not exist, the device cannot be connected. In this case, remove and then insert the device or burn the latest image for the device.
2. hdc\_std works improperly.
Run the **hdc kill** or **hdc start -r** command to kill or restart the hdc service. Then, run the **hdc list targets** command to check whether device information can be obtained. ### Accessing a Server from the Client
3. hdc\_std does not match the device. 1. Run the **kill** command to stop the local server.
If the latest image is burnt on the device, the latest hdc\_std version must be used. As hdc\_std is updated continuously, obtain hdc\_std of the latest version from the **developtools\_hdc\_standard** repository in the **prebuilt** directory. 2. Run the **-s [ip:]port -m** command to start the remote server.
Example:
```
hdc_std -s severIP:8710 -m
```
## hdc\_std Fails to Run<a name="section6825095917"></a>
- **Symptom** 3. Run **-s [ip:]port** *command* to execute a command on the remote server.
The **hdc\_std.exe** file does not run after being clicked. Example:
- **Solutions** ```
hdc_std -s severIP:8710 list targets
```
**hdc\_std.exe** requires no installation. It can be directly used on a disk or added to environment variables. Open the cmd window and run the **hdc\_std** command to use **hdc\_std.exe**.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册