将版本控制软件 (Git) 与 CoDeSys 2.3 PLC 项目结合使用

问题描述 投票:0回答:1

我希望将 Git 与 CoDeSys 2.3 PLC 项目结合使用。默认情况下,项目存储在一个大的二进制文件中。 Git 可以检测到对此文件进行了更改,但它无法查看文件以了解更改的内容。

我正在寻找一种解决方案,将代码存储在 Git 可以读取的文本文件或 XML 文件中,从而能够显示更改。如果该解决方案需要最少数量的手动干预才能发挥作用,那将是有益的。

在我的研究中,我发现可以使用菜单中的导出功能(项目 -> 导出...)将源代码导出为纯文本。还有一个导入功能,可以将源代码拉回到 PLC 项目中。

我认为这两个工具具有我正在寻找的功能,但我想找到一种方法使该过程更加自动化。理想情况下,这将是一个在保存项目后或调用 git-status 时作为构建过程的一部分自动调用的脚本。

git plc codesys
1个回答
0
投票

我在这里找到了我自己问题的部分答案:https://forge.codesys.com/forge/talk/CODESYS-V2/thread/d1685e2948/

CoDeSys 2.3 支持从命令文件运行命令列表。在命令行中调用时,此文件作为参数传递给程序。

将PLC代码导出到指定位置的powershell脚本:

#This PowerShell script opens CoDeSys 2.3 (without GUI) and asks it to export the source code plain text into a specified location. 

#Path to the CoDeSys 2.3 .exe
$EXE_PATH = 'C:\Program Files (x86)\ifm electronic\CoDeSys V2.3\Codesys.exe'

#Path to the CoDeSys PLC project file (.pro) relative or absolute
$PROG_PATH = '.\PLC PROGRAM.pro'

#Path to export folder relative or absolute.
$OUT_PATH = '.\SOURCECODE EXPORT'

#Let the user know what is happening and give them a chance to abort
Write-Output "Removing exisiting files from and exporting CoDeSys Files to: $OUT_PATH"
pause

#Check the program exists
if (-NOT(Test-Path "$PROG_PATH"))
{
    Write-Output "Specified program file doesn't exist"
    pause
    exit
}
#Remove exisiting export files
if (Test-Path "$OUT_PATH")
{
    Remove-Item ".\$OUT_PATH\*.EXP"
}

#Create a .txt file with the commands for CoDeSys.
Write-Output "Creating command file..."
Out-File -FilePath .\CoDeSys_CMD.txt -InputObject "project expmul `"$OUT_PATH`"" -Encoding ASCII

#open CoDeSys 2.3 project as specified. Passes command file to the opening program. /batch causes codesys to open without GUI. Swap with /cmd for GUI. 
Write-Output "Exporting files..."
start-process -Wait -FilePath $EXE_PATH -ArgumentList "`"$PROG_PATH`"" ,"/batch `".\CoDeSys_CMD.txt`""

#Remove command file once finished.
Write-Output "Removing command file..."
Remove-Item CoDeSys_CMD.txt
Write-Output "Done."

我不确定导出文件是否完整描述了该项目。 .pro 文件中可能保留有重要数据。因此,.pro 文件也将保留在 git 存储库中。鉴于此,我决定不自动化导入功能,因为它只是偶尔需要。

© www.soinside.com 2019 - 2024. All rights reserved.