본문으로 건너뛰기

알람 및 조건

개요​

OPC UA Part 9 ConditionType / AlarmConditionType 에서 고정된 NodeId 표준 메서드가 정의되어 있습니다.SDK 매개변수가 명확한 Python 메서드로 캡슐화되어 있습니다.

MethodNodeId입력 매개변수
Acknowledgei=9111(event_id: bytes, comment: str)
Confirmi=9113(event_id, comment)
AddCommenti=9029(event_id, comment)
Enablei=2803—
Disablei=2805—
ConditionRefreshi=3875(subscription_id)
ConditionRefresh2i=12912(subscription_id, monitored_item_id)
OneShotShelvei=9211—
TimedShelvei=9213(duration_ms: float)
Unshelvei=9215—

처음 7개의 메서드는 조건 인스턴스/서버 객체에 연결되어 있으며, 세 개의 Shelve 메서드는 알람 인스턴스의 ShelvingState 자식 노드 위로.

API​

방법분류읽기 및 쓰기설명
ua.acknowledge(condition_id, event_id, comment="")알람쓰기사용자가 이미 알고 있음
ua.confirm(condition_id, event_id, comment="")알람쓰기현장 조치가 완료되었습니다.
ua.add_comment(condition_id, event_id, comment)알람쓰기비고 입력 (comment 필수)
ua.enable_condition(condition_id)알람쓰기활성화
ua.disable_condition(condition_id)알람쓰기비활성화
ua.condition_refresh(subscription_id)알람쓰기재발급 활성화 알람
ua.condition_refresh2(subscription_id, monitored_item_id)알람쓰기지정만 MI
ua.one_shot_shelve(shelving_state_id)알람쓰기일회성 차폐
ua.timed_shelve(shelving_state_id, duration_ms)알람쓰기일시적 차단
ua.unshelve(shelving_state_id)알람쓰기차단 해제
def acknowledge(self, condition_id: str, event_id: bytes, comment: str = "") -> StatusCode: ...
def confirm(self, condition_id: str, event_id: bytes, comment: str = "") -> StatusCode: ...
def add_comment(self, condition_id: str, event_id: bytes, comment: str) -> StatusCode: ...
def enable_condition(self, condition_id: str) -> StatusCode: ...
def disable_condition(self, condition_id: str) -> StatusCode: ...
def condition_refresh(self, subscription_id: int) -> StatusCode: ...
def condition_refresh2(self, subscription_id: int, monitored_item_id: int) -> StatusCode: ...
def one_shot_shelve(self, shelving_state_id: str) -> StatusCode: ...
def timed_shelve(self, shelving_state_id: str, duration_ms: float) -> StatusCode: ...
def unshelve(self, shelving_state_id: str) -> StatusCode: ...
매개변수기본값설명
condition_id—알람 조건 예시 NodeId; 빈 문자열 반환 StatusCode.Bad 초기화 상태
event_id—알람 이벤트 ID (ByteString, bytes); None 정규화된 StatusCode
comment""LocalizedText 주석 (SDK 현재 String으로 변환되어 서버로 전달됨)
subscription_id—Publish를 포함하는 SubscriptionId
monitored_item_id—MonitoredItem Id
shelving_state_id—알람 인스턴스에서 ShelvingState 자식 노드 NodeId
duration_ms—보류 기간, 밀리초 (float); 음수 / NaN의 경우 정규화된 값을 반환합니다. StatusCode

반환 StatusCode, 실패 시 예외를 발생시키지 않음 (내부적으로 OpcUaException을 StatusCode로 정규화함).

코드 예시​

from darra_opcua import DarraOpcUa, StatusCode

with DarraOpcUa("opc.tcp://server:4840") as ua:
ua.connect()

# 직접 컨테이너 구독을 생성해야만 받을 수 있습니다. subscription_id 전달 condition_refresh
sub = ua.create_subscription(500)
es = ua.subscribe_events("i=2253", existing_subscription=sub) # ServerObject

def on_event(args):
# args는 EventArrivedEventArgs: severity / message / source_name / time / event_type
print(f"sev={args.severity} {args.source_name}: {args.message}")

# a. 서버가 현재 활성화된 경보를 다시 전송하도록 한다
ua.condition_refresh(sub.subscription_id)

es.event_arrived.append(on_event) # List[Callable], append를 사용하여 등록

# b. 사용자가 "확인"을 클릭함 —— condition_id / event_id 경보 발생 측에서 제공 ( "구현 제한" 참조)
def ack_alarm(condition_id: str, event_id: bytes):
rc = ua.acknowledge(condition_id, event_id, "操作员已知")
if rc != StatusCode.Good:
print(f"Acknowledge 失败: {rc}")

# c. 현장 처리
ua.confirm(condition_id, event_id, "现场已处理")

# d. 30초 동안 일시적으로 차단 (경보 인스턴스의 하위 ShelvingState 노드를 선택)
node = ua.resolve("ShelvingState", condition_id)
if node is not None:
ua.timed_shelve(node.node_id, 30_000.0)

es.dispose()
sub.dispose()

구현상의 제약​

  • 이벤트 콜백에서 가져올 수 없음 EventId / ConditionId.EventArrivedEventArgs 필드는 5개(severity / message / source_name / time / event_type)뿐이며, 기본 구독은 이 5개 필드로 구성됩니다.acknowledge / confirm / add_comment 필요한 필드 condition_id + event_id: bytes 는 비즈니스 측의 자체 알람 모델 / 서버 측 객체 트리에서 제공되어야 합니다.
  • EventSubscription.subscribe(node_id, event_filter) 사용자 지정을 허용하지만 EventFilter,사용자 정의 SelectClauses 현재 적용되지 않음 — 여전히 기본값인 5개의 필드를 기준으로 이벤트를 전송하며, 해당 필터링 조건이 무시되었음을 알리는 Info Diagnostic 이벤트를 추가로 하나 전송합니다.
  • acknowledge / confirm / add_comment 는 로케일 태그 없이 순수 문자열로 comment 전송됩니다.

오류 처리​

이 메서드는 항상 값을 반환하며 StatusCode, 예외를 발생시키지 않습니다. 일반적인 결과:

결과의미
StatusCode.Good성공, 서버에서 수신 완료
StatusCode.Bad실패 (통일 귀일 상태, 아래 참조)
매개변수가 비어 있음 / event_id 인 경우 None / duration_ms 음수이거나 NaN인 경우정규화된 값을 바로 반환하고 StatusCode, 전송하지 않음 RPC
상태 코드 통합

Python StatusCode 열거형에는 자주 사용되는 코드만 포함됩니다. Part 4 부록 A에 포함되지 않은 코드(예: BadConditionAlreadyEnabled / BadConditionAlreadyShelved / BadEventIdUnknown)는 모두 다음과 같이 통합됩니다. StatusCode.Bad, 반환값만으로는 구별할 수 없습니다. 구체적인 원인을 파악하려면 원시 정수 값을 OpcUaException.status_code 확인하거나, 서버에서 반환된 진단 메시지를 살펴보십시오.

모범 사례​

  • 첫 구독 후 반드시 조정해야 할 사항 condition_refresh(sub.subscription_id)
  • acknowledge 그 다음 confirm, 두 걸음
  • timed_shelve 단위 ms, 초가 아니다
  • event_arrived 콜백 내에서 ack를 동기화하지 말고, 큐에 밀어 넣어 백그라운드에서 처리하십시오.

다국어 대조​

C#PythonJavaC++RustC
AcknowledgeacknowledgeacknowledgeAcknowledgeacknowledgeDarraUa_Alarm_Acknowledge
ConfirmconfirmconfirmConfirmconfirmDarraUa_Alarm_Confirm
ConditionRefreshcondition_refreshconditionRefreshConditionRefreshcondition_refreshDarraUa_Alarm_ConditionRefresh

C의 성은 DarraUa_Alarm_*, 아니다 ; DarraUa_Condition_*;Enable / C Disable 쪽은 DarraUa_Alarm_EnableCondition / DarraUa_Alarm_DisableCondition, Refresh는 DarraUa_Alarm_ConditionRefresh(아니다 _Refresh).

다음 단계​