Join us today!

Notifications
Clear all

TwinCAT automation interface

2 Posts
2 Users
0 Reactions
507 Views
Posts: 1
Topic starter
(@bavodenys)
New Member
Joined: 10 months ago

Hi

I designed a pipeline to update modules in an existing TwinCAT project. In a last step I want to build the solution, so I can create a package that can be copied to PLC target later. Currently I'm using the TwinCAT automation interface to build my solution (see below). But this interface seems to be slow, not reliable... Are there other possibilities to build a TwinCAT solution? Are there TwinCAT pipeline integrations available or coming soon? 

using EnvDTE;
using EnvDTE80;
using TCatSysManagerLib;
using NDesk.Options;
using System;
using System.IO;


namespace BuildPLCProject
{
internal class Program
{
static void Main(string[] args)
{
string solutionFilePath = "";
string buildPlatform = "";
bool showHelp_b = false;
bool continue_b = true;

// Parse options
OptionSet options = new OptionSet()
.Add("h|?|help", delegate (string v) { showHelp_b = v != null; })
.Add("s|solutionFilePath=", delegate (string v) { solutionFilePath = v; })
.Add("b|buildPlatform=", delegate (string v) { buildPlatform = v; });

// Try to parse the input arguments
try
{
options.Parse(args);
}
catch (OptionException e)
{
Console.WriteLine(e.Message);
Environment.Exit(0);
}

// Show help
if (showHelp_b)
{
showhelp(options);
}

// Check if solution exists
if (!File.Exists(solutionFilePath))
{
Console.WriteLine(solutionFilePath);
Console.WriteLine("Solution file path does not exist!");
Environment.Exit(1);
}

Console.WriteLine("Open COM communication");
// Setup automation (COM) connection with TcXaeShell
Type t = System.Type.GetTypeFromProgID("TcXaeShell.DTE.15.0");
EnvDTE.DTE dte = (EnvDTE.DTE)System.Activator.CreateInstance(t);
// To set TcXhaeShell invisible
dte.SuppressUI = true;
dte.MainWindow.Visible = false;

Console.WriteLine("Open solution");
EnvDTE.Solution sol = dte.Solution;
sol.Open(solutionFilePath);

Console.WriteLine("Set build platform");
EnvDTE.Project pro = sol.Projects.Item(1);
ITcSysManager15 systemManager = (ITcSysManager15)pro.Object;
ITcSysManager7 sysManPlatform = (ITcSysManager7)systemManager;
ITcConfigManager configManager = (ITcConfigManager)sysManPlatform.ConfigurationManager;
configManager.ActiveTargetPlatform = buildPlatform;

Console.WriteLine("Build solution");
sol.SolutionBuild.Build(true);

Console.WriteLine("Finish!!");
Environment.Exit(0);
}

static void showhelp(OptionSet p)
{
Console.WriteLine("Usage: BuildPLCSolution [OPTIONS]");
p.WriteOptionDescriptions(Console.Out);
Environment.Exit(0);
}
}

}
Reply
Topic Tags
1 Reply
Posts: 1
(@wampahoofus)
New Member
Joined: 3 months ago

I realize this question is a bit old, but I wanted to point out two things:

 

1.  Automation interface can be slow.  It's just visual studio doing its thing in a scripted fashion.

 

2.  If you're not using a COM message filter in your automation interface application, you will have reliability problems.  A proper message filter is necessary.  See the TwinCAT Automation Interface documentation for details.

 

 

Reply
Share: