Skip to content

Attach to debug TwinCAT HMI Server Extension with just one click

The information in this post are usable with:

  • VisualStudio 2017, 2019
  • TE2000-HMI-Engineering 1.12.*.* (Download) and future releases
  • Sources of this post: GitHub Repository

Very often you have to implement your own business-logic in a TwinCAT HMI Server Extension (link: Beckhoff). To debug that extension you have to attach to the process which has loaded and runs the corresponding functionality. In TwinCAT HMI 1.12 the running process to execute that server extension has changed. In the TwinCAT HMI version 1.10 the server extension was loaded into the domain of the server process “tchmisrv.exe”. Because of security and stability reason the process has been sourced out to an individual process for any custom server extension.

In the following example a basic TwinCAT HMI Project has been created. In addition a basic TwinCAT HMI Server Extension is added to the solution. Both projects are weaved together by using the ctx-menu “Add Reference…” of the “References”-node within the HMI project.

The ServerExtensionCSharp1 project is referenced by the HMI project,
and the extension is loaded and running marked by the green arrow.

Open your prefered task manager to check the current process hierarchy of the TwinCAT HMI Server and the TwinCAT HMI Server Extension. As you can see the “TcHmiSrv.exe” process with the ‘Window Title’ “TcHmiSrv Engineering” is running, currently the process has two childs:

  • TcHmiSrv SysTray
  • TcHmiSrv (PID 18040): SeverExtensionCSharp1

The “TcHmiSrv SysTray” is not interesting for us.

The most interesting process is:

Solution: “Attach to Extension”

In Visual Studio you have to use the “Attach to Process”-dialog reachable by clicking “Debug / Attach to Process…” to start debugging of that individual process. In that dialog it is required to select a specific process you like to attach to. First pitball would be to search for the name of your extension, the result would be zero. Searching for the server process is the second pitball. Both processes are not correct. As a minimum you need four clicks to attach, a way to much work (and waste of dev-time)!

As stated at the begin of this post the extension is loaded in an individual domain / process. That process is named “TcHmiExtensionContainer” and you have to attach to that process. Not very intuitiv, right? We know!

Debug by one click!

To solve that useability issue the TwinCAT HMI provides a very smart way. Just open the context menu of your loaded and running TwinCAT HMI Server Extension named “ServerExtensionCSharp1” and click “Attach to Extension”.

As a result your Visual Studio switches to the debug view and breakpoints will be hit.

7 Comments

  1. Jon Jon

    Hello Christian,
    I do some HMI projects with TE2000_TC3_HMI_EN.pdf(V1.3) . But it has little server extension content. I have some questions, such as how to connect to mysql with server extension.Does we have some documents about server extensions?

    • I have sent you an e-mail to your provided e-mail address. Thanks for asking!

      • Kot Kot

        Hello,
        I want to create server extension in c#, which will use eventlogger and db, but i can’t find any documentation on infosys. Do you have any kind of guide ?

        • The TwinCAT HMI is already shipped with samples for TwinCAT HMI Server Extensions. You can use them as a base implementation. Working with DB-connection or with the TwinCAT EventLogger is like working with any other library/service approach. Just use the available APIs and call the functionalities, sure you have to keep an eye on multithreading concepts, mutexes, object locks, etc. But in general you can do everything.

          Do you have any concrete issue?

          The TwinCAT’ EventLogger part is described in the Beckhoff InfoSys:
          https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_eventlogger/index.html&id=8504177607767980219

          And a EventLogger samples by use of C# and COM is provided here:
          https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_eventlogger/9007206112473739.html&id=8487049537372516111

  2. Hi Christian.
    I am very interested to test nuget packages for TCHmi. But i cant find Tchmi 1.12 anywhere. Is it possible to test this version?
    I want to test adding a video stream from vision project.

    Best regards,
    Jon Christian

    • Thanks for asking Jon.

      You are not the first who is requesting more information about the 1.12 release date. We are really working on it. Currently we are reaching the last mile of the beta program. Hopefully, the release will be in June/July. There are some more blog posts in the pipeline about nice new features (e.g. TypeScript-support, Automation Interface, general Nuget-support, etc.). They will be published as soon when the 1.12 version is released.

      Anyway, right now we already publish some nuget packages on the official nuget.org (only pre-releases). Check them out, but unfortunately they are only usable with the TwinCAT HMI 1.12 release (not 1.8 nor 1.10):

      https://www.nuget.org/packages?q=Beckhoff.TwinCAT.HMI

      Despite that fact you can contact the Beckhoff support for joining the beta program…

      Beckhoff Support Germany: https://www.beckhoff.com/english.asp?beckhoff/germany.htm

      Beckhoff Support Norway: https://www.beckhoff.com/english/beckhoff/norway.htm

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.