TwinCAT 3 C++ Q&A|Mastering PTCID Variables: A Comprehensive Guide to Reading & Writing Them in Programs, Including Scope Monitoring with TwinCAT C++, MATLAB, Robot Models, & XTS Models

In projects that incorporate TcCOM Objects, such as TwinCAT C++, MATLAB, robot models, XTS (Extended Transportation System) models, and so on, as shown in the figure below,

If you wish to read and write these parameters within a PLC program, the process would involve:


There are two methods:

The first method (Advantage: Allows reading using variable names):

① These objects require binding to a task. After creating the corresponding task, check the "create symbol" option in the task settings.


It is necessary to ensure that both are running as TcCOM components within the Runtime environment.


The Scope service locates the data region corresponding to the variables within the TcCOM component through the use of Symbols, enabling the reading of relevant variable values.

② When it comes to the PTCID variable, there is a column labeled "CS"; ensure that "CS" is checked.

If you wish to monitor variables through the Scope, you need to create Symbols for the corresponding TcCOM components so that the Scope service can locate them. Here, we will use TcC++ and TcSimulink as examples for creating Symbols (the process is similar for other TcCOM components in TwinCAT).

Example: Double-click on the icons of the two TcCOM instances in the figure above -> select the "Data Area" tab -> check the "CS" checkbox for the variables you wish to monitor -> reactivate the project, and you will then be able to index the corresponding variables in the Scope.


③ After activating the configuration, you can directly view the corresponding variables (for instance, if the variable is: Object1 (untitled).CallBy) using the Target Browser. This method is applicable to many similar scenarios.




The second method (Direct reading using variable addresses):

① Through the previous method, it can be observed that the addresses of these variables follow a pattern. If there is no need to use variable names, this method can be directly applied.