알람 및 조건
개요
OPC UA Part 9 ConditionType / AlarmConditionType 에서 고정된 NodeId 표준 메서드가 정의되어 있습니다.SDK 로 AlarmConditionApi 캡슐화된정적 메서드 — 첫 번째 형식 OpcUaSession 매개변수로 전달되며, 모든 값을 반환하고 Enums.StatusCode, 실패 시 예외를 발생시키지 않습니다.
| Method | NodeId | 입력 매개변수 |
|---|---|---|
| Acknowledge | i=9111 | (eventId: byte[], comment: String) |
| Confirm | i=9113 | (eventId, comment) |
| AddComment | i=9029 | (eventId, comment) |
| Enable | i=2803 | — |
| Disable | i=2805 | — |
| ConditionRefresh | i=3875 | (subscriptionId) |
| ConditionRefresh2 | i=12912 | (subscriptionId, monitoredItemId) |
| OneShotShelve | i=9211 | — |
| TimedShelve | i=9213 | (shelvingTimeMs) |
| Unshelve | i=9215 | — |
API
| 방법 | 분류 | 읽기 및 쓰기 | 설명 |
|---|---|---|---|
| AlarmConditionApi.acknowledge(ua, conditionId, eventId, comment) | 알람 | 쓰기 | 사용자가 이미 알고 있음 |
| AlarmConditionApi.confirm(ua, conditionId, eventId, comment) | 알람 | 쓰기 | 현장 조치가 완료되었습니다. |
| AlarmConditionApi.addComment(ua, conditionId, eventId, comment) | 알람 | 쓰기 | 메모 추가 |
| AlarmConditionApi.enableCondition(ua, conditionId) | 알람 | 쓰기 | 활성화 |
| AlarmConditionApi.disableCondition(ua, conditionId) | 알람 | 쓰기 | 비활성화 |
| AlarmConditionApi.conditionRefresh(ua, subscriptionId) | 알람 | 쓰기 | 재발급 활성화 알람 |
| AlarmConditionApi.conditionRefresh2(ua, subscriptionId, monitoredItemId) | 알람 | 쓰기 | 지정만 MI |
| AlarmConditionApi.oneShotShelve(ua, shelvingStateId) | 알람 | 쓰기 | 일회성 차폐 |
| AlarmConditionApi.timedShelve(ua, shelvingStateId, durationMs) | 알람 | 쓰기 | 일시적 차단 |
| AlarmConditionApi.unshelve(ua, shelvingStateId) | 알람 | 쓰기 | 차단 해제 |
매개변수 유형: ua = OpcUaSession; conditionId / shelvingStateId = String (NodeId); eventId = byte[]; comment = String; subscriptionId / monitoredItemId = int; durationMs = double.
반환 Enums.StatusCode, 실패 시 예외를 발생시키지 않습니다.
코드 예시
import com.darra.opcua.*;
import javax.swing.JOptionPane;
try (OpcUaSession ua = new OpcUaSession("opc.tcp://server:4840")) {
ua.connect();
OpcUaSubscription sub = ua.createSubscription(500.0);
OpcUaEventSubscription ev = ua.subscribeEvents("i=2253");
ev.onEventArrived.add(args -> {
// 이벤트 스냅샷에는 severity / message / sourceName / timeFt / eventType / 등 6개의 플랫 필드만 있습니다. arrivedAtUtc
System.out.printf("[%d] %s: %s (%s)%n",
args.severity, args.sourceName, args.message, args.eventType);
// conditionId = 경보 조건 예시 NodeId (String); eventId = 해당 이벤트의 ByteString 원본 바이트 (byte[])
// 두 가지 모두 이벤트 스냅샷에 포함되지 않으며, 상위 경보 모델이 보유합니다 — 아래 설명을 참조하십시오.
String conditionId = /* 상부에서 제시한 */ null;
byte[] eventId = /* 상부에서 제시한 */ null;
// a. 서버가 현재 활성화된 경보를 재전송하도록 함 — 구독에 적용되며, 전송 SubscriptionId
AlarmConditionApi.conditionRefresh(ua, sub.getSubscriptionId());
// b. 사용자가 "확인"을 클릭하면 — 상위 conditionId 경보 모델에 eventId 의해 유지되며, 아래 설명을 참조하십시오.
Enums.StatusCode rc = AlarmConditionApi.acknowledge(ua, conditionId, eventId, "操作员已知");
if (rc != Enums.StatusCode.Good)
JOptionPane.showMessageDialog(null, "Acknowledge 失败: " + rc);
// c. 현장 처리
AlarmConditionApi.confirm(ua, conditionId, eventId, "现场已处理");
// d. 30초 동안 일시적으로 차단 — shelvingStateId 조건부 ShelvingState 자식 노드
AlarmConditionApi.timedShelve(ua, conditionId + ".ShelvingState", 30_000.0);
});
}
OpcUaEventSubscription.EventArrivedEventArgs 에는 severity (int) / message (String) / sourceName (String) / timeFt (long) / eventType (String) / arrivedAtUtc (Instant) 6개의 final 필드만 있습니다. EventId를 포함하지 않으며, ConditionId도 포함하지 않습니다.
acknowledge / confirm / addComment 의 eventId (byte[]) 와 conditionId (String) 는 호출하는 쪽이 직접 보유해야 합니다 — 서버에서 해당 이벤트의 EventId 필드를 읽어오거나, 상위 알람 모델이 관리하는 것입니다.
오류 처리
AlarmConditionApi.* 하위 레벨 예외는 Enums.StatusCode로 접어 넣습니다. Enums.StatusCode에는 자주 사용되는 코드만 등록되었으며, 등록되지 않은 서버 측 코드는 Enums.StatusCode.fromCode(int)를 통해 Bad로 병합되어 소스 코드는 저장하지 않습니다, 따라서 다음과 같은 경우에는 반환값만으로는 구별할 수 없습니다.
| OPC UA 서버 코드 (Part 4 §7.34) | 의미 | SDK 반환값 |
|---|---|---|
| Good | 성공 | Enums.StatusCode.Good |
| BadEventIdUnknown | EventId 일치하지 않음 | Enums.StatusCode.Bad (소스 코드는 포함되지 않음) |
| BadConditionAlreadyEnabled | 활성화됨 | Enums.StatusCode.Bad (소스 코드는 포함되지 않음) |
| BadConditionAlreadyShelved | 차단됨 | Enums.StatusCode.Bad (소스 코드는 포함되지 않음) |
위 표의 왼쪽 열은 OPC UA 표준 서버 상태 코드, 의 열거형 Enums.StatusCode 상수가 아니므로, 처럼 그대로 Enums.StatusCode.BadEventIdUnknown 베껴 쓸 수 없습니다.
정확하게 구분해야 할 때는 하위 계층에서 메서드를 직접 ua.call(objectNodeId, methodNodeId, inputs) 호출하고, 읽기 OpcUaException 작업을 캡처하여( ex.rawCode OpcUaException.rawCode 서버 측의 원본 int 코드를 유지) 처리해야 합니다.
모범 사례
- 첫 구독 후 반드시 조정해야 할 사항 conditionRefresh
- acknowledge 후 confirm, 두 단계
- TimedShelve 단위 ms, 초가 아님
- 리스너 내에서 ACK를 동기화하지 말고, 큐에 넣어 백그라운드에서 처리하십시오.
다국어 대조
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| Acknowledge | acknowledge | AlarmConditionApi.acknowledge | Acknowledge | acknowledge | DarraUa_Alarm_Acknowledge |
| Confirm | confirm | AlarmConditionApi.confirm | Confirm | confirm | DarraUa_Alarm_Confirm |
| AddComment | add_comment | AlarmConditionApi.addComment | AddComment | add_comment | DarraUa_Alarm_AddComment |
| EnableCondition | enable_condition | AlarmConditionApi.enableCondition | EnableCondition | enable_condition | DarraUa_Alarm_EnableCondition |
| DisableCondition | disable_condition | AlarmConditionApi.disableCondition | DisableCondition | disable_condition | DarraUa_Alarm_DisableCondition |
| ConditionRefresh | condition_refresh | AlarmConditionApi.conditionRefresh | ConditionRefresh | condition_refresh | DarraUa_Alarm_ConditionRefresh |
| ConditionRefresh2 | condition_refresh2 | AlarmConditionApi.conditionRefresh2 | ConditionRefresh2 | condition_refresh2 | DarraUa_Alarm_ConditionRefresh2 |
| OneShotShelve | one_shot_shelve | AlarmConditionApi.oneShotShelve | OneShotShelve | one_shot_shelve | DarraUa_Alarm_OneShotShelve |
| TimedShelve | timed_shelve | AlarmConditionApi.timedShelve | TimedShelve | timed_shelve | DarraUa_Alarm_TimedShelve |
| Unshelve | unshelve | AlarmConditionApi.unshelve | Unshelve | unshelve | DarraUa_Alarm_Unshelve |
C 측의 열 개 엔트리는 모두 DarraUa_Alarm_* 가족이며, 첫 번째 매개변수는 DarraUa_SessionHandle: DarraUa_Alarm_Acknowledge / _Confirm / _AddComment / _EnableCondition / _DisableCondition / _ConditionRefresh / _ConditionRefresh2 / _OneShotShelve / _TimedShelve / 이고 _Unshelve, 를 반환하며 DarraUa_Status, 예외를 발생시키지 않습니다.