SECS/GEM Communication Integration Guide
This document describes the SECS/GEM communication protocol architecture, SDK usage, and implementation patterns in GST projects. Covers both Host-side (DIASECS) and Equipment-side (DIASECSGEM) implementations.
1. Basic Concepts
1.1 Role Definitions
| Role | Description | HSMS Mode | Connection Direction |
|---|---|---|---|
| Host | Factory MES / Host Computer | Active (initiates connection) | Host → EQ |
| Equipment | Equipment-side controller | Passive (waits for connection) | EQ listens |
1.2 Protocol Layers
SECS-II (SEMI E5) — Message format definition (Stream/Function)
HSMS (SEMI E37) — TCP/IP transport layer
GEM (SEMI E30) — Generic Equipment Model (state machine, events, variables)
1.3 Commonly Used Stream/Functions
| Message | Direction | Purpose |
|---|---|---|
| S1F1/F2 | Bidirectional | Are You There / Reply |
| S1F13/F14 | H→E / E→H | Establish Communication |
| S2F41/F42 | H→E / E→H | Remote Command / Ack |
| S5F1/F2 | E→H / H→E | Alarm Report / Ack |
| S6F11/F12 | E→H / H→E | Event Report / Ack |
| S7F19/F20 | H→E / E→H | PP Directory Request / Reply |
2. SDK Comparison
| DIASECS (Driver Level) | DIASECSGEM (GEM Level) | |
|---|---|---|
| Level | Low-level (manual encode/decode) | High-level (automatic state management) |
| Configuration | Code-based | XML + CSV Profile |
| Used By | Host | Equipment |
| GEM State Machine | Must be implemented manually | Built-in automatic management |
| Message Handling | Manual ItemOut/ItemIn | Event callbacks |
| Applicable Project | InspectionHost | Inspection Demo (EQ) |
3. Host-Side Implementation (DIASECS)
3.1 Connection Setup
_driver = new DIASECS("InspectionHost");
_driver.SECS_Connect_Mode = eSECS_Comm_Mode.HSMS_MODE;
_driver.HSMSDriverSettings = new HSMSParameterSettings()
{
DeviceId = 0,
Mode = eHsmsConnectMode.Active, // Host = Active
PassiveIP = eqIp, // 設備 IP
PassivePort = eqPort, // 設備 Port
EnableLog = true,
LinkTest = 60, // Link Test 間隔(秒)
T3 = 45, T5 = 10, T6 = 5, T7 = 10, T8 = 5
};
_driver.Init();
_driver.Start();
3.2 Event Subscription
_driver.TCPIPConnectStatusChanged += OnTcpStatusChanged;
_driver.ConnectStatusChanged += OnConnectStatusChanged; // HSMS Select
_driver.SECSMessageReceived += OnMessageReceived; // 主要處理器
_driver.SECSMessageSent += OnMessageSent;
_driver.SECSMessageReplyT3 += OnT3Timeout;
3.3 Message Construction (Send)
byte[] buf = new byte[256];
int offset = 0;
// S1F13 Establish Communication
SECSLib.ItemOut(buf, ref offset, eFormat.L, 0); // Empty List
_driver.Send(1, 13, 1, GetNewSystemBytes(), buf, offset);
// S F W SystemBytes Data Length
3.4 Message Parsing (Receive)
void OnMessageReceived(object sender, SECSMessageReceivedEventArgs e)
{
int stream = e.Stream;
int function = e.Function;
byte[] data = e.RawData;
int offset = 0;
switch ((stream, function))
{
case (6, 11): // S6F11 Event Report
SECSLib.ItemIn(data, ref offset, out eFormat fmt, out int count); // L:3
SECSLib.ItemIn(data, ref offset, out fmt, out uint dataid); // DATAID
SECSLib.ItemIn(data, ref offset, out fmt, out uint ceid); // CEID
// ... 解析 Report Variables
// 回覆 S6F12
SendAck(e.SystemBytes, 6, 12, 0); // ACKC6 = 0
break;
}
}
3.5 Mock/Real Dual Mode
// DI 切換
if (useRealSecs)
services.AddSingleton<ISecsHostService, SecsHostService>();
else
services.AddSingleton<ISecsHostService, MockSecsHostService>();
4. Equipment-Side Implementation (DIASECSGEM)
4.1 Configuration File Structure
Config/Profile/
├── GemConfig.xml ← HSMS settings, Timers, feature toggles
├── EqpEvent.csv ← CEID definitions (equipment events)
├── SystemEvent.csv ← GEM standard events
├── RemoteCommand.txt ← RCMD definitions (S2F41 commands)
└── LinkEventReport.txt ← Event-Report linkage
4.2 GemConfig.xml
<item SECS_Connect_Mode="0" desc="0:HSMS, 1:SECSI" />
<item HSMS_DeviceId="1" />
<item HSMS_Mode="0" desc="0:Passive, 1:Active" />
<item HSMS_PassiveIP="127.0.0.1" />
<item HSMS_PassivePort="7000" />
<item HSMS_T3="45000" />
4.3 High-Level API
// 回報事件(S6F11)
service.ReportEvent(ceid: 101, new Dictionary<uint, object>
{
{ 20001, phaseId },
{ 20002, lotId },
{ 20003, recipeId }
});
// 更新狀態變數(S1F3/F4)
service.UpdateStatusVariable(svid: 10001, currentPhase);
// 設定 Alarm(S5F1)
service.SetAlarm(alid: 1001, isSet: true, "Camera disconnected");
4.4 Remote Command Handler
// S2F41 遠端命令處理
internal class StartCommandHandler : RemoteCommandHandlerBase
{
public override bool Decode(RemoteControlEventRemoteCommandArgs e,
out Dictionary<string, string> parameters)
{
parameters = new Dictionary<string, string>();
parameters["PPID"] = GetStringValue(e.Parameters["PPID"]);
parameters["LOTID"] = GetStringValue(e.Parameters["LOTID"]);
AckAllParams(e); // HCACK = 0 (OK)
return true;
}
}
5. Common Definition Examples
5.1 CEID (Collection Event ID)
| Range | Purpose | Example |
|---|---|---|
| 1-99 | GEM Standard | EquipmentOffline(1), OnlineRemote(2) |
| 100-199 | Process events | ProcessStarted(101), ProcessCompleted(102) |
| 200-299 | Inspection events | InspectionStarted(201), ImageCaptured(203) |
| 300-399 | Cleaning events | CleaningStarted(301), CleaningCompleted(302) |
| 500-599 | System/Alarm | AlarmSet(501), AlarmCleared(502) |
5.2 SVID (Status Variable ID)
| Range | Purpose | Example |
|---|---|---|
| 1-9 | GEM Standard | Clock(1), ControlState(2) |
| 10001-10099 | Process status | CurrentPhase(10001), CurrentRecipeId(10002) |
| 10101-10199 | Inspection status | ImageCount(10101), CurrentImageIndex(10102) |
| 10201-10299 | Motion axis | AxisXPosition(10201), AxisYPosition(10202) |
| 10301-10399 | Statistics | TotalProcessed(10301), PassRate(10304) |
5.3 RCMD (Remote Command)
| Command | Parameters | Description |
|---|---|---|
| START | PPID, LOTID | Start process |
| STOP | — | Stop process |
| PAUSE | — | Pause process |
| GO | — | Resume process |
| PP-SELECT | PPID | Select recipe |
| REMOTE | — | Switch to remote mode |
| LOCAL | — | Switch to local mode |
5.4 HCACK (Remote Command ACK)
| Value | Meaning |
|---|---|
| 0 | OK |
| 1 | Invalid Command |
| 2 | Cannot Perform Now |
| 3 | Invalid Parameter |
| 4 | Acknowledged Later |
| 5 | Already In Condition |
6. Related Projects
| Project | Role | SDK | Description |
|---|---|---|---|
| InspectionHost | Host | DIASECS | .NET 8 WPF, Mock/Real dual mode |
| Inspection Demo (EQ) | Equipment | DIASECSGEM | .NET 4.8 WinForms, Plugin architecture |
| Walton Line1/2/3 | Equipment | KGS Common | .NET 4.5, VS 2015 |
| ENR_DUC | Equipment | — | .NET 4.8 |
7. HSMS Timer Reference
| Timer | Default | Purpose |
|---|---|---|
| T3 | 45s | Reply Timeout (waiting for reply) |
| T5 | 10s | Connection Separation (reconnect interval after disconnect) |
| T6 | 5s | Control Transaction Timeout |
| T7 | 10s | Not Selected Timeout (waiting for Select after HSMS connection) |
| T8 | 5s | Network Intercharacter Timeout |
| LinkTest | 60s | Link Test Interval (Keep-Alive) |
Document Version: v1.0 | Created: 2026-03-16 | Linear Issue: GST-167