Automation Interface support

The Static Analysis can partly be operated via the Automation Interface (AI). AI support includes the following commands/actions:

Please also refer to the Automation Interface documentation:
Product description

Explicit execution of Static Analysis via the Automation Interface

The two following commands can be called explicitly via the Automation Interface:

bCheckAll can be specified as optional parameter for the method RunStaticAnalysis(). However, the method can also be called without parameters.

Parameter

Call

RunStaticAnalysis()

Execution of the Run static analysis command

RunStaticAnalysis(bCheckAll = FALSE)

RunStaticAnalysis(bCheckAll = TRUE)

Execution of the Run static analysis [Check all objects] command

PowerShell sample:

$p = $sysMan.LookupTreeItem("TIPC^MyPlcProject^MyPlcProject Project")
$p.RunStaticAnalysis()

C# sample:

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

Automation Interface support 1:

Available from TwinCAT 3.1 Build 4026

The settings from Static Analysis can be saved or exported to a *.csa file via Automation Interface.

For the method SaveStaticAnalysisSettings(string bstrFilename) the destination path of the file must be specified as a transfer parameter.

Note: The method RunStaticAnalysis is available from the interface ITcPlcIECProject3. The methods SaveStaticAnalysisSettings and LoadStaticAnalysisSettings are offered from the interface ITcPlcIECProject4.

C# sample:

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

Automation Interface support 2:

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

For the method LoadStaticAnalysisSettings(string bstrFilename) the path of the file to be loaded must be specified as a transfer parameter. 

Note: The method RunStaticAnalysis is available from the interface ITcPlcIECProject3. The methods SaveStaticAnalysisSettings and LoadStaticAnalysisSettings are offered from the interface ITcPlcIECProject4.

C# sample:

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

Automation Interface support 3:

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:

For the method ExportStandardMetrics(string bstrFilename), the path that the export file is saved on must be specified as a parameter value. 

Automation Interface support 4:

The method ExportStandardMetrics is available from the interface ITcPlcIECProject5.

C# sample:

// 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);