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/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 對照
| DIASECS(Driver Level) | DIASECSGEM(GEM Level) | |
|---|---|---|
| 層級 | 低階(手動編解碼) | 高階(自動狀態管理) |
| 設定 | 程式碼設定 | XML + CSV Profile |
| 使用端 | Host | Equipment |
| GEM 狀態機 | 需自行實作 | 內建自動管理 |
| 訊息處理 | 手動 ItemOut/ItemIn | 事件回呼 |
| 適用專案 | InspectionHost | Inspection 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-99 | GEM Standard | EquipmentOffline(1), OnlineRemote(2) |
| 100-199 | 製程事件 | ProcessStarted(101), ProcessCompleted(102) |
| 200-299 | 檢測事件 | InspectionStarted(201), ImageCaptured(203) |
| 300-399 | 清潔事件 | CleaningStarted(301), CleaningCompleted(302) |
| 500-599 | 系統/Alarm | AlarmSet(501), AlarmCleared(502) |
5.2 SVID(Status Variable ID)
| 範圍 | 用途 | 範例 |
|---|---|---|
| 1-9 | GEM Standard | Clock(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)
| 命令 | 參數 | 說明 |
|---|---|---|
| START | PPID, LOTID | 啟動製程 |
| STOP | — | 停止製程 |
| PAUSE | — | 暫停製程 |
| GO | — | 恢復製程 |
| PP-SELECT | PPID | 選擇配方 |
| REMOTE | — | 切換為遠端模式 |
| LOCAL | — | 切換為本地模式 |
5.4 HCACK(Remote Command ACK)
| 值 | 意義 |
|---|---|
| 0 | OK |
| 1 | Invalid Command |
| 2 | Cannot Perform Now |
| 3 | Invalid Parameter |
| 4 | Acknowledged Later |
| 5 | Already In Condition |
6. 涉及專案
| 專案 | 角色 | SDK | 說明 |
|---|---|---|---|
| InspectionHost | Host | DIASECS | .NET 8 WPF,Mock/Real 雙模式 |
| Inspection Demo (EQ) | Equipment | DIASECSGEM | .NET 4.8 WinForms,Plugin 架構 |
| Walton Line1/2/3 | Equipment | KGS Common | .NET 4.5,VS 2015 |
| ENR_DUC | Equipment | — | .NET 4.8 |
7. HSMS Timer 說明
| Timer | 預設 | 用途 |
|---|---|---|
| T3 | 45s | Reply Timeout(等待回覆) |
| T5 | 10s | Connection Separation(斷線後重連間隔) |
| T6 | 5s | Control Transaction Timeout |
| T7 | 10s | Not Selected Timeout(HSMS 連線後等待 Select) |
| T8 | 5s | Network Intercharacter Timeout |
| LinkTest | 60s | Link Test 間隔(Keep-Alive) |
文件版本:v1.0 | 建立日期:2026-03-16 | 對應 Issue:GST-167