@@ -232,13 +232,18 @@ def _get_list_from_linked_list(self, linked_list) -> List[str]:
232232 iec61850 .LinkedList_destroy (linked_list )
233233 return items
234234
235- def discover_model (self ):
236- """动态发现并映射服务端的数据模型"""
235+ def discover_model (self ) -> List [Dict [str , Any ]]:
236+ """动态发现并映射服务端的数据模型
237+
238+ Returns:
239+ 发现的测点列表,每个元素为 {"address": int, "frame_type": int, "ref": str}
240+ """
237241 if not self ._connection or not self ._is_connected :
238- return
242+ return []
239243
240244 log .info ("开始 IEC 61850 动态模型发现..." )
241245 start_time = time .time ()
246+ discovered_points : List [Dict [str , Any ]] = []
242247
243248 # 1. 获取逻辑设备列表
244249 result = iec61850 .IedConnection_getLogicalDeviceList (self ._connection )
@@ -247,12 +252,11 @@ def discover_model(self):
247252
248253 if error != iec61850 .IED_ERROR_OK :
249254 log .error (f"发现模型失败: 无法获取逻辑设备列表 (错误码: { error } )" )
250- return
255+ return []
251256
252257 lds = self ._get_list_from_linked_list (ld_list )
253258 log .info (f"发现逻辑设备: { lds } " )
254259
255- discovered_count = 0
256260 for ld in lds :
257261 # 2. 获取逻辑节点列表 (使用 getLogicalDeviceDirectory)
258262 result = iec61850 .IedConnection_getLogicalDeviceDirectory (self ._connection , ld )
@@ -269,7 +273,7 @@ def discover_model(self):
269273 ln_ref = f"{ ld } /{ ln } "
270274
271275 # 3. 获取数据对象列表 (使用 getLogicalNodeDirectory)
272- result = iec61850 .IedConnection_getLogicalNodeDirectory (self ._connection , ln_ref , 1 ) # 1 = ACSI_DIR_DO
276+ result = iec61850 .IedConnection_getLogicalNodeDirectory (self ._connection , ln_ref , 0 ) # 0 = ACSI_CLASS_DATA_OBJECT
273277 do_list = result [0 ] if isinstance (result , (list , tuple )) else result
274278 error = result [1 ] if isinstance (result , (list , tuple )) else 0
275279
@@ -284,33 +288,46 @@ def discover_model(self):
284288
285289 try :
286290 if ln == "MMXU1" and do .startswith ("MV_" ):
287- addr = int ( do [3 :])
291+ addr = do [3 :]
288292 ref = f"{ full_do_ref } .mag.f"
289293 self ._point_refs [(addr , 0 )] = ref
290- discovered_count += 1
294+ discovered_points . append ({ "address" : addr , "frame_type" : 0 , "ref" : ref })
291295 log .info (f"映射测点: ({ addr } , 0) -> { ref } " )
292296 elif ln == "GGIO1" and do .startswith ("SPS_" ):
293- addr = int ( do [4 :])
297+ addr = do [4 :]
294298 ref = f"{ full_do_ref } .stVal"
295299 self ._point_refs [(addr , 1 )] = ref
296- discovered_count += 1
300+ discovered_points . append ({ "address" : addr , "frame_type" : 1 , "ref" : ref })
297301 log .info (f"映射测点: ({ addr } , 1) -> { ref } " )
298302 elif ln == "GGIO1" and do .startswith ("SPC_" ):
299- addr = int ( do [4 :])
303+ addr = do [4 :]
300304 ref = f"{ full_do_ref } .ctlVal"
301305 self ._point_refs [(addr , 2 )] = ref
302- discovered_count += 1
306+ discovered_points . append ({ "address" : addr , "frame_type" : 2 , "ref" : ref })
303307 log .info (f"映射测点: ({ addr } , 2) -> { ref } " )
304308 elif ln == "GGIO2" and do .startswith ("APC_" ):
305- addr = int ( do [4 :])
309+ addr = do [4 :]
306310 ref = f"{ full_do_ref } .ctlVal"
307311 self ._point_refs [(addr , 3 )] = ref
308- discovered_count += 1
312+ discovered_points . append ({ "address" : addr , "frame_type" : 3 , "ref" : ref })
309313 log .info (f"映射测点: ({ addr } , 3) -> { ref } " )
310- except ValueError :
314+ except Exception as e :
315+ log .error (f"解析测点地址失败: { do } , 错误: { e } " )
311316 continue
312317
313- log .info (f"IEC 61850 动态发现完成, 耗时: { time .time () - start_time :.2f} s, 发现并映射了 { discovered_count } 个测点" )
318+ log .info (f"IEC 61850 动态发现完成, 耗时: { time .time () - start_time :.2f} s, 发现并映射了 { len (discovered_points )} 个测点" )
319+ return discovered_points
320+
321+ def get_discovered_points (self ) -> List [Dict [str , Any ]]:
322+ """获取当前已映射的测点列表
323+
324+ Returns:
325+ 测点列表,每个元素为 {"address": int, "frame_type": int, "ref": str}
326+ """
327+ return [
328+ {"address" : addr , "frame_type" : ft , "ref" : ref }
329+ for (addr , ft ), ref in self ._point_refs .items ()
330+ ]
314331
315332 def browse_logical_devices (self ) -> List [str ]:
316333 """浏览远端 IED 的逻辑设备列表"""
0 commit comments