-
-
Notifications
You must be signed in to change notification settings - Fork 362
doc(Modbu): add ModbusFactory documentation #6722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,119 +17,45 @@ | |||||
| [NotNull] | ||||||
| private IModbusFactory? ModbusFactory { get; set; }</Pre> | ||||||
|
|
||||||
| <Pre>var client = ModbusFactory.GetOrCreateTcpMaster("bb", options => | ||||||
| { | ||||||
| options.LocalEndPoint = new IPEndPoint(IPAddress.Loopback, 0); | ||||||
| });</Pre> | ||||||
| <p class="code-label">3. 通过工厂获得相对应协议 <code>IModbusClient</code> 实例</p> | ||||||
|
|
||||||
| <p class="code-label">3. 使用方法</p> | ||||||
| <p>Modbus 可以通过不同的物理介质传输,主要有以下几种方式:</p> | ||||||
|
|
||||||
| <ul class="ul-demo"> | ||||||
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>ConnectAsync</code> 连接远端节点</li> | ||||||
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SendAsync</code> 发送协议数据</li> | ||||||
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>Close</code> 关闭连接</li> | ||||||
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SetDataHandler</code> 方法设置数据处理器</li> | ||||||
| <li>通过 <code>ITcpSocketClient</code> 实例属性 <code>ReceivedCallBack</code> 方法设置接收数据处理器(注意:此回调未做任何数据处理为原始数据)</li> | ||||||
| <li><code>Modbus RTU (Remote Terminal Unit)</code>: 采用二进制编码,使用紧凑的二进制表示数据,效率高,是最常用的串行通信模式。通常基于 <code>RS-485</code>(支持多设备)或 <code>RS-232</code>(点对点)物理层,CRC 校验确保数据完整性。</li> | ||||||
| <li><code>Modbus TCP/IP</code>: 运行于以太网上,使用 <code>TCP/IP</code> 协议,默认端口 <code>502</code>。它在 Modbus RTU 协议基础上添加了 MBAP 报文头,并由于TCP本身是可靠连接的服务,因此去掉了 CRC 校验码。</li> | ||||||
| </ul> | ||||||
|
|
||||||
| <p class="code-label">4. 数据处理器</p> | ||||||
|
|
||||||
| <p>在我们实际应用中,建立套接字连接后就会进行数据通信,数据通信不会是杂乱无章的随机数据,在应用中都是有双方遵守的规约简称通讯协议,在通讯协议的约束下,发送方与接收方均根据通讯协议进行编码或解码工作,将数据有条不紊的传输</p> | ||||||
|
|
||||||
| <p>数据处理器设计初衷就是为了契合通讯协议大大简化我们开发逻辑,我们已通讯协议每次通讯电文均为 <b>4</b> 位定长举例说明,在实际的通讯过程中,我们接收到的通讯数据存在粘包或者分包的现象</p> | ||||||
| <p><code>IModbusFactory</code> 实例方法</p> | ||||||
|
|
||||||
| <ul class="ul-demo"> | ||||||
| <li><b>粘包</b>:比如我们期望收到 <b>1234</b> 四个字符,实际上我们接收到的是 <b>123412</b> 多出来的 <b>12</b> 其实是下一个数据包的内容,我们需要截取前 4 位数据作为一个数据包才能正确处理数据,这种相邻两个通讯数据包的粘连称为<b>粘包</b></li> | ||||||
| <li><b>分包</b>:比如我们期望收到 <b>1234</b> 四个字符,实际上我们可能分两次接收到,分别是 <b>12</b> 和 <b>34</b>,我们需要将两个数据包拼接成一个才能正确的处理数据。这种情况称为<b>分包</b></li> | ||||||
| <li>通过 <code>GetOrCreateTcpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li> | ||||||
| <li>通过 <code>GetOrCreateUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li> | ||||||
| <li>通过 <code>GetOrCreateRtuMaster</code> 方法得到 <code>IModbusRtuClient</code> 实例</li> | ||||||
| <li>通过 <code>GetOrCreateRtuOverTcpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li> | ||||||
| <li>通过 <code>GetOrCreateRtuOverUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li> | ||||||
|
||||||
| <li>通过 <code>GetOrCreateRtuOverUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li> | |
| <li>通过 <code>GetOrCreateRtuOverUdpMaster</code> 方法得到 <code>IModbusUdpClient</code> 实例</li> |
Copilot
AI
Sep 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation using tabs instead of spaces. The first line uses spaces while lines 35-36 use tabs. This should be consistent throughout the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GetOrCreateUdpMaster method should return IModbusUdpClient, not IModbusTcpClient. UDP and TCP are different protocols and should have distinct client types.