modbus
modbus copied to clipboard
Migrate to modern .NET with SDK-style projects for cross-platform support
The solution targeted .NET Framework 4.5 using legacy project formats, preventing builds on systems without Windows-specific framework packs and limiting cross-platform deployment.
Changes
Project Structure
- Core: Converted to SDK-style project with multi-targeting (.NET Standard 2.0 + .NET 8.0)
- Terminal: Converted to SDK-style project targeting .NET 8.0
- Removed obsolete
packages.configandApp.configfiles
Dependencies
- Added
System.IO.Ports8.0.0 for cross-platform SerialPort support - Updated
CommandLineParser1.9.71 → 2.9.1
Code Updates
- Updated Terminal to use CommandLineParser 2.x API (removed
DefaultValueattribute,HelpOptionmethod) - Fixed broken Terminal example code (incorrect API usage with
ModbusRtuSessionconstructor andSendRequestoverload)
Before/After
Before:
// Didn't compile - missing slaveAddress in constructor
var session = new ModbusRtuSession(new ModbusProtocolImpl(stream));
var response = session.SendRequest<ResponseFunc03>(1, 3, func03); // Wrong signature
After:
var session = new ModbusRtuSession(new ModbusProtocolImpl(stream), slaveAddress: 1);
var response = session.SendRequest<ResponseFunc03>(functionCode: 3, func03);
The library now builds on Windows, Linux, and macOS with modern .NET tooling.
Original prompt
This section details on the original issue you should resolve
<issue_title>Modern .NET support</issue_title> <issue_description>Hi! Your solution lacks modern .NET support, which limits cross-platform compatibility. Please consider adding support for recent .NET versions to improve usability across different platforms.
Thank you!</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes sontx/modbus#4
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.