# 设备通讯

## 设备通讯

常见的通讯方式有：

* TCP 套接字
* UDP 套接字
* 串口通讯

### TCP 套接字

FreeIOE框架提供TCP Socket连接有以下几种方式:

1. [SocketChannel](https://github.com/cloudwu/skynet/wiki/socketchannel) <br>

   Skynet 框架提供的TCP Socket通讯框架。有两种工作模式:<br>

   * 同步模式
   * 异步模式(需要协议支持Session)
2. [app.socket](https://github.com/freeioe/freeioe_app_book/tree/4014d0dc35e288581baebecf10ff8ce059ccd50d/guide/app_dev/app/socket.md)<br>

   FreeIOE 封装的简易TCP Socket模式。
3. [Skynet Socket模块](https://github.com/cloudwu/skynet/wiki/socket)

参考示例应用库中的/modbus/master /modbus/slave /modbus/gateway 以及 /other/dtu 和 /example/serial\_socket应用

### UDP 套接字

详见 Skynet Socket模块的说明。 并且FreeIOE扩展了Socket中的sendto函数，除了原本的sendto(id, from, data)之外，支持sendto(id, ip, port, data)方式直接指定发送目标的IP和端口信息。

### 串口通讯

FreeIOE 集成了 [librs232](http://github.com/srdgame/librs232) 模块，支持用户访问串口设备。

1. SerialChannel<br>

   同SocketChannel模式的通讯框架
2. [app.serial](https://github.com/freeioe/freeioe_app_book/tree/4014d0dc35e288581baebecf10ff8ce059ccd50d/guide/app_dev/app/serial.md)<br>

   FreeIOE 封装的建议串口模块
3. [rs232](https://github.com/srdgame/librs232/blob/master/bindings/lua/rs232.lua)<br>

   直接使用librs232模块

参考示例应用库中的modbus应用，以及 /other/dtu 和 /other/oliver\_355\_monitor、example/serial 等应用。


---

# Agent Instructions: 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/guide/app_dev/easy/dev_connection.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.
