百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

secs4net

> 编程语言
开源

SECS-II/HSSMS-SS/GEM在.NET上的执行

644 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

SECS-II/HSSMS-SS/GEM在.NET上的执行

secs4net

Project Description

SECS-II/HSMS-SS/GEM implementation on .NET. This library provides an easy way to communicate with SEMI-standard compatible devices.

Getting started

Install Nuget package

> dotnet add package Secs4Net

Configure via .NET dependency injection

Sample code reference

public void ConfigureServices(IServiceCollection services)
{
    // "secs4net" configuration section in the appsettings.json
    //  "secs4net": {
    //    "DeviceId": 0,
    //    "IsActive": true,
    //    "IpAddress": "127.0.0.1",
    //    "Port": 5000
    //  }  
    services.AddSecs4Net(Configuration); 
}

class DeviceLogger : ISecsGemLogger
{
    // implement ISecsGemLogger methods
}

Basic usage

…

Handle primary messages

await foreach (var e in secsGem.GetPrimaryMessageAsync(cancellationToken))
{     
    using var primaryMsg = e.PrimaryMessage;
    //do something for primary message

    // reply secondary message to device
    using var secondaryMsg = new SecsMessage(...);
    await e.TryReplyAsync(secondaryMsg); 
};

Creates Item via LINQ

…

Change the Item value (restricted)

Basic rule: The Item.Count has been fixed while the item was created.

You can only overwrite values on existing memory. String Item is immutable, coz C# string is immutable as well.

Reuse array for large item values

All unmanaged data Item can created from IMemoryOwner or Memory.

The following sample uses the implementation of IMemoryOwner from Microsoft.Toolkit.HighPerformance that has been referenced internally by secs4net..

var largeArrayOwner = MemoryOwner.Allocate(size: 65535);

// feed the value into largeArrayOwner.Memory or largeArrayOwner.Span
FillLargeArray(largeArrayOwner.Memory);

using var s6f11 = new SecsMessage(6, 11, replyExpected: false)
{
    Name = "LargeDataEvent",
    SecsItem = L(
        L(
            I2(1121),
            A(""),
            I4(largeArrayOwner))), // create Item from largeArrayOwner
};

// apply using on received message as well. coz the item decoded by PipeDecoder also uses MemoryOwner when the data array is big.
using var s6f12 = await secsGem.SendAsync(s6f11);

IMemoryOwner, Item, and SecsMessage have implemented IDisposable don't forget to Dispose it when they don't need anymore. Otherwise, the array will not return to the pool till GC collects.

Since the length of the max encoded bytes in a single non-List Item was 16,777,215(3 bytes), we split raw data into separated items. In that case, creating the Items from sliced Memory is more efficient.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#hsmssecs-ii

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言