Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Sep 18, 2025

Link issues

fixes #6752

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Document Modbus client limits and include a performance benchmark comparison, and enhance data conversion logic to support nullable properties.

Bug Fixes:

  • Update DataPropertyConverter to set null on nullable properties when conversion returns null

Enhancements:

  • Add max read/write quantity details for coils, discrete inputs, input registers, and holding registers in the Modbus sample documentation
  • Include a Benchmark project with LongbowModbus sample code and performance comparison against NModbus

Documentation:

  • Add benchmark results table and explanatory text to the ModbusFactories sample page

Tests:

  • Add a Benchmark method simulating concurrent ReadHoldingRegistersAsync calls across multiple Tcp master clients

Copilot AI review requested due to automatic review settings September 18, 2025 03:53
@bb-auto bb-auto bot added the documentation Improvements or additions to documentation label Sep 18, 2025
@bb-auto bb-auto bot added this to the 9.10.0 milestone Sep 18, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 18, 2025

Reviewer's Guide

This PR enhances the Modbus sample by specifying maximum read/write counts and integrating a benchmark project with code and results, and refines the data entity conversion logic by improving attribute handling and adding null assignment support.

Sequence diagram for Modbus benchmark execution

sequenceDiagram
    participant Benchmark
    participant ModbusFactory
    participant IModbusClient
    Benchmark->>ModbusFactory: GetOrCreateTcpMaster() x10
    ModbusFactory-->>Benchmark: IModbusClient x10
    loop For each client
        Benchmark->>IModbusClient: ConnectAsync("127.0.0.1", 502)
        Benchmark->>IModbusClient: ReadHoldingRegistersAsync(0x01, 0x00, 100)
    end
    loop For each client (10)
        loop For each task (10)
            loop For each operation (10)
                Benchmark->>IModbusClient: ReadHoldingRegistersAsync(1, 0, 100)
            end
        end
    end
Loading

Sequence diagram for improved DataEntities property assignment

sequenceDiagram
    participant "PropertyInfo (p)"
    participant "DataPropertyConverterAttribute (attr)"
    participant "DataEntity (entity)"
    "PropertyInfo (p)"->>"DataPropertyConverterAttribute (attr)": GetCustomAttribute()
    alt attr.Type is not null
        "PropertyInfo (p)"->>"DataPropertyConverterAttribute (attr)": ConvertTo(data)
        "PropertyInfo (p)"->>"DataEntity (entity)": SetValue(entity, value/null)
    end
Loading

Class diagram for updated Modbus benchmark logic

classDiagram
    class ModbusFactory {
        +GetOrCreateTcpMaster()
    }
    class IModbusClient {
        +ConnectAsync(ip, port)
        +ReadHoldingRegistersAsync(unitId, address, count)
    }
    class Benchmark {
        +LongbowModbus()
    }
    ModbusFactory --> IModbusClient : creates
    Benchmark --> IModbusClient : uses
Loading

File-Level Changes

Change Details Files
Enhance Modbus sample with max read/write details and benchmark code/results
  • Extended Coils, Discrete Inputs and Registers methods with max operation counts
  • Inserted InitLongbowModbus and LongbowModbus benchmark code snippets
  • Added description of concurrent tasks setup and benchmark result table
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor
Refine data property conversion logic in sockets sample
  • Removed fallback converter lookup and simplified attribute retrieval
  • Added null-to-null assignment support for nullable property types
  • Retained and applied type assignability check for non-null values
src/BootstrapBlazor.Server/Components/Samples/Sockets/DataEntities.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#6752 Add benchmark results for the Modbus component to the documentation.
#6752 Add sample code for the Modbus component demonstrating benchmarking.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Benchmark test results documentation to the Modbus component, demonstrating performance comparisons between LongbowModbus and NModbus libraries.

  • Adds documentation for Modbus operation limits (max read/write quantities for different types)
  • Includes comprehensive benchmark test code showing concurrent socket connections and task execution
  • Provides performance comparison results between LongbowModbus and NModbus implementations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/BootstrapBlazor.Server/Components/Samples/Sockets/DataEntities.razor Updates property converter code example to include null handling logic
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor Adds benchmark documentation with performance test code and results comparison

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Sep 18, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor:63-65` </location>
<code_context>
-    <li>离散输入 (Discrete Inputs) <code>ReadInputsAsync</code></li>
-    <li>输入寄存器 (Input Registers) <code>ReadInputRegistersAsync</code></li>
-    <li>保持寄存器 (Holding Registers) <code>ReadHoldingRegistersAsync</code> <code>WriteRegisterAsync</code> <code>WriteMultipleRegistersAsync</code></li>
+    <li>线圈 (Coils) <code>ReadCoilsAsync</code> <code>WriteCoilAsync</code> <code>WriteMultipleCoilsAsync</code> 最大读取数量 <code>2000</code> 最大写入数量 <code>1968</code></li>
+    <li>离散输入 (Discrete Inputs) <code>ReadInputsAsync</code> 最大读取数量 <code>2000</code></li>
+    <li>输入寄存器 (Input Registers) <code>ReadInputRegistersAsync</code> 最大读取数量 <code>125</code></li>
+    <li>保持寄存器 (Holding Registers) <code>ReadHoldingRegistersAsync</code> <code>WriteRegisterAsync</code> <code>WriteMultipleRegistersAsync</code> 最大读取数量 <code>125</code> 最大写入数量 <code>123</code></li>
 </ul>
+
</code_context>

<issue_to_address>
**suggestion:** Clarify source of Modbus protocol limits for maintainability.

Reference the Modbus specification or add a brief comment explaining the origin of these hardcoded limits to improve maintainability.

```suggestion
<!--
  Modbus 协议的最大读取/写入数量限制参考自 Modbus Application Protocol Specification V1.1b3:
  - 线圈 (Coils) 最大读取数量: 2000, 最大写入数量: 1968
  - 离散输入 (Discrete Inputs) 最大读取数量: 2000
  - 输入寄存器 (Input Registers) 最大读取数量: 125
  - 保持寄存器 (Holding Registers) 最大读取数量: 125, 最大写入数量: 123
  详见: https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf
-->

<p>对应 <code>IModbusClient</code> 实例方法如下</p>

<ul class="ul-demo">
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c198c04) to head (295c213).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6753   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31713     31713           
  Branches      4462      4462           
=========================================
  Hits         31713     31713           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArgoZhang ArgoZhang merged commit 20fba89 into main Sep 18, 2025
4 of 5 checks passed
@ArgoZhang ArgoZhang deleted the doc-socket branch September 18, 2025 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc(Modbus): add Benchmark result

2 participants