QianTools 2.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package QianTools --version 2.3.1
                    
NuGet\Install-Package QianTools -Version 2.3.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="QianTools" Version="2.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QianTools" Version="2.3.1" />
                    
Directory.Packages.props
<PackageReference Include="QianTools" />
                    
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 QianTools --version 2.3.1
                    
#r "nuget: QianTools, 2.3.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 QianTools@2.3.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=QianTools&version=2.3.1
                    
Install as a Cake Addin
#tool nuget:?package=QianTools&version=2.3.1
                    
Install as a Cake Tool

QianTools

.NET 工业自动化与系统管理工具库,支持 net6.0 / net8.0。

作者:钱军涛 | 公司:浪涛科技有限公司 | 许可证:MIT

安装

dotnet add package QianTools

功能模块

1. 日志管理 — LogManager

// 使用静态方法(默认单例)
LogManager.Info("设备启动成功");
LogManager.Error($"通信失败: {ex.Message}");

// 自定义日志路径和文件滚动
LogManager.Initialize(@"D:\AppLogs\myapp.log");
LogManager.MinLogLevel = LogLevel.Debug;
LogManager.MaxFileSizeBytes = 10 * 1024 * 1024;  // 10MB 自动滚动

// 通过 ILogger 接口注入(支持单元测试)
ILogger logger = LogManager.Instance;
logger.LogInfo("消息");

2. 配置管理 — ConfigManager

// 保存配置(原子写入,数据安全)
ConfigManager.SaveConfig("AppSettings", new { Theme = "Dark", Language = "zh-CN" });

// 读取配置
var settings = ConfigManager.LoadConfig<AppSettings>("AppSettings");

// 删除配置
ConfigManager.DeleteConfig("AppSettings");

// 错误监听
ConfigManager.OnError += msg => Console.WriteLine(msg);

3. PLC 通信 — MelsecPlcHelper

支持三菱 FX 系列(X/Y/M/S/T/C/D 元件),ASCII 协议串口通信。

// 连接 PLC
MelsecPlcHelper.Connect("COM1", baudRate: 9600);

// 读取
bool x0 = MelsecPlcHelper.ReadX(0);
bool y1 = MelsecPlcHelper.ReadY(1);
bool m10 = MelsecPlcHelper.ReadM(10);
short d100 = MelsecPlcHelper.ReadD(100);
short t5 = MelsecPlcHelper.ReadT(5);

// 写入
MelsecPlcHelper.WriteY(1, true);
MelsecPlcHelper.WriteM(10, false);
MelsecPlcHelper.WriteD(100, 12345);

// 轮询 D 寄存器
MelsecPlcHelper.OnDataUpdated += snapshot => {
    Console.WriteLine($"D100 = {snapshot.D[100]}");
};
MelsecPlcHelper.StartPolling(new[] { 100, 101, 102 }, intervalMs: 100);

// 日志监听
MelsecPlcHelper.OnLog += (msg, level) => Console.WriteLine($"[{level}] {msg}");

// 断开
MelsecPlcHelper.Shutdown();

4. MES 通信 — MesClient

// GET 请求
string result = await MesClient.SendGetRequestAsync(
    "https://mes-server/api", "production/orders", apiKey: "your-token");

// POST 请求
var data = new { OrderId = "P001", Quantity = 100 };
string response = await MesClient.SendPostRequestAsync(
    "https://mes-server/api", "production/report", data, apiKey: "your-token");

5. 系统硬件信息 — SystemHardwareInfo

string ports = SystemHardwareInfo.GetPort();          // 串口列表
string disks = SystemHardwareInfo.GetDiskInfo();       // 磁盘信息
string cpu = SystemHardwareInfo.GetCpuInfo();          // CPU 信息
string os = SystemHardwareInfo.GetOsInfo();            // 操作系统
string network = SystemHardwareInfo.GetNetworkAdapterInfo(); // 网络适配器

6. 机器码与授权 — MachineCodeGenerator

// 生成 24 位机器码(CPU + 硬盘 + 网卡)
string machineCode = MachineCodeGenerator.GenerateMachineCode();

// SHA256 哈希
string hash = MachineCodeGenerator.GetMachineCodeHash();

// 验证授权码(Base64 编码的 "机器码|过期日期")
var (isValid, expiryDate) = MachineCodeGenerator.ValidateLicenseKey(licenseKey, machineCode);

7. 文件操作 — FileHelper

FileHelper.CopyDirectory(@"C:\Source", @"D:\Backup", overwrite: true);
FileHelper.DeleteDirectory(@"C:\Temp\OldData");

8. 加密哈希 — CryptoHelper

string sha256 = CryptoHelper.ComputeSha256Hash("hello");
string md5 = CryptoHelper.ComputeMd5Hash("hello");

9. 网络下载 — NetworkHelper

await NetworkHelper.DownloadFileAsync("https://example.com/file.zip", @"D:\Download\file.zip");

10. 桌面快捷方式 — ShortcutCreator

ShortcutCreator.CreateShortcut("我的应用", @"D:\App\MyApp.exe", arguments: "-start");

11. 开机启动 — AutoStartManager

AutoStartManager.EnsureAutoStart("MyApp", @"D:\App\MyApp.exe", enable: true);
AutoStartManager.EnsureAutoStart("MyApp", null, enable: false);  // 取消

12. 安装验证 — VerifyInstallation

// 检查软件是否安装
bool installed = VerifyInstallation.IsSoftwareInstalled("MyApp", version: "2.0");

// 安装程序(需用户确认委托)
VerifyInstallation.Notify = (title, msg) => MessageBox.Show(msg, title) == DialogResult.OK;
await VerifyInstallation.InstallAsync("安装 MyApp", @"D:\Installer", "setup.exe");

发布

dotnet pack -c Release
dotnet nuget push bin\Release\QianTools.*.nupkg --source https://api.nuget.org/v3/index.json
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 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

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
2.9.0 0 10/25/2026
2.8.0 47 10/24/2026
2.7.1 48 10/23/2026
2.7.0 328 7/30/2026
2.6.5 127 7/26/2026
2.6.1 127 7/26/2026
2.6.0 127 7/21/2026
2.5.0 129 7/21/2026
2.4.0 123 7/21/2026
2.3.5 149 5/19/2026
2.3.4 119 5/19/2026
2.3.3 136 5/19/2026
2.3.2 133 5/16/2026
2.3.1 138 5/15/2026
2.3.0 138 5/15/2026
2.1.1 217 12/23/2025
1.1.3 210 12/23/2025
1.1.0 218 12/23/2025
1.0.0 203 7/20/2024