DBI.Drivers.Modbus 1.1.1

dotnet add package DBI.Drivers.Modbus --version 1.1.1
                    
NuGet\Install-Package DBI.Drivers.Modbus -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DBI.Drivers.Modbus" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DBI.Drivers.Modbus" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="DBI.Drivers.Modbus" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DBI.Drivers.Modbus --version 1.1.1
                    
#r "nuget: DBI.Drivers.Modbus, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DBI.Drivers.Modbus@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DBI.Drivers.Modbus&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=DBI.Drivers.Modbus&version=1.1.1
                    
Install as a Cake Tool

DBI.Drivers.Modbus

.NET License Build Status

Liên kết

Mô tả

DBI.Drivers.Modbus là một thư viện .NET mạnh mẽ và linh hoạt được thiết kế để triển khai giao thức Modbus Master. Thư viện hỗ trợ nhiều phương thức kết nối khác nhau bao gồm TCP/IP, Serial Port và ASCII, cung cấp một giải pháp toàn diện cho việc giao tiếp với các thiết bị Modbus trong môi trường công nghiệp.

Tính năng chính

Hỗ trợ đa giao thức

  • Modbus TCP/IP: Giao tiếp qua mạng Ethernet
  • Modbus ASCII: Giao tiếp qua Serial Port với định dạng ASCII
  • Modbus RTU: Hỗ trợ giao tiếp Serial Port

Chức năng Modbus đầy đủ

  • Đọc dữ liệu:

    • Read Coil Status (Function Code 01)
    • Read Input Status (Function Code 02)
    • Read Holding Registers (Function Code 03)
    • Read Input Registers (Function Code 04)
  • Ghi dữ liệu:

    • Write Single Coil (Function Code 05)
    • Write Multiple Coils (Function Code 15)
    • Write Single Register (Function Code 06)
    • Write Multiple Registers (Function Code 16)

Tính năng nâng cao

  • Quản lý kết nối tự động với event handling
  • Hỗ trợ nhiều kiểu dữ liệu (Bit, Word, DWord, Real, Int, DInt)
  • Xử lý ngoại lệ toàn diện với các exception tùy chỉnh
  • Converter hỗ trợ chuyển đổi dữ liệu
  • Thiết kế modular và mở rộng dễ dàng

Cấu trúc dự án

DBI.Drivers.Modbus/
├── ASCII/                  # Modbus ASCII implementation
├── TCP/                    # Modbus TCP implementation  
├── Comm/                   # Communication interfaces and adapters
├── DataTypes/              # Data type definitions
├── INException/            # Custom exception handling
├── Converters/             # Data conversion utilities
└── README.md

Yêu cầu hệ thống

  • .NET 8.0 hoặc cao hơn
  • System.IO.Ports package (v9.0.8)

Cài đặt

Package Manager Console

Install-Package DBI.Drivers.Modbus

.NET CLI

dotnet add package DBI.Drivers.Modbus

PackageReference

<PackageReference Include="DBI.Drivers.Modbus" Version="1.1.0" />

Cách sử dụng

1. Modbus TCP Master

using DBI.Drivers.Modbus.TCP;
using DBI.Drivers.Modbus.DataTypes;

// Khởi tạo TCP Master
var tcpMaster = new ModbusTCPMaster("192.168.1.100", 502);

// Kết nối
tcpMaster.Connection();

// Đọc Holding Registers
byte[] data = tcpMaster.ReadHoldingRegisters(1, 0, 10);

// Ghi Single Register
byte[] writeData = { 0x12, 0x34 };
tcpMaster.WriteSingleRegister(1, 0, writeData);

// Ngắt kết nối
tcpMaster.Disconnection();

2. Modbus ASCII Master

using DBI.Drivers.Modbus.ASCII;
using System.IO.Ports;

// Khởi tạo ASCII Master
var asciiMaster = new ModbusASCIIMaster("COM1", 9600, Parity.None, 8, StopBits.One);

// Kết nối
asciiMaster.Connection();

// Đọc Coil Status
byte[] coilStatus = asciiMaster.ReadCoilStatus(1, 0, 16);

// Ghi Multiple Coils
byte[] coilValues = { 0xFF, 0x00 };
asciiMaster.WriteMultipleCoils(1, 0, coilValues);

// Ngắt kết nối
asciiMaster.Disconnection();

3. Xử lý sự kiện kết nối

// Đăng ký event handler
tcpMaster.ConnectionStateChanged += (status) => {
    Console.WriteLine($"Connection status: {status}");
};

4. Sử dụng Data Types

using DBI.Drivers.Modbus.DataTypes;

// Sử dụng các kiểu dữ liệu có sẵn
var bitValue = new Bit(true);
var wordValue = new Word(1234);
var realValue = new Real(3.14f);
var dintValue = new DInt(123456);

Xử lý ngoại lệ

Thư viện cung cấp các exception tùy chỉnh cho việc xử lý lỗi:

try
{
    byte[] data = master.ReadHoldingRegisters(1, 0, 10);
}
catch (IllegalDataAddressException ex)
{
    Console.WriteLine($"Invalid address: {ex.Message}");
}
catch (IllegalFunctionException ex)
{
    Console.WriteLine($"Invalid function: {ex.Message}");
}
catch (GatewayTargetDeviceFailedToRespondException ex)
{
    Console.WriteLine($"Device not responding: {ex.Message}");
}

API Reference

IModbusMaster Interface

Giao diện chính định nghĩa các phương thức Modbus cơ bản:

Phương thức Mô tả
Connection() Thiết lập kết nối với thiết bị
Disconnection() Ngắt kết nối
ReadCoilStatus() Đọc trạng thái coil
ReadInputStatus() Đọc trạng thái input
ReadHoldingRegisters() Đọc holding registers
ReadInputRegisters() Đọc input registers
WriteSingleCoil() Ghi single coil
WriteMultipleCoils() Ghi multiple coils
WriteSingleRegister() Ghi single register
WriteMultipleRegisters() Ghi multiple registers

Connection Types

public enum ConnectionType
{
    Ethernet,    // TCP/IP connection
    SerialPort   // Serial Port connection
}

Đóng góp

Chúng tôi hoan nghênh mọi đóng góp cho dự án! Vui lòng:

  1. Fork repository
  2. Tạo feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add some AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Mở Pull Request

Quy tắc đóng góp

  • Tuân thủ coding standards của .NET
  • Viết unit tests cho các tính năng mới
  • Cập nhật documentation khi cần thiết
  • Đảm bảo code compile không có warning

Roadmap

  • Hỗ trợ Modbus Plus
  • Async/Await support
  • Performance optimizations
  • Extended data type support
  • Configuration file support
  • Logging integration

Giấy phép

Dự án này được phân phối dưới giấy phép MIT. Xem file LICENSE để biết thêm chi tiết.

Hỗ trợ

Tác giả

DBI Team - Initial work

Lịch sử phiên bản

v1.0.0 (2024-10-05)

  • Initial release
  • Modbus TCP/IP support
  • Modbus ASCII support
  • Basic data types implementation
  • Exception handling system

Nếu dự án này hữu ích với bạn, hãy cho chúng tôi một star!

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DBI.Drivers.Modbus:

Package Downloads
DBI.Drivers.Delta.PLC

Delta PLC driver library supporting Modbus TCP, ASCII, and RTU protocols. Bridges Delta DVP/AS series PLCs to industrial automation systems.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 161 4/2/2026
1.1.0 145 3/19/2026