-
-
Notifications
You must be signed in to change notification settings - Fork 362
doc(Modbus): add IModbusFactory documentation #6717
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
6cba49d
9829649
fbc28ea
00782fc
898354f
8262030
6ee1d0e
0042098
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 |
|---|---|---|
|
|
@@ -118,3 +118,6 @@ univer | |
| rdkit | ||
| webkitdirectory | ||
| dotx | ||
| Modbus | ||
| Protocol | ||
| vditor | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,135 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @page "/modbus-factory" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @inject IStringLocalizer<ModbusFactories> Localizer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <h3>Modbus 串行通讯服务 <code>IModbusFactory</code></h3> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <h4>组件库内置了 Modbus 串行通讯服务</h4> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <PackageTips Name="Longbow.Modbus" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <p class="code-label">1. 服务注入</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Pre>services.AddModbusFactory();</Pre> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <p class="code-label">2. 使用服务</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <p>调用 <code>ModbusFactory</code> 实例方法 <code>GetOrCreateTcpMaster</code> 即可得到一个 <code>IModbusClient</code> 实例。内部提供复用机制,调用两次得到的 <code>IModbusClient</code> 为同一对象</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Pre>[Inject] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [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. 使用方法</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> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+32
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <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>IModbusClient</code> 实例方法 <code>ConnectAsync</code> 连接远端节点(如有需要)</li> | |
| <li>通过 <code>IModbusClient</code> 实例方法 <code>ReadCoilsAsync</code> 或 <code>ReadRegistersAsync</code> 读取数据</li> | |
| <li>通过 <code>IModbusClient</code> 实例方法 <code>WriteSingleCoilAsync</code> 或 <code>WriteSingleRegisterAsync</code> 写入数据</li> | |
| <li>通过 <code>IModbusClient</code> 实例方法 <code>Close</code> 关闭连接</li> | |
| <li>如需处理接收数据,可通过相关事件或回调方法进行设置(具体请参考 <code>IModbusClient</code> 的文档)</li> |
Copilot
AI
Sep 5, 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.
The code example incorrectly shows using ITcpSocketFactory and ITcpSocketClient in Modbus documentation. This should demonstrate IModbusFactory and IModbusClient usage instead.
| private ITcpSocketFactory? TcpSocketFactory { get; set; } | |
| private async Task CreateClient() | |
| { | |
| // 创建 ITcpSocketClient 实例 | |
| var client = TcpSocketFactory.GetOrCreate("localhost", 0); | |
| // 设置数据适配器 使用 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据 | |
| var adapter = new DataPackageAdapter | |
| { | |
| DataPackageHandler = new FixLengthDataPackageHandler(4) | |
| }; | |
| // 如果 client 不销毁切记使用 RemoveDataPackageAdapter 移除回调委托防止内存泄露 | |
| client.AddDataPackageAdapter(adapter, buffer => | |
| { | |
| // buffer 即是接收到的数据 | |
| return ValueTask.CompletedTask; | |
| }); | |
| // 连接远端节点 连接成功后自动开始接收数据 | |
| private IModbusFactory? ModbusFactory { get; set; } | |
| private async Task CreateModbusClient() | |
| { | |
| // 创建 IModbusClient 实例 | |
| var client = ModbusFactory.GetOrCreateTcpMaster("modbus", options => | |
| { | |
| options.LocalEndPoint = new IPEndPoint(IPAddress.Loopback, 0); | |
| }); | |
| // 设置数据包处理器(如有需要,可自定义处理器) | |
| var handler = new FixLengthDataPackageHandler(4); | |
| client.SetDataHandler(handler, buffer => | |
| { | |
| // buffer 即是接收到的数据 | |
| return ValueTask.CompletedTask; | |
| }); | |
| // 连接远端 Modbus 设备 |
Copilot
AI
Sep 5, 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.
Empty code tags with no content. This appears to be incomplete documentation that should either be removed or completed with the intended content.
| <p>使用 <code></code></p> | |
| <p>使用</p> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Samples.Modbus; | ||
|
|
||
| /// <summary> | ||
| /// IModbusFactory 服务说明文档 | ||
| /// </summary> | ||
| public partial class ModbusFactories | ||
| { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Samples; | ||
| namespace BootstrapBlazor.Server.Components.Samples.Sockets; | ||
|
|
||
| /// <summary> | ||
| /// ISocketFactory 服务说明文档 | ||
|
|
||
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.
Using a beta version (9.0.0-beta01) in production code may introduce instability. Consider using a stable release version if available.