Table Of Contents

TcForms

The NuGet-package TcForms simplifies the development of functional WinForms applications for TwinCAT PLCs. It manages the ADS communication with PLC variables and links UI controls with minimal programming effort.


Requirements

  1. .NET 8.0
  2. TwinCAT 3.1.4024.10 (XAE, XAR or ADS Setup) or later.

First Steps

Add Tc3_TcForms PLC-Library (from Sample Project) to your TwinCAT PLC project and call the FB_License function block to validate the CLIENT license. No license key is required on a development PC.

PROGRAM MAIN
VAR
	fbTcFormsLicense	: Tc3_TcForms.FB_License;
END_VAR

----

// TcForms License
fbTcFormsLicense(bExecute:=TRUE);

Create a Windows Forms App project with .NET 8.0. Add a file called config.ini to the project. Navigate to the properties of this file and select ‘Build Action’: Content and ‘Copy to output’: Copy if newer. Copy the following content into the config.ini file.

[License]
Type=CLIENT
Key=
SymbolName=MAIN.fbTcFormsLicense
[TwinCAT]
AmsNetID=127.0.0.1.1.1
CycleTime=100

Add a TcControl (e.g. TcButton) to your Form and set the name of the variable to be linked under Properties -> TwinCAT -> PlcVariable. Add the following code to your Form class to link all TcControls of the form to the TwinCAT PLC.

using System.Windows.Forms;
using TcForms;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        private TcControlLink tcControlLink = new();
        public Form1()
        {
            InitializeComponent();
            this.Load += Form1_Load;
            this.FormClosing += Form1_FormClosing;
        }

        private void Form1_Load(object? sender, EventArgs e)
        {
            foreach (Control control in this.Controls)
            {
                if (control is ITcControl)
                {
                    tcControlLink.Add(control);
                }
            }
        }
        private void Form1_FormClosing(object? sender, FormClosingEventArgs e)
        {
            foreach (Control control in this.Controls)
            {
                if (control is ITcControl)
                {
                    tcControlLink.Remove(control);
                }
            }
        }        
    }
}

Build and start the project to check the connection.


Sample Project

GitHub Sample Project ‘TwinCAT-GUI’