ICD文件
<?xml version="1.0" encoding="UTF-8"?>
<SCL xmlns="http://www.iec.ch/61850/2003/SCL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.iec.ch/61850/2003/SCL SCL.xsd" xmlns:ext="http://nari-relays.com" xmlns:csg="http://www.csg.cn">
<Header id="PCS-222ILA-DG-N" version="V1.03" toolID="NRRConfig" nameStructure="IEDName"/>
<Communication>
<SubNetwork name="SubNetwork_Processbus" type="8-GOOSE">
<BitRate unit="b/s" multiplier="M">10</BitRate>
<ConnectedAP iedName="TEMPLATE" apName="G1">
<GSE ldInst="RPIT" cbName="gocb0">
<Address>
<P type="MAC-Address">01-0C-CD-01-00-01</P>
<P type="VLAN-ID">000</P>
<P type="VLAN-PRIORITY">4</P>
<P type="APPID">3001</P>
</Address>
<MinTime unit="s" multiplier="m">2</MinTime>
<MaxTime unit="s" multiplier="m">5000</MaxTime>
</GSE>
<GSE ldInst="RPIT" cbName="gocb1">
<Address>
<P type="MAC-Address">01-0C-CD-01-00-02</P>
<P type="VLAN-ID">000</P>
<P type="VLAN-PRIORITY">4</P>
<P type="APPID">3002</P>
</Address>
<MinTime unit="s" multiplier="m">2</MinTime>
<MaxTime unit="s" multiplier="m">5000</MaxTime>
</GSE>
<GSE ldInst="RPIT" cbName="gocb2">
一、解析Python代码
import os
from lxml import etree
def find_all_nodes(node, node_type):
ln_nodes = []
if node.tag.endswith(node_type):
ln_nodes.append(node)
for child in node:
ln_nodes.extend(find_all_nodes(child, node_type))
return ln_nodes
inputs = []
py_dir = os.path.split(os.path.realpath(__file__))[0]
count = 0
for file_name in os.listdir(py_dir):
if file_name.endswith(".icd"):
temp = ["IED设备名称,虚端子类型,虚端子数据属性,虚端子定义,ICD文件行号"]
file_path = os.path.join(py_dir, file_name)
icd_tree = etree.parse(file_path)
icd_root = icd_tree.getroot()
ln_nodes = find_all_nodes(icd_root, "LN")
ied_node = find_all_nodes(icd_root, "IED")
for ln in ln_nodes:
prefix = ln.get("prefix")
if prefix == None:
prefix = ""
lnclass = ln.get("lnClass")
inst = ln.get("inst")
in_out = "GOOSE输出"
if "GOIN" in str(prefix):
in_out = "GOOSE输入"
for doi in find_all_nodes(ln, "DOI"):
input_node = file_name.replace(".icd", "") + "," + in_out + "," + ln.getparent().get("inst") + "/" + prefix + lnclass + inst
break_dai = False
for dai in find_all_nodes(doi, "DAI"):
if break_dai == True:
break
for val in find_all_nodes(dai, "Val"):
if val.text == doi.get("desc"):
input_node = input_node + "." + doi.get("name") + "." + doi.getchildren()[0].get("name") + "," + val.text + "," + str(dai.sourceline)
temp.append(input_node)
break_dai = True
break
temp = [i for i in temp if not "LD0" in i.split(',')[2]]
with open(os.path.join(py_dir, "虚端子表导出结果", file_name.replace(".icd", "") + ".csv"), "w", encoding="utf-8") as file:
for item in temp:
file.write(item + "\n")
print("虚端子表导出完成")
二、虚端子表