SuncodeSoftware.SuperSDK.Core 5.1.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package SuncodeSoftware.SuperSDK.Core --version 5.1.1
                    
NuGet\Install-Package SuncodeSoftware.SuperSDK.Core -Version 5.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="SuncodeSoftware.SuperSDK.Core" Version="5.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SuncodeSoftware.SuperSDK.Core" Version="5.1.1" />
                    
Directory.Packages.props
<PackageReference Include="SuncodeSoftware.SuperSDK.Core" />
                    
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 SuncodeSoftware.SuperSDK.Core --version 5.1.1
                    
#r "nuget: SuncodeSoftware.SuperSDK.Core, 5.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 SuncodeSoftware.SuperSDK.Core@5.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=SuncodeSoftware.SuperSDK.Core&version=5.1.1
                    
Install as a Cake Addin
#tool nuget:?package=SuncodeSoftware.SuperSDK.Core&version=5.1.1
                    
Install as a Cake Tool

SuperSDK.Core

SuperSDK 核心基础库,提供零 UI 依赖的通用工具类和消息系统。

安装

dotnet add package SuperSDK.Core

使用示例

1. 消息总线 - 基础用法

using SuperSDK.Core.Messaging;

// 定义消息类型
public class TestResultMessage
{
    public string TestName { get; set; }
    public bool Passed { get; set; }
}

// 订阅消息(全局通道)
public class TestObserver
{
    public TestObserver()
    {
        MessageBus.Subscribe<TestResultMessage>(this, OnTestResult);
    }
    
    private void OnTestResult(TestResultMessage msg)
    {
        Console.WriteLine($"Test: {msg.TestName}, Result: {msg.Passed}");
    }
    
    ~TestObserver()
    {
        MessageBus.UnsubscribeAll(this); // 清理订阅
    }
}

// 发送消息(全局通道)
MessageBus.Pub(new TestResultMessage 
{ 
    TestName = "Voltage Test", 
    Passed = true 
});

2. Fixture/Slot 级通道隔离

适用于多工位测试场景:

// Fixture 级通道(例如:Fixture 0)
MessageBus.Subscribe<TestResultMessage>(this, msg => {
    Console.WriteLine($"[Fixture 0] {msg.TestName}");
}, fixtureId: 0);

MessageBus.Pub(new TestResultMessage { TestName = "Test1", Passed = true }, fixtureId: 0);

// Slot 级通道(例如:Fixture 0, Slot 1)
MessageBus.Subscribe<TestResultMessage>(this, msg => {
    Console.WriteLine($"[F0S1] {msg.TestName}");
}, fixtureId: 0, slotId: 1);

MessageBus.Pub(new TestResultMessage { TestName = "Test2", Passed = false }, 
    fixtureId: 0, slotId: 1);

3. 请求-响应模式

// 定义请求和响应类型
public class GetConfigRequest
{
    public string ConfigName { get; set; }
}

public class ConfigResponse
{
    public string Value { get; set; }
}

// 注册请求处理器
public class ConfigService
{
    public ConfigService()
    {
        MessageBus.RegisterReqHandler<GetConfigRequest, ConfigResponse>(
            this, 
            async req => {
                // 模拟数据库查询
                await Task.Delay(100);
                return new ConfigResponse { Value = "TestValue" };
            }
        );
    }

    ~ConfigService()
    {
        // 方式1:注销特定类型的处理器
        MessageBus.UnregisterReqHandler<GetConfigRequest>(this);
        // 方式2:注销该对象注册的所有处理器和订阅
        // MessageBus.UnsubscribeAll(this);
    }
}

// 发送请求并等待响应(默认超时 5000ms)
var response = await MessageBus.Req<GetConfigRequest, ConfigResponse>(
    new GetConfigRequest { ConfigName = "DataPath" }
);
Console.WriteLine($"Config Value: {response.Value}");

// 指定自定义超时(毫秒)
var response2 = await MessageBus.Req<GetConfigRequest, ConfigResponse>(
    new GetConfigRequest { ConfigName = "DataPath" },
    timeout: 3000
);

// 检查是否已注册处理器
bool hasHandler = MessageBus.HasReqHandler<GetConfigRequest>();

// 查询处理器的所有者
object? owner = MessageBus.GetReqHandlerOwner<GetConfigRequest>();

4. 数据路径生成工具

using SuperSDK.Core.Tools;

// SlotSync 模式路径生成
DateTime now = DateTime.Now;
string dataRoot = "D:\\GoesData";

// 1. 创建 Fixture 批次文件夹
string fixturePath = DataPathHelper.GetFixtureBatchFolderPath(
    fixtureId: 0, 
    startTime: now, 
    dataRootPath: dataRoot
);
// 返回: D:\GoesData\2025-12-15\F1_20251215_143052

// 2. 创建 Slot 数据文件夹
string slotPath = DataPathHelper.GetSlotDataFolderPath(
    fixtureId: 0,
    slotId: 0,
    startTime: now,
    workMode: "SlotSync",
    dataRootPath: dataRoot,
    sn: "SN12345",
    fixtureBatchFolderPath: fixturePath
);
// 返回: D:\GoesData\2025-12-15\F1_20251215_143052\S1_SN12345_20251215_143055

// 3. 获取 CSV 文件路径
string csvPath = DataPathHelper.GetDetailedCsvFilePath(
    fixtureId: 0,
    slotId: 0,
    startTime: now,
    workMode: "SlotSync",
    dataRootPath: dataRoot,
    sn: "SN12345",
    fixtureBatchFolderPath: fixturePath
);
// 返回: D:\GoesData\2025-12-15\F1_20251215_143052\S1_SN12345_20251215_143055\ItemResult.csv

// 确保文件夹存在
DataPathHelper.EnsureFolderExists(slotPath);

5. 性能测量工具

using SuperSDK.Core.Tools;

// 方式 1:自动打印耗时
var result = Utils.MeasureTime(() => {
    // 执行耗时操作
    Thread.Sleep(100);
    return "完成";
}, "数据库查询");
// 输出: 数据库查询耗时: 100 ms

// 方式 2:获取耗时数据
var result2 = Utils.MeasureTime(() => {
    Thread.Sleep(50);
    return 42;
}, out TimeSpan elapsed);

Console.WriteLine($"操作耗时: {elapsed.TotalMilliseconds:F2} ms");

6. 系统工具类

using SuperSDK.Core.Tools;

// 跨平台打开文件夹(Windows/macOS/Linux 自动判断)
bool opened = SystemHelper.OpenFolder("/Users/demo/Documents/MyFolder");

// 跨平台打开 URL(在默认浏览器中打开)
bool opened2 = SystemHelper.OpenUrl("https://scsoftware.cloud");

7. 文件工具类

using SuperSDK.Core.Tools;

// 验证路径
bool isValid = FileTools.IsValidPath("C:\\Data\\test.csv"); // true
bool isInvalid = FileTools.IsValidPath("C:\\Data\\test?.csv"); // false (? 是非法字符)

// 检查路径是否存在
if (FileTools.PathExists("D:\\Data"))
{
    Console.WriteLine("路径存在");
}

// 确保目录存在
FileTools.EnsureDirectoryExists("D:\\Logs\\2025-12-15");

// 安全删除文件
bool deleted = FileTools.SafeDeleteFile("D:\\temp.txt");

// 获取文件大小
long fileSize = FileTools.GetFileSize("D:\\data.csv");
Console.WriteLine($"文件大小: {fileSize} 字节");

📖 API 文档

MessageBus 类

发布消息
方法 说明
Pub<T>(T message) 发布全局消息
Pub<T>(T message, int fixtureId) 发布 Fixture 级消息
Pub<T>(T message, int fixtureId, int slotId) 发布 Slot 级消息
Log(string logName, string message, LogLevel level) 发布日志消息
订阅消息
方法 说明 返回值
Subscribe<T>(object owner, Action<T> handler) 订阅全局消息 IDisposable
Subscribe<T>(object owner, Action<T> handler, int fixtureId) 订阅 Fixture 级消息 IDisposable
Subscribe<T>(object owner, Action<T> handler, int fixtureId, int slotId) 订阅 Slot 级消息 IDisposable
取消订阅
方法 说明
UnsubscribeAll(object owner) 取消该 owner 的所有订阅(含请求处理器)
UnsubscribeAll() 取消所有订阅和请求处理器(全局清空)
Unsubscribe<T>(object owner) 取消全局通道的特定类型订阅
Unsubscribe<T>(object owner, int fixtureId) 取消 Fixture 级订阅
Unsubscribe<T>(object owner, int fixtureId, int slotId) 取消 Slot 级订阅
请求-响应
方法 说明
RegisterReqHandler<TRequest, TResponse>(owner, handler) 注册请求处理器(每种请求类型只允许一个)
Req<TRequest, TResponse>(request, timeout) 发送请求并等待响应(默认超时 5000ms)
UnregisterReqHandler<TRequest>(owner) 注销特定类型的请求处理器
UnregisterAllRequestHandlersByOwner(owner) 注销该 owner 注册的所有请求处理器
HasReqHandler<TRequest>() 检查是否已注册处理器
GetReqHandlerOwner<TRequest>() 获取请求处理器的所有者

DataPathHelper 类

方法 说明
GetDateFolderPath(date, rootPath) 获取日期文件夹路径
GetFixtureBatchFolderPath(fixtureId, time, rootPath) 获取 Fixture 批次文件夹
GetSlotFolderName(slotId, sn, time) 获取 Slot 文件夹名称
GetSlotDataFolderPath(...) 获取 Slot 数据文件夹完整路径
GetDetailedCsvFilePath(...) 获取详细测试数据 CSV 路径
GetDailySummaryCsvFilePath(date, rootPath) 获取每日汇总 CSV 路径
EnsureFolderExists(path) 确保文件夹存在

Utils 类

方法 说明
MeasureTime<T>(Func<T>, out TimeSpan) 测量函数执行时间
MeasureTime<T>(Func<T>, string) 测量并打印耗时
GetRandomI(num1, num2) 生成随机整数
GetRandomD(num1, num2) 生成随机浮点数(1位小数)
ParseFileName(path, out name, out version) 解析版本化文件名
KillPythonProcesses() 终止所有 Python 进程

SystemHelper 类

方法 说明
OpenFolder(path) 跨平台打开文件夹(Windows/macOS/Linux)
OpenUrl(url) 跨平台在默认浏览器打开 URL

FileTools 类

方法 说明
IsValidPath(path) 验证路径是否有效
PathExists(path) 检查路径是否存在
EnsureDirectoryExists(path) 确保目录存在
SafeDeleteFile(path) 安全删除文件
GetFileSize(path) 获取文件大小

🏗️ 完整 SuperSDK 系列

SuperSDK 采用分层架构,按需引用:

Package 描述 依赖
SuperSDK.Core 核心工具和消息系统(本包)
SuperSDK.Data 数据访问层(EF Core + Sqlite) Core + EF Core
SuperSDK.UI.Avalonia Avalonia UI 组件 Core + Avalonia
SuperSDK.Driver 仪器驱动和 License Core + NSec

📝 注意事项

  • 线程安全:所有 API 都是线程安全的
  • 内存管理:记得在对象销毁时调用 MessageBus.UnsubscribeAll(this)
  • 性能优化:使用 Fixture/Slot 级通道避免全局消息泛滥
  • ⚠️ 订阅管理:避免重复订阅同一消息类型

📄 License

MIT License - 详见 LICENSE 文件

🤝 贡献

欢迎提交 Issue 和 Pull Request!


Made with ❤️ by Goes Team

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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
Loading failed

test2