Automation Interface support
The Static Analysis can partly be operated via the Automation Interface (AI). AI support includes the following commands/actions:
- Explicit execution of Static Analysis via the Automation Interface
- Implicit execution of Static Analysis via the Automation Interface
- Save settings/configuration via Automation Interface
- Load settings/configuration via Automation Interface
- Export metrics
- Start static analysis and export to Sarif file
Please also refer to the Automation Interface documentation:
Product description
Explicit execution of Static Analysis via the Automation Interface
You can run the static analysis automatically by calling the RunStaticAnalysis() method via the Automation Interface.
Functionally, this corresponds to the following commands:
Parameters:
bCheckAll can be specified as optional parameter for the RunStaticAnalysis() method. However, the method can also be called without parameters.
Parameter | Call |
|---|---|
RunStaticAnalysis() | Execution of the Run static analysis [Check all objects] command |
RunStaticAnalysis(bCheckAll = TRUE) | |
RunStaticAnalysis(bCheckAll = FALSE) | Execution of the Run static analysis command |
PowerShell sample:
$p = $sysMan.LookupTreeItem("TIPC^MyPlcProject^MyPlcProject Project")
$p.RunStaticAnalysis()C# sample for TC3.1 version >= Build 4024:
ITcPlcIECProject3 plcIec3 = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project") as ITcPlcIECProject3;
plcIec3.RunStaticAnalysis();C# sample for TC3.1 version >= Build 4026:
ITcPlcIECProject4 plcIec4 = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project") as ITcPlcIECProject4;
plcIec4.RunStaticAnalysis();Implicit execution of Static Analysis via the Automation Interface
Alternatively, the setting Perform static analysis automatically can be enabled, and the project can be created via the Automation Interface, so that the Static Analysis is implicitly performed during the project creation process.
Save settings/configuration via Automation Interface
![]() | Available from TwinCAT 3.1 Build 4026 |
The settings from Static Analysis can be saved or exported to a *.csa file via Automation Interface.
Parameters:
For the SaveStaticAnalysisSettings(string bstrFilename) method the destination path of the configuration file must be specified as a transfer parameter.
![]() | The |
C# sample for TC3.1 version >= Build 4026:
// Path to the location to export the SAN configuration
string saveCsaPath = @"C:\Users\UserName\Desktop\SaveTest.csa";
[…]
// Navigate to PLC project
ITcPlcIECProject4 plcIec4 = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project") as ITcPlcIECProject4;
// Save SAN configuration
plcIec4.SaveStaticAnalysisSettings(saveCsaPath);Load settings/configuration via Automation Interface
![]() | Available from TwinCAT 3.1 Build 4026 |
A ready-made Static Analysis configuration (*.csa file) can be loaded into the PLC project via Automation Interface. The settings loaded by this can then be checked by AI by running the Static Analysis (see above).
Parameters:
For the LoadStaticAnalysisSettings(string bstrFilename) method the path of the configuration file to be loaded must be specified as a transfer parameter.
![]() | The |
C# sample for TC3.1 version >= Build 4026:
// Path to load a SAN configuration
string loadCsaPath = @"C:\Users\UserName\Desktop\LoadTest.csa";
[…]
// Navigate to PLC project
ITcPlcIECProject4 plcIec4 = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project") as ITcPlcIECProject4;
// Load SAN configuration
plcIec4.LoadStaticAnalysisSettings(loadCsaPath);
// Optionally run SAN afterwards
plcIec4.RunStaticAnalysis();Export metrics
![]() | Available from TwinCAT 3.1 Build 4026.4 |
The standard metrics can be exported to a text file (*.csv) via the Automation Interface. A current calculation of the metrics is performed implicitly. If this process was executed manually, it would include the following two commands:
- Command 'View Standard Metrics'
- Export table command, see Commands in the context menu of the 'Standard Metrics' view
Parameters:
For the ExportStandardMetrics(string bstrFilename) method, the destination path of the resulting export file must be specified as a transfer parameter.
![]() | The |
C# sample for TC3.1 version >= Build 4026.4:
// Path to save the csv file
string savePath = @"C:\Users\UserName\Desktop\Metrics.csv";
[…]
// Navigate to PLC project
ITcPlcIECProject5 plcIec5 = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project") as ITcPlcIECProject5;
// Export standard metrics
plcIec5.ExportStandardMetrics(savePath);Start static analysis and export to Sarif file
![]() | Available from TwinCAT 3.1.4026.20 |
The static code analysis can be started via Automation Interface and the result saved in a SARIF file.
Functionally, this corresponds to the following command:
Parameters:
For the method ExportToSarif(string exportPath), the destination path of the resulting Sarif file can be specified as a transfer parameter. If you do not specify a path, the file is saved in the folder of the current project.
Note:
Before executing the ExportToSarif() method - and therefore before running the analysis and saving the SARIF file - you can load the desired SAN configuration by calling the LoadStaticAnalysisSettings() method. Further information on loading the configuration via Automation Interface can be found here:
C# sample for TC3.1 version >= Build 4026.20:
// Path to load a SAN configuration
string loadCsaPath = @"C:\Users\UserName\Desktop\LoadTest.csa";
// Path to save the Sarif file
string sarifExportPath = @"C:\Users\UserName\Desktop\SarifFolder\SarifExpotViaAutomationInterface.sarif.json";
// Navigate to PLC project
ITcPlcIECProject7 plcIec7 = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project") as ITcPlcIECProject7;
// Load desired SAN configuration
plcIec7.LoadStaticAnalysisSettings(loadCsaPath);
// Run SAN and save results in Sarif file
plcIec7.ExportToSarif(sarifExportPath); 