알람 및 조건 (확인 / 승인 / 갱신 / 보류)
개요
OPC UA Part 9 (Alarms & Conditions)에서는 ConditionType / AlarmConditionType 에 고정된 표준 NodeId 메서드가 정의되어 있습니다.SDK 매개변수가 명확하게 지정된 C# 메서드(모두 DarraOpcUa 의 멤버)를 제공하므로, 상위 알람 패널에서 Variant[] 매개변수를 직접 입력할 필요가 없습니다.
고정 NodeId (Part 9 / Part 5 표준 네임스페이스 0):
| Method | NodeId | 입력 매개변수 |
|---|---|---|
| Acknowledge | i=9111 | (eventId : ByteString, comment : LocalizedText) |
| Confirm | i=9113 | (eventId : ByteString, comment : LocalizedText) |
| AddComment | i=9029 | (eventId : ByteString, comment : LocalizedText) |
| Enable | i=2803 | 없음 |
| Disable | i=2805 | 없음 |
| ConditionRefresh | i=3875 | (subscriptionId : IntegerId) |
| ConditionRefresh2 | i=12912 | (subscriptionId, monitoredItemId) |
| OneShotShelve | i=9211 | 없음 |
| TimedShelve | i=9213 | (shelvingTime : Duration ms) |
| Unshelve | i=9215 | 없음 |
API
| 방법 | 분류 | 읽기 및 쓰기 | 설명 |
|---|---|---|---|
| ua.Acknowledge(conditionId, eventId, comment = "") | 알람 | 쓰기 | 사용자가 이미 알고 있음 |
| ua.Confirm(conditionId, eventId, comment = "") | 알람 | 쓰기 | 현장 조치가 완료되었습니다. |
| ua.AddComment(conditionId, eventId, comment) | 알람 | 쓰기 | 메모 추가 (comment 필수 입력, 기본값 없음) |
| ua.EnableCondition(conditionId) | 알람 | 쓰기 | 활성화 |
| ua.DisableCondition(conditionId) | 알람 | 쓰기 | 비활성화 |
| ua.ConditionRefresh(subscriptionId) | 알람 | 쓰기 | 서버 측에서 현재 활성화된 모든 알람을 재전송하도록 합니다. |
| ua.ConditionRefresh2(subscriptionId, monitoredItemId) | 알람 | 쓰기 | 지정된 MI 에 한해 재발급 |
| ua.OneShotShelve(shelvingStateId) | 알람 | 쓰기 | 일회성 차단 (다음 활성화 시 자동으로 복원됨) |
| ua.TimedShelve(shelvingStateId, durationMs) | 알람 | 쓰기 | N 밀리초 동안 차단 |
| ua.Unshelve(shelvingStateId) | 알람 | 쓰기 | 차단 해제 |
진짜 서명 (모두 DarraOpcUa 의 구성원):
public StatusCode Acknowledge(string conditionId, byte[] eventId, string comment = "");
public StatusCode Confirm(string conditionId, byte[] eventId, string comment = "");
public StatusCode AddComment(string conditionId, byte[] eventId, string comment);
public StatusCode EnableCondition(string conditionId);
public StatusCode DisableCondition(string conditionId);
public StatusCode ConditionRefresh(uint subscriptionId);
public StatusCode ConditionRefresh2(uint subscriptionId, uint monitoredItemId);
public StatusCode OneShotShelve(string shelvingStateId);
public StatusCode TimedShelve(string shelvingStateId, double durationMs);
public StatusCode Unshelve(string shelvingStateId);
매개변수:
| 매개변수 | 유형 | 설명 |
|---|---|---|
| conditionId | string | 경고 조건 인스턴스 NodeId; null / 빈 문자열이면 RPC를 보내지 않고 raw 0x80AB0000(BadInvalidArgument)을 바로 반환합니다 |
| eventId | byte[] | 이번 알람의 EventId (ByteString); null 역시 바로 BadInvalidArgument를 반환합니다. |
| comment | string | LocalizedText 텍스트; Acknowledge / Confirm 기본값: 빈 문자열, AddComment 필수 입력 |
| subscriptionId / monitoredItemId | uint | Part 4 IntegerId |
| shelvingStateId | string | 조건 인스턴스의 ShelvingState 하위 노드 NodeId (일반적으로 "{conditionId}.ShelvingState") |
| durationMs | double | 보류 기간, 밀리초; NaN 또는 음수인 경우 바로 BadInvalidArgument를 반환합니다. |
StatusCode 반환, 실패 예외를 던지지 않음 (호출 중에 발생한 는 OpcUaException 로 접혀서 StatusCode 반환되며), 상위 수준에서 자동으로 재시도합니다.
코드 예시
using System;
using DarraOpcUa_Client;
using var ua = new DarraOpcUa("opc.tcp://server:4840");
ua.Connect();
// 1) 알림 이벤트 구독 (nodeId 기본값은 Server=i=2253이며, 여기서는 명시적으로 기재함)
using var sub = ua.CreateSubscription(500);
using var ev = ua.SubscribeEvents("i=2253", sub);
ev.EventArrived += (s, e) =>
{
// 콜백에는 5개의 필드만 제공됩니다: Severity / Message / SourceName / Time / EventType
// (Time은 DateTime?, 서버에서 시간을 제공하지 않은 경우 null)
Console.WriteLine($"[{e.Time:HH:mm:ss}] sev={e.Severity} {e.SourceName}: {e.Message} ({e.EventType})");
};
// a. 서버가 현재 활성화된 모든 경보를 다시 전송하도록 한다 (패널을 처음 열 때)
var rc = ua.ConditionRefresh(sub.SubscriptionId);
Console.WriteLine(rc == StatusCode.Good ? "ConditionRefresh OK" : $"ConditionRefresh 失败: {rc}");
// 2) 경보 처리 — conditionId / eventId / shelvingStateId 상위 계층에서 서버 측의 조건 인스턴스 모델에서 가져와,
// 현재 EventArrivedEventArgs 이 세 개의 ID는 표시되지 않습니다.
static void HandleAlarm(DarraOpcUa ua, string conditionId, byte[] eventId, string shelvingStateId)
{
// b. 사용자가 "확인"을 클릭합니다.
var rc1 = ua.Acknowledge(conditionId, eventId, "操作员已知");
Console.WriteLine(rc1 == StatusCode.Good ? "已确认" : $"Acknowledge 失败: {rc1}");
// c. 현장에서 처리를 마친 후 "완료 확인"을 클릭합니다.
ua.Confirm(conditionId, eventId, "现场已处理");
// d. 30초(30밀리초_000 ) 동안 일시적으로 차단
ua.TimedShelve(shelvingStateId, 30_000.0);
// e. 비고 추가 (Ack/Confirm 상태에는 영향을 미치지 않음)
ua.AddComment(conditionId, eventId, "等待夜班巡检");
}
// 3) 전체 조건 활성화/비활성화 (유지보수 기간 중)
ua.DisableCondition("ns=2;s=Tank.HighLevel");
// ... 유지보수를 마친 후
ua.EnableCondition("ns=2;s=Tank.HighLevel");
Acknowledge / Confirm / AddComment 필요한 conditionId 항목은 eventId 현재 이벤트 콜백을 통해 노출되지 않으며, 상위 계층에서 자체적으로 정한 조건에 따라 인스턴스와 NodeId 이벤트 ID를 제공합니다.
오류 처리
다음은 서버가 이러한 메서드에 대해 반환할 수 있는 상태 코드 이름입니다(OPC UA 표준 정의).
| StatusCode | 의미 |
|---|---|
| Good (0x00000000) | 성공 |
| BadEventIdUnknown | EventId 현재 조건과 일치하지 않음 |
| BadConditionAlreadyEnabled | 활성화됨 |
| BadConditionAlreadyDisabled | 비활성화됨 |
| BadConditionAlreadyShelved | 차단됨 |
| BadConditionNotShelved | 차단되지 않았으나, Unshelve할 수 없음 |
StatusCode 열거형에 포함되어 있지 않습니다.C#의 StatusCode 열거형은 BadHistoryOperationUnsupported 등과 같은 일반적인 코드까지만 정의되어 있으며, 위 표에 나열된 Part 9 전용 코드들은 해당 열거형 멤버가 없습니다. 서버에서 반환될 때는 StatusCode 값이 원본 그대로 전송되며, 판단은 수치 비교만 가능합니다:
// uint 상수를 사용하여 열거형의 누락된 항목을 보완
const uint SC_BadInvalidArgument = 0x80AB0000u;
if ((uint)rc == SC_BadInvalidArgument) { /* 입력 매개변수가 빈 값이라 로컬에서 차단되어 전송되지 않았습니다. RPC */ }
이 두 raw 코드의 값: BadInvalidArgument = 0x80AB0000 (conditionId / eventId / shelvingStateId 가 비어 있을 경우 바로 반환하며, 전송하지 않음 RPC),BadInternalError = 0x80020000.
모범 사례
- 첫 구독 후 반드시 조정해야 할 사항
ConditionRefresh— 그렇지 않으면 새로운 이벤트만 수신하고, 이미 활성화된 기존 알람은 볼 수 없습니다. Acknowledge그 다음에Confirm— 두 단계의 절차이며, ‘Confirm’ 단계를 건너뛰지 마십시오. 일부 조건 유형은 이 중 하나만 지원합니다.- TimedShelve의 단위는 밀리초이며, 매개변수는 다음과 같습니다.
double— 30초 이내 작성30_000.0; 서버는 일반적으로 시간MaxTimeShelved제약이 있으며, 이를 초과하면 오류가 반환됩니다.BadShelvingTimeOutOfRange - comment의 로케일은 다음과 같이 고정되어 있습니다.
"en"— 전송 시 로케일은 항상"en",로 표기하며, 중국어 텍스트는 en 로케일로 표시됩니다. 텍스트 자체는 UTF-8로 전송됩니다. eventIdISO-8859-1번을 눌러 전송 —byte[]바이트 단위로 ISO-8859-1 문자열로 매핑하여 전송하며, UTF-8 다바이트 확장 처리는 수행하지 않습니다. 실매개변수 유형을 엄격하게 검증하는 서버의 경우 수신을 거부할 수 있습니다.EventArrived에서 Ack을 동기화하지 마십시오 —ConcurrentQueue푸시-퀘스트를 사용하여 백그라운드 스레드에서 처리
다국어 대조
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| Acknowledge | acknowledge | acknowledge | Acknowledge | acknowledge | DarraUa_Alarm_Acknowledge |
| Confirm | confirm | confirm | Confirm | confirm | DarraUa_Alarm_Confirm |
| ConditionRefresh | condition_refresh | conditionRefresh | ConditionRefresh | condition_refresh | DarraUa_Alarm_ConditionRefresh |
| TimedShelve | timed_shelve | timedShelve | TimedShelve | timed_shelve | DarraUa_Alarm_TimedShelve |