TwinCAT3 - 自动化接口 - 在 Jenkins 控制台上显示 O/P

TwinCAT3 - Automation Interface - Display O/P on Jenkins console

  1. 使用自动化接口,我能够在 TwinCAT 3.1.4024.4 中构建和启动激活配置。
  2. 如果在正常运行和Activate Configuration下相同的项目,消息和错误会显示在VS2013的输出控制台中。
  3. 在自动化界面中,使用 ErrorItems errors = dte.ToolWindows.ErrorList.ErrorItems; 我只能读取和显示消息 1 到 10。
  4. 其他消息有不同的格式TwinCAT System (10000) or PlcTask (350):
  5. 这不会被dte.ToolWindows.ErrorList.ErrorItems;捕获吗?
  6. VS2013的输出控制台有两个选项:Show output from build and Show output from twinCAT.
  7. 在自动化接口中,我想,我只能从构建中读取消息而不能从 TwinCAT 中读取消息
  8. 还有什么方法可以读取 TwinCAT 消息吗?

VS2013控制台输出:

    Message 1   The application is up to date       0   0   
    Message 2   Build complete -- 0 errors, 0 warnings : ready for download!        0   0   
    Message 3   Additional code checks ...      0   0   
    Error   4   SA0033: Unused Variable 'fbSum_Test'    UnitTestJenkins (UnitTestJenkins\UnitTestJenkins)
    Error   5   SA0033: Unused Variable 'fbDegreesToRadians'    4   1   UnitTestJenkins (UnitTestJenkins\UnitTestJenkins)
    Error   6   SA0033: Unused Variable 'data'  FB_DegreesToRadians_Test.DegreesToRadians_Test1 3   1   UnitTestJenkins (UnitTestJenkins\UnitTestJenkins)
    Message 7   Additional code checks complete -- 3 errors     0   0   
    Message 8   Generate TMC information ...        0   0   
    Message 9   Import symbol information ...       0   0   
    Message 10  generate boot information...    PLC.UnitTestJenkins 0   0   UnitTestJenkins (UnitTestJenkins\UnitTestJenkins)
    Message 11  29.11.2019 09:52:58 477 ms | 'TwinCAT System' (10000): Ein Neustart des TwinCAT Systems wurde von AmsNetId: 10.73.8.239.1.1 Port 32867 angefordert.     
    Message 12  29.11.2019 09:52:58 614 ms | 'TwinCAT System' (10000): Konfiguration des COM Servers TcEventLogger wird gesichert!      
    Message 13  29.11.2019 09:52:59 440 ms | 'TwinCAT System' (10000): COM Servers TcEventLogger wird heruntergefahren!     
    Message 14  29.11.2019 09:53:01 467 ms | 'TwinCAT System' (10000): Konfiguration des COM Servers TcEventLogger wird geladen!        
    Message 15  29.11.2019 09:53:01 468 ms | 'TwinCAT System' (10000): COM Server TcEventLogger wird initialisiert!     
    Message 16  29.11.2019 09:53:01 517 ms | 'TwinCAT System' (10000): TcIo Server wurde gestartet: TcIo.       
    Message 17  29.11.2019 09:53:01 530 ms | 'TwinCAT System' (10000): TcPlc30 Server wurde gestartet: TcPlc30.     
    Message 18  29.11.2019 09:53:01 537 ms | 'TwinCAT System' (10000): TcRtsObjects Server wurde gestartet: TcRtsObjects.       
    Message 19  29.11.2019 09:53:01 543 ms | 'TwinCAT System' (10000): TcRTime Server wurde gestartet: TcRTime.     
    Message 20  29.11.2019 09:53:01 660 ms | 'License Server' (30): license validation status is Valid(3)       
    Message 21  29.11.2019 09:53:01 704 ms | 'TCRTIME' (200): Intel(R) Core(TM)-i 4'th generation detected      
    Message 22  29.11.2019 09:53:02 078 ms | 'TwinCAT System' (10000): COM Server TcEventLogger wird gestartet!     
    Error   23  29.11.2019 09:53:02 108 ms | 'PlcTask' (350): FAILED TEST 'PRG_TEST.fbSum_Test@TwoPlusTwoEqualsFour', EXP: 4, ACT: 3, MSG: The calculation is not correct       
    Error   24  29.11.2019 09:53:02 168 ms | 'PlcTask' (350): FAILED TEST 'PRG_TEST.fbDegreesToRadians@DegreesToRadians_Test1', EXP: 0.0, ACT: 0.01745329, MSG: The calculation is not correct      
    Error   25  29.11.2019 09:53:02 228 ms | 'PlcTask' (350): FAILED TEST 'PRG_TEST.fbDegreesToRadians@DegreesToRadians_Test2', EXP: 1.0, ACT: 0.01745329, MSG: The calculation is not correct      
    Error   26  29.11.2019 09:53:02 388 ms | 'PlcTask' (350): | ==========TESTS FINISHED RUNNING==========      
    Error   27  29.11.2019 09:53:02 708 ms | 'PlcTask' (350): | Test suites: 2      
    Error   28  29.11.2019 09:53:03 028 ms | 'PlcTask' (350): | Tests: 4        
    Error   29  29.11.2019 09:53:03 348 ms | 'PlcTask' (350): | Successful tests: 1     
    Error   30  29.11.2019 09:53:03 668 ms | 'PlcTask' (350): | Failed tests: 3     
    Error   31  29.11.2019 09:53:03 988 ms | 'PlcTask' (350): | ======================================  

Jenkins 控制台上的输出:[只能读取前 10 条消息]

    ActivateConfiguration Errors count: 10
    vsBuildErrorLevelLow: Description: The application is up to date
    vsBuildErrorLevelLow: Description: Build complete -- 0 errors, 0 warnings : ready for download!
    vsBuildErrorLevelLow: Description: Additional code checks ...
    vsBuildErrorLevelHigh: Description: SA0033: Unused Variable 'fbSum_Test'
    vsBuildErrorLevelHigh: Description: SA0033: Unused Variable 'fbDegreesToRadians'
    vsBuildErrorLevelHigh: Description: SA0033: Unused Variable 'data'
    vsBuildErrorLevelLow: Description: Additional code checks complete -- 3 errors
    vsBuildErrorLevelLow: Description: Generate TMC information ...
    vsBuildErrorLevelLow: Description: Import symbol information ...
    vsBuildErrorLevelLow: Description: generate boot information...
    Exit code is 1

C#代码:

//5.4.1 ITcPlcProject - Automation Interface document 
    ITcSmTreeItem plcProjectRootItem = sysMan.LookupTreeItem("TIPC^UnitTestJenkins");
    ITcPlcProject iecProjectRoot = (ITcPlcProject)plcProjectRootItem;
    iecProjectRoot.BootProjectAutostart = true;
    iecProjectRoot.GenerateBootProject(true);

    sysMan.ActivateConfiguration();
    sysMan.StartRestartTwinCAT();
    ErrorItems ActivateConfigurationErrors = dte.ToolWindows.ErrorList.ErrorItems;
    Console.WriteLine("ActivateConfiguration Errors count: " + ActivateConfigurationErrors.Count);

    for (int i = 1; i <= ActivateConfigurationErrors.Count; i++)
    {
        ErrorItem item = ActivateConfigurationErrors.Item(i);
        Console.WriteLine(item.ErrorLevel + ": " + "Description: " + item.Description);
    }

请查看输出的屏幕截图: Build&TwinCAToutput

我看到您正在使用 TcUnit。 问题是您在收集 ErrorItems 之前没有等待 TcUnit 完成。您仅在执行 ActivateConfiguration() 和 StartRestartTwincat() 后收集错误项(这就是为什么您只获得前 10 个)。您需要等待 TcUnit 完成。

将 TcUnit 的 运行 包裹在一个 while 循环中,并向 TcUnit 询问结果。一旦返回所有结果(当您完成所有打印时就完成了),您就可以使用您的 ErrorItems。所以基本上,在 while-true 循环中收集 ErrorItems(但确保每隔一秒左右使用一次睡眠),一旦你从 TcUnit 获得所有结果(换句话说,行 ======== ==TESTS FINISHED 运行========== 以及随后的所有内容),您可以打印所有错误项(或解析它们,或对它们做任何您想做的事)。

祝你好运!

谢谢 @Jakob
您的建议帮助解决了这个问题。
重新启动后,等待 10 秒,每次读取后,休眠 5 秒。

    sysMan.ActivateConfiguration();
    sysMan.StartRestartTwinCAT();
    System.Threading.Thread.Sleep(10000);    

    ErrorItems ACErrors = dte.ToolWindows.ErrorList.ErrorItems;
    ErrorItem ACErrorsItems;
    int j = 1;
    do
    {
        System.Threading.Thread.Sleep(5000);
        ACErrorsItems = ACErrors.Item(j);
        j++;
        if (ACErrorsItems.ErrorLevel != vsBuildErrorLevel.vsBuildErrorLevelLow)
        {
            Console.WriteLine("Description: " + ACErrorsItems.Description);
        }
    } while (!ACErrorsItems.Description.Contains("| 'PlcTask' (350): | ================"));    

独立于 VS ErrorList,另一种访问输出的方式window,e。 G。获取构建信息:

// access output window in VS
EnvDTE.OutputWindow outWin = ((DTE2)dte).ToolWindows.OutputWindow;
try
{
    // get specific output window of the collection
    EnvDTE.OutputWindowPane Buildpane = outWin.OutputWindowPanes.Item("Build");
    // get text document of the selected pane
    EnvDTE.TextDocument BuildtextDoc = Buildpane.TextDocument;
    // select all text in the output window
    EnvDTE.EditPoint BuildeditPoint = BuildtextDoc.StartPoint.CreateEditPoint();
    string Buildtext = BuildeditPoint.GetText(BuildtextDoc.EndPoint);
    Console.WriteLine(Buildtext);
}
catch (Exception e)
{
    MessageBox.Show(e.Message);
}