How mkjeff/secs4net works
Project Type & Purpose
• This is an open‐source .NET library (secs4net) implementing the SEMI SECS‐II/HSMS‐SS/GEM protocols.
• It’s intended for embedding in host applications to communicate with SEMI‐standard devices.
File Structure
• src/ – core library and protocol modules (Secs4Net, Secs4Net.Json, Secs4Net.Sml)
• common/ – shared helpers & extensions across modules
• samples/ – three client applications demonstrating usage:
– DeviceWorkerService (worker service using DI)
– SecsDevice (WinForms simulator)
– WpfVisualizer (WPF UI for message visualization)
• test/ – unit tests & benchmarks per module
• Configuration/build (global.json, Directory.Build.props, .github/workflows/dotnet.yml)
README Insights
• Core features: message creation (SecsMessage/Item), sending/receiving via secsGem.SendAsync & GetPrimaryMessageAsync
• DI integration via services.AddSecs4Net<TLogger>()
• Extensions: JSON and SML serializers as separate NuGet packages
Main Components & Relationships
a. Client Applications (samples)
– DeviceWorkerService
– SecsDevice (WinForms)
– WpfVisualizer (WPF)
They all reference the Secs4Net core and optionally Secs4Net.Json / Secs4Net.Sml.
b. Dependency Injection Layer
– Microsoft.Extensions.DependencyInjection registers SecsGem as a service.
c. Secs4Net Core Library (Secs4Net.dll)
– Connection Manager (HsmsConnection implementing ISecsConnection)
– Message API (SecMessage factory, PrimaryMessage/SecondaryMessage wrapper)
– Item Model (SecsItem, Item.Factory, Encode/Decode logic)
– PipeDecoder / MessageHeader / MessageIdGenerator
– Resource & Exception handling (SecsException, SecsFormat)
d. Protocol Extensions
– Secs4Net.Json (JSON Reader/Writer, ItemJsonConverter)
– Secs4Net.Sml (SML Reader/Writer)
e. Transport Layer
– Underlying TCP/IP socket managed by HsmsConnection
– Stream‐based framing via PipeDecoder for incoming data
f. External Dependencies
– Microsoft DI, BenchmarkDotNet, MemoryOwner<T> pool
Architectural Patterns & Principles
• Layered Architecture
– Presentation (samples) → API (SecsGem) → Protocol (SECS‐II, HSMS‐SS) → Transport (TCP/IP)
• Plugin/Extension Pattern
– JSON and SML serializers live in separate assemblies, discovered via DI or referenced directly.
• Resource Management
– Items and Messages implement IDisposable and use pooled memory (IMemoryOwner<T>).
• Each component clearly labeled.
• Notes on resource lifecycles (IDisposable & MemoryOwner).