简体   繁体   English

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

[英]TwinCAT3 - Automation Interface - Display O/P on Jenkins console

  1. Using Automation Interface I could able to build and initiate Activate Configuration in TwinCAT 3.1.4024.4.使用自动化接口,我可以在 TwinCAT 3.1.4024.4 中构建和启动激活配置。
  2. If same project under normal run and Activate Configuration, Messages and errors are displayed in the output console of VS2013.如果同一个项目在正常运行和Activate Configuration下,VS2013的输出控制台会显示Messages和errors。
  3. In Automation Interface, Using ErrorItems errors = dte.ToolWindows.ErrorList.ErrorItems;在自动化界面中,使用ErrorItems errors = dte.ToolWindows.ErrorList.ErrorItems; I could only read and display message 1 to 10.我只能读取和显示消息 1 到 10。
  4. Other Messages has different format TwinCAT System (10000) or PlcTask (350 ):其他消息具有不同的格式TwinCAT System (10000) or PlcTask (350 ):
  5. Is this will not be captured by dte.ToolWindows.ErrorList.ErrorItems;这会不会被dte.ToolWindows.ErrorList.ErrorItems;捕获dte.ToolWindows.ErrorList.ErrorItems; ? ?
  6. In the output console of VS2013 there are two options: Show output from build and Show output from twinCAT .在 VS2013 的输出控制台中有两个选项: Show output from build and Show output from twinCAT
  7. In Automation Interface,I think, i could only read messages from build and no Messages from TwinCAT在自动化接口中,我认为我只能从构建中读取消息,而不能从 TwinCAT 中读取消息
  8. Is there any way to read TwinCAT messages Also?还有什么方法可以读取 TwinCAT 消息吗?

VS2013 console output: 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): | ======================================  

Output on the Jenkins Console: [Could read only first 10 messages] 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# Code: 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);
    }

Please look in to screenshots of the outputs: Build&TwinCAToutput请查看输出的屏幕截图: Build&TwinCAToutput

I see that you are using TcUnit .我看到您正在使用TcUnit The problem is that you're not waiting for TcUnit to finish before you are collecting your ErrorItems.问题是在收集 ErrorItems 之前,您没有等待 TcUnit 完成。 You are only collecting the error items after doing the ActivateConfiguration() and StartRestartTwincat() (that's why you only get the first 10).您只在执行 ActivateConfiguration() 和 StartRestartTwincat() 之后收集错误项(这就是为什么您只得到前 10 个)。 You need to wait for TcUnit to finish.您需要等待 TcUnit 完成。

Wrap the running of TcUnit in a while-loop, and ask TcUnit for the results.将 TcUnit 的运行包装在一个 while 循环中,并向 TcUnit 询问结果。 Once all results are returned (which is done when you have all prints done), you can then use your ErrorItems.返回所有结果后(完成所有打印后完成),您就可以使用 ErrorItems。 So basically, collect the ErrorItems in a while-true loop (but make sure to use a sleep every second or so), and once you have all the results from TcUnit (in other words, the lines ==========TESTS FINISHED RUNNING========== and everything that follows), you can print all error items (or parse them, or do whatever you want with them).所以基本上,在一个 while-true 循环中收集 ErrorItems(但确保每隔一秒左右使用一次睡眠),一旦你从 TcUnit 获得所有结果(换句话说,行 ======== ==TESTS FINISHED RUNNING========== 以及接下来的所有内容),您可以打印所有错误项目(或解析它们,或对它们进行任何您想做的事情)。

Good luck!祝你好运!

Thank you @Jakob谢谢@Jakob
Your suggestion helped to solve this issue.您的建议有助于解决此问题。
After restart, 10 seconds of wait and after each read, 5 seconds of sleep.重新启动后,等待 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): | ================"));    

Independent of the VS ErrorList, another way to access the output window, eg to catch the build information:独立于 VS ErrorList,另一种访问输出窗口的方法,例如捕获构建信息:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM