본문으로 건너뛰기

알람 및 조건

개요​

OPC UA Part 9 ConditionType / AlarmConditionType 에서 고정된 NodeId 표준 메서드가 정의되어 있습니다.SDK 로 AlarmConditionApi 캡슐화된정적 메서드 — 첫 번째 형식 OpcUaSession 매개변수로 전달되며, 모든 값을 반환하고 Enums.StatusCode, 실패 시 예외를 발생시키지 않습니다.

MethodNodeId입력 매개변수
Acknowledgei=9111(eventId: byte[], comment: String)
Confirmi=9113(eventId, comment)
AddCommenti=9029(eventId, comment)
Enablei=2803—
Disablei=2805—
ConditionRefreshi=3875(subscriptionId)
ConditionRefresh2i=12912(subscriptionId, monitoredItemId)
OneShotShelvei=9211—
TimedShelvei=9213(shelvingTimeMs)
Unshelvei=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);
});
}
이벤트 스냅샷에 EventId / ConditionId가 포함되지 않습니다

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
BadEventIdUnknownEventId 일치하지 않음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#PythonJavaC++RustC
AcknowledgeacknowledgeAlarmConditionApi.acknowledgeAcknowledgeacknowledgeDarraUa_Alarm_Acknowledge
ConfirmconfirmAlarmConditionApi.confirmConfirmconfirmDarraUa_Alarm_Confirm
AddCommentadd_commentAlarmConditionApi.addCommentAddCommentadd_commentDarraUa_Alarm_AddComment
EnableConditionenable_conditionAlarmConditionApi.enableConditionEnableConditionenable_conditionDarraUa_Alarm_EnableCondition
DisableConditiondisable_conditionAlarmConditionApi.disableConditionDisableConditiondisable_conditionDarraUa_Alarm_DisableCondition
ConditionRefreshcondition_refreshAlarmConditionApi.conditionRefreshConditionRefreshcondition_refreshDarraUa_Alarm_ConditionRefresh
ConditionRefresh2condition_refresh2AlarmConditionApi.conditionRefresh2ConditionRefresh2condition_refresh2DarraUa_Alarm_ConditionRefresh2
OneShotShelveone_shot_shelveAlarmConditionApi.oneShotShelveOneShotShelveone_shot_shelveDarraUa_Alarm_OneShotShelve
TimedShelvetimed_shelveAlarmConditionApi.timedShelveTimedShelvetimed_shelveDarraUa_Alarm_TimedShelve
UnshelveunshelveAlarmConditionApi.unshelveUnshelveunshelveDarraUa_Alarm_Unshelve

C 측의 열 개 엔트리는 모두 DarraUa_Alarm_* 가족이며, 첫 번째 매개변수는 DarraUa_SessionHandle: DarraUa_Alarm_Acknowledge / _Confirm / _AddComment / _EnableCondition / _DisableCondition / _ConditionRefresh / _ConditionRefresh2 / _OneShotShelve / _TimedShelve / 이고 _Unshelve, 를 반환하며 DarraUa_Status, 예외를 발생시키지 않습니다.

다음 단계​