> For the complete documentation index, see [llms.txt](https://freeioe.gitbook.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://freeioe.gitbook.io/doc/reference/app/port/helper.md).

# 帮助模块

***

## 应用通讯端口帮助函数模块

本模块封装一些有助与使用通讯端口的函数。帮助用户快速开发FreeIOE应用。

[使用参考](https://github.com/freeioe/freeioe_example_apps/blob/master/example/serial_socket/app.lua)

## 成员函数

### read\_socket

读取套接字数据。

```lua
function _M.read_socket(sock, len, dump)
end
```

#### 参数说明

* sock socket对象 (socketchannel的request中response函数传入的socket对象)
* len 数据长度
* dump 报文输出回调函数 function(string\_data)

#### 返回值

读取成功则读到的数据，否则返回nil

### read\_serial

读取串口数据。

```lua
function _M.read_serial(serial, len, dump, timeout)
end
```

#### 参数说明

* serial serial对象 (serialchannel的request中response函数传入的serial对象)
* len 数据长度
* dump 报文输出回调函数 `function(string_data)`
* timeout 读取超时，单位是ms。默认是3000ms

#### 返回值

读取成功则读到的数据，否则返回nil


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://freeioe.gitbook.io/doc/reference/app/port/helper.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
