Detect code changes on Beckhoff PLC using C#

拈花ヽ惹草 提交于 2019-12-08 07:53:29

问题


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.


回答1:


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

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.




回答2:


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).



来源:https://stackoverflow.com/questions/51981879/detect-code-changes-on-beckhoff-plc-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!