Skip to content

feat: support FC22 in servers - #619

Merged
yaacov merged 2 commits into
yaacov:mainfrom
yguyot:feat/server-fc22
Jul 22, 2026
Merged

feat: support FC22 in servers#619
yaacov merged 2 commits into
yaacov:mainfrom
yguyot:feat/server-fc22

Conversation

@yguyot

@yguyot yguyot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

  • FC22 is supported by the client but not by the servers.

Solution

  • Add FC22 support to TCP and RTU servers.
  • Add setRegisterMask to the server vector.
  • Support synchronous, callback, and Promise handlers.
  • Handle invalid requests and vector errors.

Tests

  • Add TCP and RTU coverage.
  • Cover success and error scenarios.
  • Lint and full test suite passing.

Documentation

  • Update TypeScript declarations.
  • Update the server examples.
  • Update the README with the new server vector method.

Summary by CodeRabbit

  • New Features
    • Added Modbus Function Code 22 (Mask Write Register) handling on both TCP and serial servers.
    • Supports callback-, Promise-, and synchronous-style setRegisterMask implementations.
    • Returns correct FC22 responses and Modbus exceptions for unsupported or failing requests.
  • Documentation
    • Updated the ModbusTCP server README example and added public type declarations for setRegisterMask.
  • Tests
    • Added FC22 test coverage across TCP variants and serial, including success, malformed requests, and failure/exception scenarios.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9f54ad2-bbc1-421b-be6d-09336a969ea5

📥 Commits

Reviewing files that changed from the base of the PR and between 131c2fa and 8a76a2e.

📒 Files selected for processing (1)
  • examples/server.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/server.js

📝 Walkthrough

Walkthrough

Modbus serial and TCP servers now support Modbus function code 22, including typed vector handlers, callback/Promise/synchronous execution, response generation, error handling, examples, and protocol tests.

Changes

Modbus FC22 mask-write support

Layer / File(s) Summary
FC22 contract and handler
ServerTCP.d.ts, servers/servertcp_handler.js, servers/serverserial.js, servers/servertcp.js
Adds the optional setRegisterMask API, dispatches function code 22, parses mask parameters, invokes supported handler styles, and returns echoed responses or Modbus errors.
Serial and TCP behavior coverage
test/servers/serverserial.test.js, test/servers/servertcp*.test.js
Tests successful masking, response frames, synchronous/callback/Promise failures, missing handlers, short requests, and unit IDs.
Example vector support
README.md, examples/server.js
Adds setRegisterMask logging callbacks to the server examples.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ModbusClient
  participant ModbusServer
  participant maskWriteRegister
  participant setRegisterMask
  ModbusClient->>ModbusServer: Send FC22 request
  ModbusServer->>maskWriteRegister: Dispatch request
  maskWriteRegister->>setRegisterMask: Pass address and masks
  setRegisterMask-->>maskWriteRegister: Complete or return error
  maskWriteRegister-->>ModbusClient: Echo response or exception
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding FC22 support to the servers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/server.js`:
- Line 25: Update the setRegisterMask function signature in the example to
accept unitID as the fourth parameter after addr, andMask, and orMask, and
include it in the existing log output so the example matches the FC22 invocation
contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a81a4d26-580e-43e2-bc6b-8a4a31656b4e

📥 Commits

Reviewing files that changed from the base of the PR and between 3200f11 and 131c2fa.

📒 Files selected for processing (10)
  • README.md
  • ServerTCP.d.ts
  • examples/server.js
  • servers/serverserial.js
  • servers/servertcp.js
  • servers/servertcp_handler.js
  • test/servers/serverserial.test.js
  • test/servers/servertcp.test.js
  • test/servers/servertcpCallback.test.js
  • test/servers/servertcpPromise.test.js

Comment thread examples/server.js Outdated
@yaacov

yaacov commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Thank you for the pull request 💚

please address the automatic comment

@yaacov
yaacov merged commit 38fc8ec into yaacov:main Jul 22, 2026
4 checks passed
@yguyot

yguyot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Is it possible to get a npm release ? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants