diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml new file mode 100644 index 0000000..d47cd1d --- /dev/null +++ b/bitbucket-pipelines.yml @@ -0,0 +1,11 @@ +image: python:3.7.3 +options: + max-time: 1 +pipelines: + default: + - step: + script: + - git submodule update --init + - git submodule + - python twincat_version_manager.py + - python check_fix_white_space.py diff --git a/check_fix_white_space.py b/check_fix_white_space.py new file mode 100755 index 0000000..cf6fe3c --- /dev/null +++ b/check_fix_white_space.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 + +# +# Script to fix whithespace errors in files +# All trailing white space are removed +# TAB are replace by spaces +# +import glob +import sys + +file_patterns_tab_width = {"**/*.Tc*": 4, + "**/*.py": 4, + "**/*.sh": 8} +def fix_white_space(debug, fix_files): + """ + Checks the Twincat source code for white space: + TAB should not be used + Trailing SPACE shoulf not be there. + :return: A dictionary of white-space-damaged files + """ + incorrect_files = dict() + for file_path, tab_width in file_patterns_tab_width.items(): + found_files = glob.glob(file_path, recursive=True) + #if not found_files: + # raise IOError("ERROR: No files of type {} found".format(file_path)) + + for pathname in found_files: + dirty = False + new_lines = [] + if debug >= 1: + print("tab_with=%d pathname=%s" % (tab_width, pathname)) + file = open(pathname, 'r', newline='', encoding="iso-8859-1") + lines = file.readlines() + file.close() + for old_line in lines: + had_crlf = 0 + this_line_dirty = False + if old_line.endswith('\r\n'): + had_crlf = 2 # Both CR and LF + elif old_line.endswith('\n'): + had_crlf = 1 # LF + # Convert all TAB into SPACE + new_line = old_line.expandtabs(tabsize=tab_width) + # Strip of all trailing white space, including the CRLF + new_line = new_line.rstrip("\r\n ") + if had_crlf == 2: + new_line = new_line + '\r\n' + elif had_crlf == 1: + new_line = new_line + '\n' + + if len(new_line) != len(old_line): + dirty = True + this_line_dirty = True + new_lines.append(new_line) + if this_line_dirty: + if debug >= 2: + print("had_crlf=%d" % had_crlf) + print("old_line=%s" % old_line) + print("new_line=%s" % new_line) + # end of loop of all line in one file + if debug >= 1: + print("pathname=%s dirty=%d" % (pathname, dirty)) + if dirty: + incorrect_files[pathname] = True + if fix_files: + file = open(pathname, 'w', newline='', encoding="iso-8859-1") + file.writelines(new_lines) + file.close() + + return incorrect_files + + +if __name__ == "__main__": + try: + argc = len(sys.argv) + arg_idx = 1 + debug = 0 + fix_files = False + while arg_idx < argc: + if sys.argv[arg_idx] == "--fix": + fix_files = True + elif sys.argv[arg_idx] == "--debug": + debug = debug + 1 + else: + print("%s : [--fix|--debug]" % sys.argv[0]) + exit(2) + arg_idx = arg_idx + 1 + incorrect_files = fix_white_space(debug, fix_files) + if not fix_files: + for file in incorrect_files: + print("ERROR: '{}' has white space damage".format(file)) + if incorrect_files: + exit(1) + except IOError as e: + print(e) # Likely no files found + exit(2) diff --git a/solution/solution.tsproj b/solution/solution.tsproj index b64b221..729ffe6 100644 --- a/solution/solution.tsproj +++ b/solution/solution.tsproj @@ -1,5 +1,5 @@ - + NCTOPLC_AXIS_REF_STATE @@ -411,8 +411,7 @@ AxisState UDINT - - - +]]> 32 64 @@ -440,8 +438,7 @@ External Setpoint Generation: HomingState UDINT - - - +]]> 32 128 CoupleState UDINT - - - +]]> 32 160 @@ -690,13 +684,13 @@ External Setpoint Generation: NCAXLESTRUCT_TOPLC4 - + - + - + @@ -913,30 +907,22 @@ External Setpoint Generation: PlcTask Inputs GVL.axes[1].inputs.bLimitFwd - - - + BOOL GVL.axes[1].inputs.bLimitBwd - - - + BOOL GVL.axes[1].inputs.bHomeSensor - - - + BOOL GVL.axes[1].inputs.bEncLAtch - - - + BOOL @@ -944,8 +930,7 @@ External Setpoint Generation: NCTOPLC_AXIS_REF AxisState - - - +]]> HomingState - - - +]]> CoupleState - - - +]]> GVL.axes[2].inputs.bLimitFwd - - - + BOOL GVL.axes[2].inputs.bLimitBwd - - - + BOOL GVL.axes[2].inputs.bHomeSensor - - - + BOOL GVL.axes[2].inputs.bEncLAtch - - - + BOOL @@ -1021,8 +993,7 @@ External Setpoint Generation: NCTOPLC_AXIS_REF AxisState - - - +]]> HomingState - - - +]]> CoupleState - - - +]]> GVL.axes[3].inputs.bLimitFwd - - - + BOOL GVL.axes[3].inputs.bLimitBwd - - - + BOOL GVL.axes[3].inputs.bHomeSensor - - - + BOOL GVL.axes[3].inputs.bEncLAtch - - - + BOOL @@ -1098,8 +1056,7 @@ External Setpoint Generation: NCTOPLC_AXIS_REF AxisState - - - +]]> HomingState - - - +]]> CoupleState - - - +]]> @@ -1147,9 +1099,7 @@ External Setpoint Generation: PlcTask Outputs MAIN.bOutput1 - - - + BOOL diff --git a/solution/tc_epicscommodule b/solution/tc_epicscommodule index 6c86fc4..a13d6bb 160000 --- a/solution/tc_epicscommodule +++ b/solution/tc_epicscommodule @@ -1 +1 @@ -Subproject commit 6c86fc4bd9250add709323079d3c84c63790648b +Subproject commit a13d6bb6221ab2fbe8fa8f7f2345ca8cd791f8d1 diff --git a/solution/tc_project_app/GVLs/GVL_APP.TcGVL b/solution/tc_project_app/GVLs/GVL_APP.TcGVL index a366e64..a846a85 100644 --- a/solution/tc_project_app/GVLs/GVL_APP.TcGVL +++ b/solution/tc_project_app/GVLs/GVL_APP.TcGVL @@ -1,14 +1,14 @@  - + \ No newline at end of file diff --git a/solution/tc_project_app/GlobalTextList.TcGTLO b/solution/tc_project_app/GlobalTextList.TcGTLO index 9aedffb..859af55 100644 --- a/solution/tc_project_app/GlobalTextList.TcGTLO +++ b/solution/tc_project_app/GlobalTextList.TcGTLO @@ -1,5 +1,5 @@  - + diff --git a/solution/tc_project_app/POUs/MAIN.TcPOU b/solution/tc_project_app/POUs/MAIN.TcPOU index 2c8e8a8..261f7c0 100644 --- a/solution/tc_project_app/POUs/MAIN.TcPOU +++ b/solution/tc_project_app/POUs/MAIN.TcPOU @@ -1,30 +1,30 @@  - + , - nSelectedError=> , - pErrorSystem=> ); + En:= TRUE, + bReset:= , + nErrorNum:= , + bACK:= , + bValidSelection:= , + nTableRowIndex:= , + EnO=> , + nSelectedError=> , + pErrorSystem=> ); FOR GVL.iAxis:=1 TO gvl_app.axisNum DO - aFbAxesError[gvl.iAxis](EN:=TRUE, - nNC_ErrorID:= gvl.axes[gvl.iAxis].status.nErrorID, - nNC_AxisID:=gvl.axes[gvl.iAxis].Axis.NcToPlc.AxisId, - ErrorSystem:= fbErrorSystem.pErrorSystem); + aFbAxesError[gvl.iAxis](EN:=TRUE, + nNC_ErrorID:= gvl.axes[gvl.iAxis].status.nErrorID, + nNC_AxisID:=gvl.axes[gvl.iAxis].Axis.NcToPlc.AxisId, + ErrorSystem:= fbErrorSystem.pErrorSystem); END_FOR - - + + (*call all the necessary instance (input assistance F2 or right click) according to the terminals that you have in your hardware and - add "TRUE" in the input En, the corresponding number of termianl to the iTerminal_ID and -the variable "fbErrorSystem.pErrorSystem" to the input ErrorSystem in each FB E. g. : + add "TRUE" in the input En, the corresponding number of termianl to the iTerminal_ID and +the variable "fbErrorSystem.pErrorSystem" to the input ErrorSystem in each FB E. g. : fbEL1808( - En:= TRUE, - iTerminal_ID:= 01, - ErrorSystem:= fbErorSystem.pErrorSystem, - EnO=> , - bError=> ); + En:= TRUE, + iTerminal_ID:= 01, + ErrorSystem:= fbErorSystem.pErrorSystem, + EnO=> , + bError=> ); *) ]]> diff --git a/solution/tc_project_app/PlcTask.TcTTO b/solution/tc_project_app/PlcTask.TcTTO index dfc6cfd..98d1faf 100644 --- a/solution/tc_project_app/PlcTask.TcTTO +++ b/solution/tc_project_app/PlcTask.TcTTO @@ -1,5 +1,5 @@  - + 1000 diff --git a/solution/tc_project_app/Visualization Manager.TcVMO b/solution/tc_project_app/Visualization Manager.TcVMO index d2e340f..83b1ee8 100644 --- a/solution/tc_project_app/Visualization Manager.TcVMO +++ b/solution/tc_project_app/Visualization Manager.TcVMO @@ -1,5 +1,5 @@  - + diff --git a/solution/tc_project_app/tc_mca_std_lib b/solution/tc_project_app/tc_mca_std_lib index 32b87da..ab99f8c 160000 --- a/solution/tc_project_app/tc_mca_std_lib +++ b/solution/tc_project_app/tc_mca_std_lib @@ -1 +1 @@ -Subproject commit 32b87da57e91d57eaebbf927638554641a37c6b9 +Subproject commit ab99f8caafe634de4ebfb327f8cf1ebe53228514 diff --git a/twincat_version_manager.py b/twincat_version_manager.py new file mode 100644 index 0000000..3483331 --- /dev/null +++ b/twincat_version_manager.py @@ -0,0 +1,40 @@ +import glob +import xml.etree.ElementTree as ET + +VERSION_TAGS = {"**/*.Tc*": "ProductVersion", "**/*.tsproj": "TcVersion"} +CORRECT_VERSION = "3.1.4024.0" + + +def check_versions(): + """ + Checks the Twincat version used to create a file. + It assumes that the version is stored as an attribute on the top element of the file, the attribute names are + listed in VERSION_TAGS. + :return: A dictionary of incorrect files and their version numbers + """ + incorrect_files = dict() + for file_path, version_attrib in VERSION_TAGS.items(): + found_files = glob.glob(file_path, recursive=True) + if not found_files: + raise IOError("ERROR: No files of type {} found".format(file_path)) + for file in found_files: + tree = ET.parse(file) + try: + found_version = tree.getroot().attrib[version_attrib] + if found_version != CORRECT_VERSION: + incorrect_files[file] = found_version + except KeyError: + print("WARNING: No version found for {}".format(file)) + return incorrect_files + + +if __name__ == "__main__": + try: + incorrect_files = check_versions() + for file, version in incorrect_files.items(): + print("ERROR: {} has incorrect version {}, expected version {}".format(file, version, CORRECT_VERSION)) + if incorrect_files: + exit(1) + except IOError as e: + print(e) # Likely no files found + exit(2)