I'm trying to control my Beckhoff device by means of Python Pyads wrapper.
If TwinCAT is in Config mode on my target device, is it possible to start it with a Python command?
I'm trying to control my Beckhoff device by means of Python Pyads wrapper.
If TwinCAT is in Config mode on my target device, is it possible to start it with a Python command?
I don't think this is possible from pyads. It is possible to do it with the TwinCAT automation interface. See example code from InfoSys:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE100;
using System.IO;
using TCatSysManagerLib;
namespace ActivatePreviousConfiguration
{
class Program
{
static void Main(string[] args)
{
Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
EnvDTE.DTE dte = (EnvDTE.DTE)System.Activator.CreateInstance(t);
dte.SuppressUI = false;
dte.MainWindow.Visible = true;
EnvDTE.Solution sol = dte.Solution;
sol.Open(@"C:\Temp\SolutionFolder\MySolution1\MySolution1.sln");
EnvDTE.Project pro = sol.Projects.Item(1);
ITcSysManager sysMan = pro.Object;
sysMan.ActivateConfiguration();
sysMan.StartRestartTwinCAT();
}
}
}
Then you could use PythonNET to call this program from Python.
This should be possible using the method write_control
in the connection class. And sending the device state ADSSTATE_RUN
.
The example in C is here: https://infosys.beckhoff.com/content/1033/tc3_adsdll2/124821771.html?id=4386625485690101318
But this should translate to pyads as it's just a wrapper around the C DLL.