Skip to main content

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

RoleDescriptionHSMS ModeConnection Direction
HostFactory MES / Host ComputerActive (initiates connection)Host → EQ
EquipmentEquipment-side controllerPassive (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

MessageDirectionPurpose
S1F1/F2BidirectionalAre You There / Reply
S1F13/F14H→E / E→HEstablish Communication
S2F41/F42H→E / E→HRemote Command / Ack
S5F1/F2E→H / H→EAlarm Report / Ack
S6F11/F12E→H / H→EEvent Report / Ack
S7F19/F20H→E / E→HPP Directory Request / Reply

2. SDK Comparison

DIASECS (Driver Level)DIASECSGEM (GEM Level)
LevelLow-level (manual encode/decode)High-level (automatic state management)
ConfigurationCode-basedXML + CSV Profile
Used ByHostEquipment
GEM State MachineMust be implemented manuallyBuilt-in automatic management
Message HandlingManual ItemOut/ItemInEvent callbacks
Applicable ProjectInspectionHostInspection 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)

RangePurposeExample
1-99GEM StandardEquipmentOffline(1), OnlineRemote(2)
100-199Process eventsProcessStarted(101), ProcessCompleted(102)
200-299Inspection eventsInspectionStarted(201), ImageCaptured(203)
300-399Cleaning eventsCleaningStarted(301), CleaningCompleted(302)
500-599System/AlarmAlarmSet(501), AlarmCleared(502)

5.2 SVID (Status Variable ID)

RangePurposeExample
1-9GEM StandardClock(1), ControlState(2)
10001-10099Process statusCurrentPhase(10001), CurrentRecipeId(10002)
10101-10199Inspection statusImageCount(10101), CurrentImageIndex(10102)
10201-10299Motion axisAxisXPosition(10201), AxisYPosition(10202)
10301-10399StatisticsTotalProcessed(10301), PassRate(10304)

5.3 RCMD (Remote Command)

CommandParametersDescription
STARTPPID, LOTIDStart process
STOPStop process
PAUSEPause process
GOResume process
PP-SELECTPPIDSelect recipe
REMOTESwitch to remote mode
LOCALSwitch to local mode

5.4 HCACK (Remote Command ACK)

ValueMeaning
0OK
1Invalid Command
2Cannot Perform Now
3Invalid Parameter
4Acknowledged Later
5Already In Condition
ProjectRoleSDKDescription
InspectionHostHostDIASECS.NET 8 WPF, Mock/Real dual mode
Inspection Demo (EQ)EquipmentDIASECSGEM.NET 4.8 WinForms, Plugin architecture
Walton Line1/2/3EquipmentKGS Common.NET 4.5, VS 2015
ENR_DUCEquipment.NET 4.8

7. HSMS Timer Reference

TimerDefaultPurpose
T345sReply Timeout (waiting for reply)
T510sConnection Separation (reconnect interval after disconnect)
T65sControl Transaction Timeout
T710sNot Selected Timeout (waiting for Select after HSMS connection)
T85sNetwork Intercharacter Timeout
LinkTest60sLink Test Interval (Keep-Alive)

Document Version: v1.0 | Created: 2026-03-16 | Linear Issue: GST-167