CSoft.Protocol.Adam4017 10.0.18

dotnet add package CSoft.Protocol.Adam4017 --version 10.0.18
                    
NuGet\Install-Package CSoft.Protocol.Adam4017 -Version 10.0.18
                    
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="CSoft.Protocol.Adam4017" Version="10.0.18" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSoft.Protocol.Adam4017" Version="10.0.18" />
                    
Directory.Packages.props
<PackageReference Include="CSoft.Protocol.Adam4017" />
                    
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 CSoft.Protocol.Adam4017 --version 10.0.18
                    
#r "nuget: CSoft.Protocol.Adam4017, 10.0.18"
                    
#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 CSoft.Protocol.Adam4017@10.0.18
                    
#: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=CSoft.Protocol.Adam4017&version=10.0.18
                    
Install as a Cake Addin
#tool nuget:?package=CSoft.Protocol.Adam4017&version=10.0.18
                    
Install as a Cake Tool

Adam4017

Adam4017 数据采集模块的 C# 通讯协议实现,支持串口和 TCP 两种通讯模式。

安装

dotnet add package CSoft.Protocol.Adam4017

特性

  • ✅ 串口通讯(RS-485)
  • ✅ TCP 客户端模式
  • ✅ TCP 服务端模式(支持多客户端)
  • ✅ Fluent API 配置
  • ✅ 异步操作
  • ✅ 连接事件监听

快速开始

串口模式

using Adam4017;

// 创建串口设备
var device = Adam4017Device
    .UseSerial("COM3", baudRate: 9600)
    .Timeout(5000)
    .OnConnect(() => Console.WriteLine("已连接"))
    .OnDisconnect(() => Console.WriteLine("已断开"))
    .Build();

// 打开连接
await device.OpenAsync();

// 读取信号量(8路模拟量)
var values = await device.ReadSignalValueAsync(address: "01");
if (values != null)
{
    Console.WriteLine($"信号量: {string.Join(", ", values)}");
}

// 关闭连接
await device.CloseAsync();

TCP 客户端模式

// 连接 Adam4017 设备
var client = Adam4017Device
    .UseTcpClient(host: "192.168.1.100", port: 9000)
    .Timeout(5000)
    .Build();

await client.OpenAsync();
var values = await client.ReadSignalValueAsync("01");
await client.CloseAsync();

TCP 服务端模式

服务端用于接收 Adam4017 设备主动连接,支持同时管理多个设备。

// 创建服务端
var server = Adam4017Device
    .UseTcpServer(host: "0.0.0.0", port: 9000)
    .Timeout(5000)
    .OnClientConnected(clientId => Console.WriteLine($"设备连接: {clientId}"))
    .OnClientDisconnected(clientId => Console.WriteLine($"设备断开: {clientId}"))
    .Build();

// 启动监听
await server.StartAsync();

// 获取所有连接的客户端
var clients = server.GetConnectedClients();
foreach (var clientId in clients)
{
    // 向指定客户端读取信号量
    var values = await server.ReadSignalValueAsync(clientId, address: "01");
    Console.WriteLine($"{clientId}: {string.Join(", ", values)}");
}

// 停止服务
await server.StopAsync();

API 参考

Adam4017Device 静态方法

方法 说明
UseSerial(portName, baudRate) 串口模式
UseTcpClient(host, port) TCP 客户端模式
UseTcpServer(host, port) TCP 服务端模式

配置选项

方法 说明
.Timeout(milliseconds) 设置超时时间
.OnConnect(handler) 连接成功回调
.OnDisconnect(handler) 断开连接回调
.OnClientConnected(handler) 客户端连接回调(仅服务端)
.OnClientDisconnected(handler) 客户端断开回调(仅服务端)

IAdam4017 接口

public interface IAdam4017
{
    bool IsConnect { get; }
    Task OpenAsync();
    Task CloseAsync(bool closePhysicalPort = true);
    Task<List<decimal>?> ReadSignalValueAsync(string address = "01", int tryCount = 0, CancellationToken cancelToken = default);
    
    event DisconnectEventHandler OnDisconnect;
    event ConnectEventHandler OnConnect;
}

IAdam4017Server 接口

public interface IAdam4017Server
{
    bool IsListened { get; }
    Task StartAsync();
    Task StopAsync();
    Task<List<decimal>?> ReadSignalValueAsync(string clientId, string address = "01", int tryCount = 0, CancellationToken cancelToken = default);
    IEnumerable<string> GetConnectedClients();
    
    event ClientConnectEventHandler OnClientConnect;
    event ClientDisconnectEventHandler OnClientDisconnect;
}

协议说明

Adam4017 采用 ASCII 协议,帧格式如下:

  • 请求: #地址\r 例如: #01\r
  • 响应: >+0.123+0.456+0.789+1.234+1.567+1.890+2.123+2.456\r

返回 8 路模拟量信号值,单位为电压值(V)。

依赖

  • .NET Standard 2.0 / .NET 10.0
  • CSoft.Protocol.ProtocolInterface
  • CSoft.Communication.TopPortLib

许可证

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.18 0 3/30/2026
10.0.17 107 1/14/2026
10.0.16 101 1/14/2026
10.0.15 102 1/13/2026
10.0.14 101 1/13/2026
10.0.13 100 1/13/2026
10.0.12 104 1/9/2026
10.0.11 165 12/26/2025
10.0.9 274 12/18/2025
10.0.8 282 12/18/2025
10.0.7 299 12/18/2025
10.0.6 446 12/10/2025
10.0.5 319 12/8/2025
10.0.4 587 12/1/2025
10.0.2 425 11/18/2025
10.0.0 299 11/12/2025
9.5.8 220 9/1/2025
Loading failed

依赖更新