Continue development of XSY import module.

This commit is contained in:
2026-01-27 17:15:38 -06:00
parent 386262da3d
commit 2b6b024971
2 changed files with 99 additions and 6 deletions

View File

@@ -1,11 +1,47 @@
import xml.etree.ElementTree as et
import xmltodict
import pandas as pd
def get_
from iec import datatypes, ElementaryVariable, UDT
def main(inputfile):
root = et.parse(inputfile)
dataBlock = root.find('dataBlock')
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__':
main('builtins.xsy')
read_xsy('D:\\OneDrive - Prime Controls\\Repositories\\AuDaGe\\formats\\controlexpert\\builtins.xsy')