Skip to content

Instantly share code, notes, and snippets.

@klauer
Last active August 15, 2019 17:19
Show Gist options
  • Save klauer/a1489e408042a95ed9e804e37e7832c2 to your computer and use it in GitHub Desktop.
Save klauer/a1489e408042a95ed9e804e37e7832c2 to your computer and use it in GitHub Desktop.
pre-commit hook for Beckhoff TwinCAT projects (.tmc/.tpy files)
#!/bin/bash
# Save this file as .git/hooks/pre-commit and make it executable (chmod +x)
#
# Quick install:
# curl -L https://git.io/fjd80 > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
#
# Largely based on https://github.com/michalrus/git-hooks-code-autoformat/blob/master/pre-commit
# and https://medium.com/@harshitbangar/automatic-code-formatting-with-git-66c3c5c26798
echo "** pre-commit hook **"
echo "* Formatting the berkhoff!"
FORMAT_EXTENSIONS=("\.tmc$" "\.tpy$")
REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
EXT_GREP_ARGS=$(echo ${FORMAT_EXTENSIONS[@]}|tr " " "|")
set -e
# for debugging: set -x
if [ ! $(command -v xmllint) ]; then
echo "ERROR: xmllint not found!";
exit 1;
fi
git diff --name-only --cached | {
while IFS= read -r fn ; do
abs_fn="${REPO_ROOT_DIR}/${fn}"
# Skip deleted files
[ -f "$abs_fn" ] || continue
# Check the extension
(echo "$abs_fn" | grep -Eqi -e "$EXT_GREP_ARGS") || continue
temp_file="$(mktemp)"
lint_result=$(xmllint --format "${abs_fn}" >"$temp_file" )
if [ $lint_result -ne 0 ]; then
echo 'fatal: `xmllint --format` failed for:' "$abs_fn" >&2
rm "$temp_file"
exit 1
fi
cat "$temp_file" > "$abs_fn"
rm "$temp_file"
git add "$abs_fn"
done
}
diff --git a/TC_project/TwinCAT Project1/TwinCAT Project1/Untitled1/Untitled1.tmc b/TC_project/TwinCAT Project1/TwinCAT Project1/Untitled1/Untitled1.tmc
index 73f0ba1..9a3f716 100644
--- a/TC_project/TwinCAT Project1/TwinCAT Project1/Untitled1/Untitled1.tmc
+++ b/TC_project/TwinCAT Project1/TwinCAT Project1/Untitled1/Untitled1.tmc
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<TcModuleClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.beckhoff.com/schemas/2009/05/TcModuleClass" Hash="{79967873-A014-B1E6-294C-B259B6722CB3}" GeneratedBy="TwinCAT XAE Plc">
+<TcModuleClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.beckhoff.com/schemas/2009/05/TcModuleClass" Hash="{8312B438-DEA2-8292-CD86-F443AB269ECB}" GeneratedBy="TwinCAT XAE Plc">
<DataTypes>
<DataType>
<Name GUID="{6F5942ED-BFA1-497D-8225-23C6DAAD0A09}" TcBaseType="true">ST_LibVersion</Name>
@@ -1157,6 +1157,21 @@
</Properties>
<BitOffs>4516064</BitOffs>
</Symbol>
+ <Symbol>
+ <Name>MAIN.nUnsignedInt32</Name>
+ <BitSize>32</BitSize>
+ <BaseType>UDINT</BaseType>
+ <Properties>
+ <Property>
+ <Name>pytmc</Name>
+ <Value>
+ pv: ADS_TST:nUnsignedInt32
+ io: io
+ </Value>
+ </Property>
+ </Properties>
+ <BitOffs>4519872</BitOffs>
+ </Symbol>
<Symbol>
<Name>MAIN.diTestCycle</Name>
<BitSize>32</BitSize>
@@ -1170,7 +1185,7 @@
</Value>
</Property>
</Properties>
- <BitOffs>4519872</BitOffs>
+ <BitOffs>4519904</BitOffs>
</Symbol>
</DataArea>
</DataAreas>
@@ -1183,7 +1198,7 @@
</Property>
<Property>
<Name>ChangeDate</Name>
- <Value>2019-08-15T10:04:35</Value>
+ <Value>2019-08-15T10:06:46</Value>
</Property>
<Property>
<Name>GeneratedCodeSize</Name>
diff --git a/TC_project/TwinCAT Project1/TwinCAT Project1/Untitled1/Untitled1.tpy b/TC_project/TwinCAT Project1/TwinCAT Project1/Untitled1/Untitled1.tpy
index 9f5df81..5ff8c9b 100644
--- a/TC_project/TwinCAT Project1/TwinCAT Project1/Untitled1/Untitled1.tpy
+++ b/TC_project/TwinCAT Project1/TwinCAT Project1/Untitled1/Untitled1.tpy
@@ -921,11 +921,18 @@
<IOffset>564508</IOffset>
<BitSize>16</BitSize>
</Symbol>
+ <Symbol>
+ <Name>MAIN.nUnsignedInt32</Name>
+ <Type>UDINT</Type>
+ <IGroup>16448</IGroup>
+ <IOffset>564984</IOffset>
+ <BitSize>32</BitSize>
+ </Symbol>
<Symbol>
<Name>MAIN.diTestCycle</Name>
<Type>DINT</Type>
<IGroup>16448</IGroup>
- <IOffset>564984</IOffset>
+ <IOffset>564988</IOffset>
<BitSize>32</BitSize>
</Symbol>
</Symbols>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment