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.
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.