diff --git a/formats/controlexpert/flatten_xsy.xslt b/formats/controlexpert/flatten_xsy.xslt index e298172..283a291 100644 --- a/formats/controlexpert/flatten_xsy.xslt +++ b/formats/controlexpert/flatten_xsy.xslt @@ -4,28 +4,46 @@ Copyright 2026 Prime Controls. All rights reserved. --> - - + + + + + + + + + + + - + + + +
+ + + :
- - . + + + +
+ : - + \ No newline at end of file diff --git a/formats/controlexpert/read_xsy.py b/formats/controlexpert/read_xsy.py index 1c93e49..f07f53e 100644 --- a/formats/controlexpert/read_xsy.py +++ b/formats/controlexpert/read_xsy.py @@ -1,47 +1,38 @@ -import xmltodict import pandas as pd +import sys from iec import datatypes, ElementaryVariable, UDT +from io import StringIO +from lxml import etree +from pandas import DataFrame -def get_ddts(): - """Extract the DDT definitions from an XSY file.""" +path = 'D:/OneDrive - Prime Controls/Repositories/AuDaGe/formats/controlexpert/' - 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): +def read_xsy(xsypath, sspath, outpath) -> DataFrame: """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') + with open(sspath) as ssfile: + ssxml = etree.XML(ssfile.read()) + sstransform = etree.XSLT(ssxml) + with open(xsypath) as xsyfile: + xsyxml = etree.parse(xsyfile) + xsy = sstransform(xsyxml) + xsy.write_output(outpath + '.xml') + df = pd.read_xml(StringIO(str(xsy))) + # print(df) + df.to_csv(outpath + '.csv', index=False) if __name__ == '__main__': - read_xsy('D:\\OneDrive - Prime Controls\\Repositories\\AuDaGe\\formats\\controlexpert\\builtins.xsy') \ No newline at end of file + try: + xsypath = sys.argv[1] + except: + xsypath = 'builtins.xsy' + try: + sspath = sys.argv[2] + except: + sspath = 'flatten_xsy.xslt' + try: + outpath = sys.argv[3] + except: + outpath = 'test/test' + + read_xsy(path + xsypath, path + sspath, path + outpath) \ No newline at end of file diff --git a/formats/controlexpert/xsy_structure.md b/formats/controlexpert/xsy_structure.md new file mode 100644 index 0000000..812eb09 --- /dev/null +++ b/formats/controlexpert/xsy_structure.md @@ -0,0 +1,18 @@ +# XSY Structure + +- VariablesExchangeFile + - ~~fileHeader~~ + - dataBlock + - variables+ (name, typeName, [topologicalAddress]) + - attribute+ (name=(Save), value=(-1)) + - comment + - value + - instanceElementDesc+ (name) + - value + - ~~FBSource+~~ + - DDTSource+ + - attribute+ + - structure + - variables+ + - attribute+ (name=(ExtractBit), value) + - comment \ No newline at end of file