Skip to main content

TwinCAT Git Integration

Setup

Under GIT > Settings

Input your GIT credentials here and make note of the location for your repos. I recommend you pin it in your File Explorerimage.png

Ensure these settings are as shownimage.png

Ensure these boxes are checked off

image.png

Under Git Repository Settings, if you need to change the settings for a specific repo

Set the following ( with your name and email)image.png

Instructions on how to set the compare tool for Git (diff checking) can be found here: Beckhoff Information System - English

Cloning

Make sure you have a git account and are added to the SilverHills Organization (Ask Matt or Kieran)

Navigate to the repo that you want to clone

image.png

image.png

In TwinCAT navigate to File>Clone Repository

In the Path, paste the link that you copied from github. 

Leave the Repository location to its default path. TwinCAT git works best the closest to C: as possible. 

image.png

Click Clone

Your repo will open.

Usage

Key Concepts

Repository: A folder or location in which the history of the contents are tacked. 

Local Repo: The repo that exists on the device you are currently using.

Remote Repo: Repos that exist external to your device (Most of the time this is Github)

It's important to understand that there is no functional difference between a local and remote repo. There is nothing special about the repo that exists on Github. It is pure convention that we agree that it is the "master" repo that all others act on, but it could just as easily by any other computer, or a local server.

Change: A difference that git detects between the code you are working on and the code in your local repo. As you code, changes will accumulate. 

Stage: Selecting a file or part of a file as to be part of a commit that has not yet happened. 

Commit: The writing of staged changes to the history of your local repo. Each commit has an associated comment that the user writes to describe the changes that are contained.

Fetch: The retrieval of a list of all commits that are present on remote repos but not your local repo. This just gets the list, it does not change your code. 

Pull: Taking all commits that are present on remote repos and updating your local repo to also contain those commits.  

Push: Taking all the commits that are present on your local repo but not the remote and sending them to the remote. 

Conflict: When attempting to pull or push, git detects that there are changes that are mutually exclusive and do not hold priority over each other. The pull or push is halted until the conflict is resolved. 

Merge: Conflicts are present and user intervention is required on a line-by-line basis to choose the version of the code that should survive the merge.

Windows

If the git windows are not present, you can find them by navigating to View>Git Changes/Git Repository

image.png

These windows are where the majority of the git work is done. 

Opening a Repo

Upon launching TwinCAT, you can find your configured repos in the bottom right corner.

image.png

image.png

If your repo has only one Solution in it, that solution will automatically open, otherwise TwinCAT will ask you which Solution you wish to open. 

Git Control

Commit

Under Git Changes press the "+" buttons next to the changed files to stage them. 

image.pngimage.png

You can unstage a file by pressing the "-".

If you want to see what exact lines are changed, double click on the file. TcProjectCompare will launch. There is a setup required to get TcProjectCompare set as your comparison tool. Talk to Kieran. 

image.png

The RIGHT side is the new code that you have written, the LEFT is the old code. This is indicated by the grey arrow between the two panes at the top. 

You do not need to accept anything at this time. This software also allows for merging. Simply close the window. 

Add a suitable comment to the commit and press Commit Staged.

image.png

The committed files are removed from your Changes list and the commit is added to the history of your local repo as an Outgoing change. 

image.png

COMMIT SMALL! COMMIT OFTEN!

Closing the Solution

For the following actions, it is important that you CLOSE your solution before Fetching and Pulling 

ALWAYS unload your project before interacting with remote repos. Committing to a local repo is fine, but when you interact with a remote repo, you need to ensure that all temporary files are closed. 

image.png

Once the project is unloaded, push and pull your project as needed. 

When you want to open the project again, select "Reload project with dependencies"

image.png

Remote Repo

image.png

It is this header in the "git changes" tab that allows you to interact with your remote repo and do the following:

  • View and change what branch you are on - "master"
  • Fetch
  • Pull
  • Push
  • Sync
  • View how many outgoing and incoming commits there are 

Multi-Project Integration

If we want to integrate multiple projects onto a single IPC and keep the git repos separate, there are some accommodations that need to be made. 

Project Structure

  • Top-Level System Repo [TwinCAT XAE Project]
    • A: Sub-Level PLC Repo [TwinCAT PLC Project]
    • B: Sub-Level PLC Repo [TwinCAT PLC Project]
    • C: ...

Each component of the project is contained within its own repo.

The Top-Level System repo of the only project that is made with the template XAE Project. It it intended to contain the system IO, licences, mappings, and boot settings. 

The Sub-Level PLC repos are made with the template PLC Project. Each PLC project is intended to contain its own self-contained in-production system (like a palletizer or racking robot). The PLC project contains all the code for a single project, and there should be no cross-talk between PLC projects. 

Each project should have it's own separate repo. 

Top Level Project Creation

Create a repo location and push it to the remote. Create an XAE project in this location. 

image.png

Sub Level PLC Project Creation

For the projects themselves, the code is isolated from the IO and boot settings (those are located in the top-level project)

image.png

It is important that each PLC project has a different ADS port, otherwise the projects will conflict. 

image.png

Depending on the PLC Project application, a different ADS port will be used. This allows a PLC project to be reused and added to different systems while not conflicting with other projects on the IPC. Ports 851- 899 can be used. 

Project Type ADS Port
Generic Material Handling 851, 861, 871, 881, 891
Racking 852, 862, 872, 882, 892
Deracking 853, 863, 873. 883, 893
Palletizing 854, 864, 874, 884, 894

Depanning
855, 865, 875, 885, 895

856, 866, 876, 886, 896

857, 867, 877, 887, 897

858, 868, 878, 888, 898

859, 869, 879, 889, 899

860, 870, 880, 890

This table is a work in process and subject to change