1

I have a Beckhoff PLC that's running a software developed with TwinCat3. Is there a way to retrieve the running software using C# application ? The TwinCAT.Ads library does not seem to offer such functionality.

The plan is to be able to compare what is online with a backup stored locally to detect any unplanned code changes made by Service Technician.

It would be enough for me if I could for example retrieve a hash code from the PLC and generate hash from a local backup and see if they match.

Is there perhaps a better way to detect such changes ?

I am new to Beckhoff PLC / TwinCat3 so all information regarding this matter is much appreciated.

EDIT: I should add that the C# application will automate the process of checking for unplanned code changes and only flag it so that an engineer can approve or reject the changes.

skari
  • 45
  • 1
  • 8

2 Answers2

3

TwinCAT 3 contains a data type of PlcAppSystemInfo, which contains some information of the PLC project as well as the system. See this link. The data can be found from a global variable _AppInfo

Image of _AppInfo

The AppTimestamp is DT (DATE_AND_TIME) of the time when application software was last changed. From Beckhoff documentation I would get a feeling that it would reset after each reboot ("Time at the start of the PLC application") but when I tested it kept the same when rebooting and powering off. When I updated the PLC application, the date changed with both online change and download.

So, as far as I know, you can read the date and time when the application was last updated and compare if it changes. You didn't say if you already know how to use c# to read variables, I suppose you know how to use ReadAny so just read the value fom variable _AppInfo.AppTimeStamp.

Quirzo
  • 1,183
  • 8
  • 10
  • Thank you, this looks promising :) – skari Sep 04 '18 at 11:00
  • 1
    Glad to hear! The `KeepOutputsOnBP` is a great variable by the way. When it's set TRUE, you can stop the program with breakpoints and all outputs will keep their state. Normally all outputs will set to 0, so motors etc. will shut down. – Quirzo Jan 09 '19 at 06:09
  • 1
    I am floored at how few mentions of KeepOutputsOnBP are to be found online. Structured text debugging without this set to TRUE is a nightmare. There must be a reason this is not the default behaviour? No one in their right mind would cause a general-purpose IDE to force all files and network connections to close when stepping into the code. Why would you want to essentially turn off your machine while trying to debug it? Beats me. – Fred May 20 '23 at 00:33
1

The first thing that comes in my mind is the TwinCAT automation interface. It's basically an API that allows you to access certain parts of what you normally do in Visual Studio/TwinCAT. The TwinCAT automation interface libraries are installed together with your TwinCAT installation, and there are several ways to access these. The documentation and examples for the API is mostly in C#/.NET.

See the documentation here: http://download.beckhoff.com/download/document/automation/twincat3/AutomationInterface_pdf_EN.pdf

More specifically for your case I think this would be interesting: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_automationinterface/2488994571.html&id=155511204171430517

With this you could do a comparison of the local project (which you would also open through the automation interface).

Jakob
  • 1,288
  • 7
  • 13
  • Thank you, this might be useful for me. I will mark the answer as accepted if I go for this :) – skari Aug 23 '18 at 13:16