DBI.Drivers.Delta.PLC
1.1.2
dotnet add package DBI.Drivers.Delta.PLC --version 1.1.2
NuGet\Install-Package DBI.Drivers.Delta.PLC -Version 1.1.2
<PackageReference Include="DBI.Drivers.Delta.PLC" Version="1.1.2" />
<PackageVersion Include="DBI.Drivers.Delta.PLC" Version="1.1.2" />
<PackageReference Include="DBI.Drivers.Delta.PLC" />
paket add DBI.Drivers.Delta.PLC --version 1.1.2
#r "nuget: DBI.Drivers.Delta.PLC, 1.1.2"
#:package DBI.Drivers.Delta.PLC@1.1.2
#addin nuget:?package=DBI.Drivers.Delta.PLC&version=1.1.2
#tool nuget:?package=DBI.Drivers.Delta.PLC&version=1.1.2
DBI.Drivers.Delta.PLC
Thư viện DBI.Drivers.Delta.PLC cung cấp driver giao tiếp với PLC Delta DVP/AS series thông qua giao thức Modbus (TCP, ASCII, RTU).
Thư viện được xây dựng dựa trên DBI.Drivers.Modbus, cung cấp API thân thiện để đọc/ghi dữ liệu PLC theo vùng nhớ (D, M, X, Y, S, C, T…).
Liên kết
- Project URL: https://github.com/buiminhduc23011/DBI.Drivers/tree/main/DBI.Drivers.Delta.PLC
- Repository: https://github.com/buiminhduc23011/DBI.Drivers
- NuGet: https://www.nuget.org/packages/DBI.Drivers.Delta.PLC
Cài đặt
Cài package:
dotnet add package DBI.Drivers.Delta.PLCImport namespace trong code:
using DBI.Drivers.Delta.PLC; using DBI.Drivers.Delta.PLC.Interfaces;
Cấu trúc thư viện
DBI.Drivers.Delta.PLC/
│
├── Interfaces/
│ └── IDeltaClient.cs
│
├── Converters/
│ ├── WordConverter.cs
│ ├── DoubleWordConverter.cs
│ ├── FloatConverter.cs
│ └── BcdConverter.cs
│
├── DataTypes/
│ ├── DeltaRegisterType.cs
│ └── PlcTag.cs
│
├── DeltaClient.cs
├── DeltaAddressMap.cs
└── DeltaConnectionType.cs
Khởi tạo kết nối
1. TCP (DVP)
var plc = new DeltaClient("192.168.1.10", 502, DeltaConnectionType.TcpDVP);
plc.Connect();
2. TCP (AS)
var plcAs = new DeltaClient("192.168.1.20", 502, DeltaConnectionType.TcpAS);
plcAs.Connect();
3. ASCII (Serial)
var plc = new DeltaClient("COM3", 9600, DeltaConnectionType.Ascii);
plc.Connect();
(RTU sẽ hỗ trợ trong phiên bản tiếp theo)
Hỗ trợ dòng PLC
TcpDVP: Delta DVP seriesTcpAS: Delta AS seriesAscii: Serial/ASCII (mapping tương thích DVP)
Lưu ý: AS series có mapping và range mở rộng cho nhiều vùng nhớ; ngoài D/M/X/Y/S/T/C còn có vùng AS-only như SR, HC, E trong DeltaAddressMap.
Tùy chọn AutoReconnect
Thư viện hỗ trợ tính năng tự động kết nối lại nếu PLC bị ngắt:
plc.AutoReconnect = true;
plc.ReconnectInterval = 5000; // thử lại mỗi 5s
plc.MaxRetry = -1; // -1 = retry vô hạn
Nếu AutoReconnect = true, khi Connect() thất bại hoặc PLC rớt kết nối, thư viện sẽ tự động thử kết nối lại theo chu kỳ.
Các API chính
Word (D Register)
short[] d100 = plc.ReadD(100, 5); // đọc D100 ~ D104
plc.WriteD(200, new short[] { 123, 456 });
DINT (Double Word)
int v = plc.ReadDInt(300); // đọc D300-D301
plc.WriteDInt(400, 123456);
Float (REAL)
float f = plc.ReadFloat(700); // đọc D700-D701
plc.WriteFloat(710, 3.14159f);
Coil (M, Y, S)
bool[] m0 = plc.ReadM(0, 8); // đọc M0 ~ M7
plc.WriteM(10, new bool[] { true, false, true });
bool[] y0 = plc.ReadY(0, 4); // đọc Y0 ~ Y3
plc.WriteY(5, new bool[] { true, true });
Input (X)
bool[] x0 = plc.ReadX(0, 8); // đọc X0 ~ X7
Counter (C)
short[] c0 = plc.ReadC(0, 5); // giá trị Counter
bool[] cStatus = plc.ReadCStatus(0, 8); // trạng thái Counter
Timer (T)
short[] t0 = plc.ReadT(0, 3); // giá trị Timer
bool[] tStatus = plc.ReadTStatus(0, 4); // trạng thái Timer
BCD
int bcd = plc.ReadBCD(1000); // đọc D1000 dạng BCD
plc.WriteBCD(1010, 1234); // ghi số 1234
Generic API
Có thể đọc/ghi trực tiếp bằng địa chỉ chuỗi:
var d100 = plc.Read("D100"); // 1 word
var d200 = (short[])plc.Read("D200", 10);
var dint = (int)plc.Read("DI300"); // DINT
plc.Write("DI400", 123456);
var real = (float)plc.Read("R500"); // REAL
plc.Write("R600", 3.14f);
var m10 = (bool[])plc.Read("M10", 8); // M10~M17
plc.Write("M20", new bool[] { true, false, true });
Ví dụ ConsoleApp
File Program.cs:
using System;
using DBI.Drivers.Delta.PLC;
class Program
{
static void Main()
{
try
{
// Kết nối PLC Delta qua TCP
var plc = new DeltaClient("192.168.1.10", 502, DeltaConnectionType.Tcp);
plc.AutoReconnect = true;
plc.Connect();
// Đọc D register
var d100 = plc.ReadD(100, 1);
Console.WriteLine($"D100 = {d100[0]}");
// Ghi D register
plc.WriteD(101, new short[] { 123 });
Console.WriteLine("Đã ghi D101 = 123");
// Đọc DINT
int dint = plc.ReadDInt(200);
Console.WriteLine($"D200-D201 (DINT) = {dint}");
// Đọc REAL
float real = plc.ReadFloat(300);
Console.WriteLine($"D300-D301 (REAL) = {real}");
// Đọc X input
var x0 = plc.ReadX(0, 8);
Console.WriteLine("X0..X7 = " + string.Join(",", x0));
// Ghi coil M
plc.WriteM(10, new bool[] { true, false, true });
Console.WriteLine("Đã ghi M10..M12");
// Dùng Generic API
var val = plc.Read("D400");
Console.WriteLine($"Generic Read D400 = {val}");
plc.Write("D401", (short)999);
Console.WriteLine("Generic Write D401 = 999");
}
catch (Exception ex)
{
Console.WriteLine("Lỗi: " + ex.Message);
}
}
}
Ghi chú
- Địa chỉ bắt đầu từ
0(ví dụD0,M0,X0). DeltaAddressMapánh xạ vùng nhớ PLC sang địa chỉ Modbus. Offset có thể thay đổi theo model PLC → cần chỉnh nếu khác.- Khi đọc mảng DINT/REAL phải nhân hệ số 2 vì mỗi biến chiếm 2 word.
- Nếu bật
AutoReconnect, thư viện sẽ chạy ngầm task retry → phù hợp ứng dụng HMI/SCADA cần kết nối ổn định.
License
MIT License © DBI
| Product | Versions 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. |
-
net8.0
- DBI.Drivers.Modbus (>= 1.1.1)
- System.IO.Ports (>= 9.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.