使用mrsargent
的指导更新非常有用的信息
我试图在c# (Visual Studio)中自动执行以下步骤:
- 运行并连接TIA门户
- 创建项目
- 安装GSDML设备文件
- 按GSDML 添加PLC和单个设备
- 产品与PLC (cpu)的设计应用关系
我试图使用相同的开放演示应用程序,但我无法通过代码步进,并且在演示GUI中没有选项来安装GSDML文件。
我试图按照文档为GSDML文件的CAX导入编写以下代码,但遇到如下所述的错误:
代码:
using
(TiaPortal tiaPortal = new TiaPortal(TiaPortalMode.WithoutUserInterface))
{
Console.WriteLine("TIA Portal has started");
ProjectComposition projects = tiaPortal.Projects;
Console.WriteLine("Opening Project...");
DirectoryInfo dinfo = new DirectoryInfo(@"C:projectsTestProjects");
string unixTimestamp = Convert.ToString((int)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
string prj_name = "Prj_" + unixTimestamp;
Project project = null;
try
{
project = projects.Create(dinfo, prj_name);
}
catch (Exception)
{
Console.WriteLine(String.Format("Could not open project {0}", projectPath.FullName));
Console.WriteLine("Demo complete hit enter to exit");
Console.ReadLine();
return;
}
CaxProvider caxProvider = project.GetService<CaxProvider>();
if (caxProvider != null)
{
// GETTING ERROR OVER HERE
// {"Error when calling method 'Import' of type 'Siemens.Engineering.Cax.CaxProvider'.rnrnThe path of the import file 'C:\Gaurav\GSDML-xxxxxxxx.xml' with the extension '.xml' is invalid.rn"}
caxProvider.Import(
new FileInfo(@"C:GSDML-xxxx.xml"),
new FileInfo(@"C:ProjectImport_Log.log"),
CaxImportOptions.MoveToParkingLot
);
}
Console.WriteLine(String.Format("Project {0} is open", project.Path.FullName));
// IterateThroughDevices(project);
project.Close();
Console.WriteLine("Demo complete hit enter to exit");
Console.ReadLine();
}
观察到以下错误:
{"Error when calling method 'Import' of type 'Siemens.Engineering.Cax.CaxProvider'.rnrnThe path of the import file 'C:GSDML-xxx.xml' with the extension '.xml' is invalid.rn"}
是的,这是一件很难做到的事情。然而,这是可能的。首先,您需要适当的文档,这有点难以找到。手册非常详细,可以在这里找到
您需要导入GSD文件作为文档第939页的CAx。
//Access the CaxProvider service
Project project = tiaPortal.Projects.Open(...);
CaxProvider caxProvider = project.GetService<CaxProvider>();
if(caxProvider != null)
{
// Perform Cax export and import operation
}
要创建这个CAx (xml文档),您需要从本手册的第988页开始查看。它将告诉您如何配置。在这个论坛里解释和列出太多了,但是在你读了5遍之后,文档做了很好的解释;)
最好阅读整个导入/导出部分,以便全面了解如何执行此操作。希望这对你有帮助!