跳至主要内容

SECS/GEM 通訊整合指南

本文件說明 GST 專案中 SECS/GEM 通訊協定的架構、SDK 使用方式與實作模式。 涵蓋 Host 端(DIASECS)與 Equipment 端(DIASECSGEM)兩種實作。

1. 基本概念

1.1 角色定義

角色說明HSMS 模式連線方向
Host工廠 MES / 上位機Active(主動連線)Host → EQ
Equipment設備端控制器Passive(被動等待)EQ 監聽

1.2 協定層級

SECS-II(SEMI E5)     — 訊息格式定義(Stream/Function)
HSMS(SEMI E37) — TCP/IP 傳輸層
GEM(SEMI E30) — 設備通用模型(狀態機、事件、變數)

1.3 常用 Stream/Function

Message方向用途
S1F1/F2雙向Are 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 對照

DIASECS(Driver Level)DIASECSGEM(GEM Level)
層級低階(手動編解碼)高階(自動狀態管理)
設定程式碼設定XML + CSV Profile
使用端HostEquipment
GEM 狀態機需自行實作內建自動管理
訊息處理手動 ItemOut/ItemIn事件回呼
適用專案InspectionHostInspection Demo (EQ)

3. Host 端實作(DIASECS)

3.1 連線設定

_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 事件訂閱

_driver.TCPIPConnectStatusChanged += OnTcpStatusChanged;
_driver.ConnectStatusChanged += OnConnectStatusChanged; // HSMS Select
_driver.SECSMessageReceived += OnMessageReceived; // 主要處理器
_driver.SECSMessageSent += OnMessageSent;
_driver.SECSMessageReplyT3 += OnT3Timeout;

3.3 訊息建構(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 訊息解析(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 雙模式

// DI 切換
if (useRealSecs)
services.AddSingleton<ISecsHostService, SecsHostService>();
else
services.AddSingleton<ISecsHostService, MockSecsHostService>();

4. Equipment 端實作(DIASECSGEM)

4.1 設定檔結構

Config/Profile/
├── GemConfig.xml ← HSMS 設定、Timer、功能開關
├── EqpEvent.csv ← CEID 定義(設備事件)
├── SystemEvent.csv ← GEM 標準事件
├── RemoteCommand.txt ← RCMD 定義(S2F41 命令)
└── LinkEventReport.txt ← Event-Report 連結

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 高階 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. 常用定義範例

5.1 CEID(Collection Event ID)

範圍用途範例
1-99GEM StandardEquipmentOffline(1), OnlineRemote(2)
100-199製程事件ProcessStarted(101), ProcessCompleted(102)
200-299檢測事件InspectionStarted(201), ImageCaptured(203)
300-399清潔事件CleaningStarted(301), CleaningCompleted(302)
500-599系統/AlarmAlarmSet(501), AlarmCleared(502)

5.2 SVID(Status Variable ID)

範圍用途範例
1-9GEM StandardClock(1), ControlState(2)
10001-10099製程狀態CurrentPhase(10001), CurrentRecipeId(10002)
10101-10199檢測狀態ImageCount(10101), CurrentImageIndex(10102)
10201-10299運動軸AxisXPosition(10201), AxisYPosition(10202)
10301-10399統計TotalProcessed(10301), PassRate(10304)

5.3 RCMD(Remote Command)

命令參數說明
STARTPPID, LOTID啟動製程
STOP停止製程
PAUSE暫停製程
GO恢復製程
PP-SELECTPPID選擇配方
REMOTE切換為遠端模式
LOCAL切換為本地模式

5.4 HCACK(Remote Command ACK)

意義
0OK
1Invalid Command
2Cannot Perform Now
3Invalid Parameter
4Acknowledged Later
5Already In Condition

6. 涉及專案

專案角色SDK說明
InspectionHostHostDIASECS.NET 8 WPF,Mock/Real 雙模式
Inspection Demo (EQ)EquipmentDIASECSGEM.NET 4.8 WinForms,Plugin 架構
Walton Line1/2/3EquipmentKGS Common.NET 4.5,VS 2015
ENR_DUCEquipment.NET 4.8

7. HSMS Timer 說明

Timer預設用途
T345sReply Timeout(等待回覆)
T510sConnection Separation(斷線後重連間隔)
T65sControl Transaction Timeout
T710sNot Selected Timeout(HSMS 連線後等待 Select)
T85sNetwork Intercharacter Timeout
LinkTest60sLink Test 間隔(Keep-Alive)

文件版本:v1.0 | 建立日期:2026-03-16 | 對應 Issue:GST-167