@@ -235,21 +235,40 @@ def install(
235235
236236 try :
237237 nref = _normalize_ref (rcb_ref , rcb_type )
238+ log .info (f"安装报告回调: rcb_ref={ rcb_ref } , mms_ref={ nref } , rpt_id={ rpt_id !r} , rcb_type={ rcb_type } " )
239+
240+ # 警告:RptId 为空时,部分版本的 libIEC61850 RCBSubscriber
241+ # 无法匹配服务器推送的报告,导致 RCBHandler.trigger 永远不会被调用
242+ effective_rpt_id = rpt_id or ""
243+ if not effective_rpt_id :
244+ log .warning (
245+ f"RptId 为空,报告回调可能无法匹配服务器推送的报告!"
246+ f"请检查 IED 的 RCB 配置中是否设置了 RptId。rcb_ref={ rcb_ref } "
247+ )
248+
238249 handler = _PyRCBHandler (rcb_ref )
239250 subscriber = iec61850 .RCBSubscriber ()
240251 subscriber .setIedConnection (conn )
241252 subscriber .setRcbReference (nref )
242- subscriber .setRcbRptId (rpt_id or "" )
253+ subscriber .setRcbRptId (effective_rpt_id )
243254 subscriber .setEventHandler (handler )
244- if not subscriber .subscribe ():
245- log .warning (f"订阅报告失败: ref={ nref } " )
255+
256+ log .debug (f"RCBSubscriber.subscribe() 调用: ref={ nref } , rpt_id={ effective_rpt_id !r} " )
257+ subscribe_ok = subscriber .subscribe ()
258+ if not subscribe_ok :
259+ log .warning (
260+ f"RCBSubscriber.subscribe() 返回失败: ref={ nref } , rpt_id={ effective_rpt_id !r} , "
261+ f"rcb_ref={ rcb_ref } "
262+ )
246263 with contextlib .suppress (Exception ):
247264 subscriber .deleteEventHandler ()
248265 if hasattr (handler , "thisown" ):
249266 with contextlib .suppress (Exception ):
250267 handler .thisown = 0
251268 return False
252269
270+ log .info (f"RCBSubscriber.subscribe() 成功: ref={ nref } , rpt_id={ effective_rpt_id !r} " )
271+
253272 _CALLBACK_REGISTRY [rcb_ref ] = _CallbackInfo (
254273 rcb_ref = rcb_ref ,
255274 handler = handler ,
@@ -258,13 +277,13 @@ def install(
258277 max_cache = max_cache ,
259278 enabled_at = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" ),
260279 mms_ref = nref ,
261- rpt_id = rpt_id or "" ,
280+ rpt_id = effective_rpt_id ,
262281 dataset_members = dataset_members or [],
263282 )
264- log .info (f"报告回调已安装: { rcb_ref } (mms_ref={ nref } )" )
283+ log .info (f"报告回调已安装: { rcb_ref } (mms_ref={ nref } , rpt_id= { effective_rpt_id !r } )" )
265284 return True
266285 except Exception as e :
267- log .error (f"安装报告回调异常: { rcb_ref } , { e } " )
286+ log .error (f"安装报告回调异常: { rcb_ref } , { e } " , exc_info = True )
268287 return False
269288
270289 @staticmethod
0 commit comments