Files
AuDaGe/formats/controlexpert/read_xsy.py

47 lines
1.4 KiB
Python

import xmltodict
import pandas as pd
from iec import datatypes, ElementaryVariable, UDT
def get_ddts():
"""Extract the DDT definitions from an XSY file."""
ddt_sources = root.findall('DDTSource')
for ddt in ddt_sources:
df = pd.read_xml(ddt)
def handle_element(path, item):
nodename = path[1][0]
match nodename:
case 'DDTSource':
ddtname = item['@DDTName']
ddtcomment = item['comment']
ddtvariables = dict()
for var in item['structure']['variables']:
ddtvariables[var['@name']] = ElementaryVariable(
name = var['@name'],
type = var['@typeName'],
address = 0,
comment = var['comment']
)
print(f"DDT Name: {ddtname}")
print(f"DDT Comment: {ddtcomment}")
print(f"DDT Variables: {ddtvariables}")
case 'dataBlock':
pass
return True # Continue processing
def read_xsy(inputfile):
"""Read an XSY file into a dataframe."""
with open(inputfile, 'rb') as f:
xmltodict.parse(
f,
item_depth=2,
item_callback=handle_element
)
# data_block = root.find('dataBlock')
if __name__ == '__main__':
read_xsy('D:\\OneDrive - Prime Controls\\Repositories\\AuDaGe\\formats\\controlexpert\\builtins.xsy')