├── .github ├── FUNDING.yml └── workflows │ └── dotnet-core.yml ├── .gitignore ├── LICENSE ├── README.md ├── Tests └── PlcProject │ ├── .gitignore │ ├── TwinCATDummy.sln │ └── TwinCATDummy │ ├── MainPLC │ ├── DUTs │ │ ├── User1DUT.TcDUT │ │ ├── User2DUT.TcDUT │ │ ├── UserInnerInnerDUT.TcDUT │ │ └── UserInnerInnerDUTPersistent.TcDUT │ ├── GVLs │ │ └── GVL.TcGVL │ ├── MainPLC.plcproj │ ├── MainPLC.tmc │ ├── POUs │ │ ├── MAIN.TcPOU │ │ ├── TestFB1.TcPOU │ │ ├── TestFB1Device.TcPOU │ │ └── TestFB1DeviceSubdevice.TcPOU │ └── PlcTask.TcTTO │ └── TwinCATDummy.tsproj ├── TwinCatAdsTool.Gui ├── App.xaml ├── App.xaml.cs ├── Commands │ └── ReactiveRelayCommand.cs ├── Converters │ ├── BoolToVisibilityConverter.cs │ ├── ConnectionStateToBoolConverter.cs │ ├── ConnectionStateToIconConverter.cs │ ├── ConnectionStateToVisibilityConverter.cs │ ├── DtToDateTimeConverter.cs │ ├── LTimeToTimeSpanConverter.cs │ └── TimeToTimeSpanConverter.cs ├── Extensions │ ├── ReactiveUiExtensions.cs │ ├── TreeViewModelExtension.cs │ └── VariableViewModelExtension.cs ├── GuiModuleCatalog.cs ├── Properties │ ├── Resources.Designer.cs │ ├── Resources.de.resx │ └── Resources.resx ├── Resources │ ├── evopro.png │ └── twincat.png ├── TwinCatAdsTool.Gui.csproj ├── ViewModelLocator.cs ├── ViewModels │ ├── BackupViewModel.cs │ ├── CompareViewModel.cs │ ├── ConnectionCabViewModel.cs │ ├── ExploreViewModel.cs │ ├── GraphViewModel.cs │ ├── MainWindowViewModel.cs │ ├── ObserverViewModel.cs │ ├── RestoreViewModel.cs │ ├── SearchResult.cs │ ├── SymbolObservationViewModel.cs │ ├── TabsViewModel.cs │ ├── TreeViewModel.cs │ ├── VariableViewModel.cs │ └── ViewModelBase.cs └── Views │ ├── BackupView.xaml │ ├── BackupView.xaml.cs │ ├── CompareView.xaml │ ├── CompareView.xaml.cs │ ├── ConnectionCabView.xaml │ ├── ConnectionCabView.xaml.cs │ ├── ExploreView.xaml │ ├── ExploreView.xaml.cs │ ├── GraphView.xaml │ ├── GraphView.xaml.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── RestoreView.xaml │ ├── RestoreView.xaml.cs │ ├── SymbolObservationTemplateSelector.cs │ ├── TabsView.xaml │ └── TabsView.xaml.cs ├── TwinCatAdsTool.Interfaces ├── Commons │ ├── IInitializable.cs │ ├── IInstanceCreator.cs │ └── IViewModelFactory.cs ├── Constants.cs ├── Extensions │ └── DisposableExtensions.cs ├── Logging │ └── LoggerFactory.cs ├── Models │ └── NetId.cs ├── Services │ ├── IClientService.cs │ ├── IPersistentVariableService.cs │ └── ISelectionService.cs └── TwinCatAdsTool.Interfaces.csproj ├── TwinCatAdsTool.Logic ├── LogicModuleCatalog.cs ├── Properties │ ├── Resources.Designer.cs │ ├── Resources.de.resx │ └── Resources.resx ├── Router │ ├── RemotePlcInfo.cs │ ├── Request.cs │ ├── Response.cs │ ├── ResponseResult.cs │ └── Segment.cs ├── Services │ ├── ClientService.cs │ ├── DeviceFinder.cs │ ├── IPHelper.cs │ ├── PersistentVariableService.cs │ └── SymbolSelectionService.cs └── TwinCatAdsTool.Logic.csproj ├── TwinCatAdsTool.sln ├── TwinCatAdsTool ├── Program.cs ├── TwinCatAdsTool.csproj ├── log.config └── twincat.ico └── docs └── images ├── evopro.png ├── screenshot1.png ├── screenshot2.png └── twincat.png /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: fbarresi 4 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-core.yml: -------------------------------------------------------------------------------- 1 | name: .NET Core Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - develop 7 | - 'features/**' 8 | pull_request: 9 | branches: [ master, develop ] 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: windows-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Setup .NET Core 19 | uses: actions/setup-dotnet@v1 20 | with: 21 | dotnet-version: 5.0.x 22 | - name: Install dependencies 23 | run: dotnet restore 24 | - name: Build 25 | run: dotnet build --configuration Release --no-restore 26 | - name: Test 27 | run: dotnet test --no-restore --verbosity normal 28 | - name: Publish 29 | run: dotnet publish TwinCatAdsTool\TwinCatAdsTool.csproj -c Release /p:AssemblyVersion=1.2.${{ github.run_number }} /p:FileVersion=1.2.${{ github.run_number }} -o out 30 | - name: Compress 31 | run: Compress-Archive out\TwinCatAdsTool.exe TwinCatAdsTool_v1.2.${{ github.run_number }}.zip 32 | - name: Publish ReadyToRun 33 | run: dotnet publish TwinCatAdsTool\TwinCatAdsTool.csproj -c Release /p:AssemblyVersion=1.2.${{ github.run_number }} /p:FileVersion=1.2.${{ github.run_number }} /p:SelfContained=true /p:PublishReadyToRun=true -o out 34 | - name: Compress ReadyToRun 35 | run: Compress-Archive out\TwinCatAdsTool.exe TwinCatAdsTool_ReadyToRun_v1.2.${{ github.run_number }}.zip 36 | - name: Create Release 37 | id: create_release 38 | uses: actions/create-release@v1 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | with: 42 | tag_name: 1.2.${{ github.run_number }} 43 | release_name: 1.2.${{ github.run_number }} 44 | draft: false 45 | prerelease: true 46 | - name: Upload 47 | id: upload-release-asset 48 | uses: actions/upload-release-asset@v1 49 | env: 50 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 51 | with: 52 | upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps 53 | asset_path: TwinCatAdsTool_v1.2.${{ github.run_number }}.zip 54 | asset_name: TwinCatAdsTool_v1.2.${{ github.run_number }}.zip 55 | asset_content_type: application/zip 56 | - name: Upload ReadyToRun 57 | id: upload-release-asset2 58 | uses: actions/upload-release-asset@v1 59 | env: 60 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 61 | with: 62 | upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps 63 | asset_path: TwinCatAdsTool_ReadyToRun_v1.2.${{ github.run_number }}.zip 64 | asset_name: TwinCatAdsTool_ReadyToRun_v1.2.${{ github.run_number }}.zip 65 | asset_content_type: application/zip 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Federico Barresi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TwinCatAdsTool 2 | 3 | [![.NET Core Build](https://github.com/fbarresi/TwinCatAdsTool/actions/workflows/dotnet-core.yml/badge.svg?branch=develop)](https://github.com/fbarresi/TwinCatAdsTool/actions/workflows/dotnet-core.yml) 4 | The TwinCAT Tool you ever wanted and your lite alternative to visual studio 5 | 6 | ### [Download it now](https://github.com/fbarresi/TwinCatAdsTool/releases/latest) 7 | 8 | ## Features 9 | 10 | - View, save and restore a Backup of all persistent variable 11 | - Compare different backup 12 | - Search, explore or observe the symbols of a plc 13 | 14 | 15 | 16 | ## Requirements 17 | 18 | This software requires Twincat ADS installed. 19 | 20 | In order to get connected with a PLC you also need to setup a route. 21 | 22 | Get more information [here](https://infosys.beckhoff.com/) or [download ADS](https://www.beckhoff.de/english.asp?forms/twincat3/warenkorb2.aspx?id=1890306418903071160&lg=en&title=TC31-ADS-Setup.3.1.4024.4&version=3.1.4024.4). 23 | 24 | ## Credits 25 | 26 | This software was sponsored by 27 | 28 | 29 | 30 | and was realized with [Twincat.JsonExtension](https://github.com/fbarresi/TwinCAT.JsonExtension) 31 | -------------------------------------------------------------------------------- /Tests/PlcProject/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | [Rr]eleases/ 14 | x64/ 15 | build/ 16 | bld/ 17 | [Bb]in/ 18 | [Oo]bj/ 19 | 20 | # Roslyn cache directories 21 | *.ide/ 22 | 23 | # MSTest test Results 24 | [Tt]est[Rr]esult*/ 25 | [Bb]uild[Ll]og.* 26 | 27 | #NUNIT 28 | *.VisualState.xml 29 | TestResult.xml 30 | 31 | # Build Results of an ATL Project 32 | [Dd]ebugPS/ 33 | [Rr]eleasePS/ 34 | dlldata.c 35 | 36 | *_i.c 37 | *_p.c 38 | *_i.h 39 | *.ilk 40 | *.meta 41 | *.obj 42 | *.pch 43 | *.pdb 44 | *.pgc 45 | *.pgd 46 | *.rsp 47 | *.sbr 48 | *.tlb 49 | *.tli 50 | *.tlh 51 | *.tmp 52 | *.tmp_proj 53 | *.log 54 | *.vspscc 55 | *.vssscc 56 | .builds 57 | *.pidb 58 | *.svclog 59 | *.scc 60 | 61 | # Chutzpah Test files 62 | _Chutzpah* 63 | 64 | # Visual C++ cache files 65 | ipch/ 66 | *.aps 67 | *.ncb 68 | *.opensdf 69 | *.sdf 70 | *.cachefile 71 | 72 | # Visual Studio profiler 73 | *.psess 74 | *.vsp 75 | *.vspx 76 | 77 | # TFS 2012 Local Workspace 78 | $tf/ 79 | 80 | # Guidance Automation Toolkit 81 | *.gpState 82 | 83 | # ReSharper is a .NET coding add-in 84 | _ReSharper*/ 85 | *.[Rr]e[Ss]harper 86 | *.DotSettings.user 87 | 88 | # JustCode is a .NET coding addin-in 89 | .JustCode 90 | 91 | # TeamCity is a build add-in 92 | _TeamCity* 93 | 94 | # DotCover is a Code Coverage Tool 95 | *.dotCover 96 | 97 | # NCrunch 98 | _NCrunch_* 99 | .*crunch*.local.xml 100 | 101 | # MightyMoose 102 | *.mm.* 103 | AutoTest.Net/ 104 | 105 | # Web workbench (sass) 106 | .sass-cache/ 107 | 108 | # Installshield output folder 109 | [Ee]xpress/ 110 | 111 | # DocProject is a documentation generator add-in 112 | DocProject/buildhelp/ 113 | DocProject/Help/*.HxT 114 | DocProject/Help/*.HxC 115 | DocProject/Help/*.hhc 116 | DocProject/Help/*.hhk 117 | DocProject/Help/*.hhp 118 | DocProject/Help/Html2 119 | DocProject/Help/html 120 | 121 | # Click-Once directory 122 | publish/ 123 | 124 | # Publish Web Output 125 | *.[Pp]ublish.xml 126 | *.azurePubxml 127 | ## TODO: Comment the next line if you want to checkin your 128 | ## web deploy settings but do note that will include unencrypted 129 | ## passwords 130 | *.pubxml 131 | 132 | # NuGet Packages 133 | packages/* 134 | *.nupkg 135 | ## TODO: If the tool you use requires repositories.config 136 | ## uncomment the next line 137 | #!packages/repositories.config 138 | 139 | # Enable "build/" folder in the NuGet Packages folder since 140 | # NuGet packages use it for MSBuild targets. 141 | # This line needs to be after the ignore of the build folder 142 | # (and the packages folder if the line above has been uncommented) 143 | !packages/build/ 144 | 145 | # Windows Azure Build Output 146 | csx/ 147 | *.build.csdef 148 | 149 | # Windows Store app package directory 150 | AppPackages/ 151 | 152 | # Others 153 | sql/ 154 | *.Cache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | 165 | # RIA/Silverlight projects 166 | Generated_Code/ 167 | 168 | # Backup & report files from converting an old project file 169 | # to a newer Visual Studio version. Backup files are not needed, 170 | # because we have git ;-) 171 | _UpgradeReport_Files/ 172 | Backup*/ 173 | UpgradeLog*.XML 174 | UpgradeLog*.htm 175 | 176 | # SQL Server files 177 | *.mdf 178 | *.ldf 179 | 180 | # Business Intelligence projects 181 | *.rdl.data 182 | *.bim.layout 183 | *.bim_*.settings 184 | 185 | # Microsoft Fakes 186 | FakesAssemblies/ 187 | *.~u 188 | 189 | 190 | *.compileinfo 191 | *.bak 192 | /*.~u 193 | _Boot 194 | _Boot 195 | _Libraries/ 196 | _Deployment 197 | _CompileInfo 198 | TrialLicense.tclrs 199 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # TcXaeShell Solution File, Format Version 11.00 4 | VisualStudioVersion = 15.0.28010.2050 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{B1E792BE-AA5F-4E3C-8C82-674BF9C0715B}") = "TwinCATDummy", "TwinCATDummy\TwinCATDummy.tsproj", "{FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|TwinCAT CE7 (ARMV7) = Debug|TwinCAT CE7 (ARMV7) 11 | Debug|TwinCAT OS (ARMT2) = Debug|TwinCAT OS (ARMT2) 12 | Debug|TwinCAT RT (x64) = Debug|TwinCAT RT (x64) 13 | Debug|TwinCAT RT (x86) = Debug|TwinCAT RT (x86) 14 | Release|TwinCAT CE7 (ARMV7) = Release|TwinCAT CE7 (ARMV7) 15 | Release|TwinCAT OS (ARMT2) = Release|TwinCAT OS (ARMT2) 16 | Release|TwinCAT RT (x64) = Release|TwinCAT RT (x64) 17 | Release|TwinCAT RT (x86) = Release|TwinCAT RT (x86) 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7) 21 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7) 22 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2) 23 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2) 24 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64) 25 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64) 26 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86) 27 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86) 28 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7) 29 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7) 30 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2) 31 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2) 32 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64) 33 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64) 34 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86) 35 | {FB210DFE-7BE8-49D7-9CA5-CC0A1090C72A}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86) 36 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7) 37 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7) 38 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2) 39 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2) 40 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64) 41 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64) 42 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86) 43 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86) 44 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7) 45 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7) 46 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2) 47 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2) 48 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64) 49 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64) 50 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86) 51 | {43BCB400-F6AB-43C5-93E9-C1BEACBEAAB3}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86) 52 | EndGlobalSection 53 | GlobalSection(SolutionProperties) = preSolution 54 | HideSolutionNode = FALSE 55 | EndGlobalSection 56 | GlobalSection(ExtensibilityGlobals) = postSolution 57 | SolutionGuid = {7C065B52-19E4-4DF6-B90F-5A1EE58F24AD} 58 | EndGlobalSection 59 | EndGlobal 60 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/DUTs/User1DUT.TcDUT: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/DUTs/User2DUT.TcDUT: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/DUTs/UserInnerInnerDUT.TcDUT: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/DUTs/UserInnerInnerDUTPersistent.TcDUT: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/GVLs/GVL.TcGVL: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 24 | 25 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/MainPLC.plcproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.0.0.0 4 | 2.0 5 | {43bcb400-f6ab-43c5-93e9-c1beacbeaab3} 6 | True 7 | true 8 | true 9 | false 10 | MainPLC 11 | 3.1.4024.12 12 | {4af4fc67-911e-4f54-8bd3-fd4cb53b58b3} 13 | {1e02c0a7-0807-47ec-8ba4-43533fedec80} 14 | {401fc747-d8bd-4bd3-a7ee-fd560a5a6775} 15 | {0ea0a5f1-6c83-49f2-bd31-5072ac08cd4e} 16 | {cebca137-69c6-4c29-aa65-6407f9c6dac5} 17 | {9b04bfe7-a898-4f26-8044-e06a9388721b} 18 | 19 | 20 | 21 | Code 22 | 23 | 24 | Code 25 | 26 | 27 | Code 28 | 29 | 30 | Code 31 | 32 | 33 | Code 34 | true 35 | 36 | 37 | Code 38 | 39 | 40 | Code 41 | 42 | 43 | Code 44 | 45 | 46 | Code 47 | 48 | 49 | Code 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | Tc2_Standard, * (Beckhoff Automation GmbH) 61 | Tc2_Standard 62 | 63 | 64 | Tc2_System, * (Beckhoff Automation GmbH) 65 | Tc2_System 66 | 67 | 68 | Tc2_Utilities, * (Beckhoff Automation GmbH) 69 | Tc2_Utilities 70 | 71 | 72 | Tc3_Module, * (Beckhoff Automation GmbH) 73 | Tc3_Module 74 | 75 | 76 | 77 | 78 | Content 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | "<ProjectRoot>" 87 | 88 | {40450F57-0AA3-4216-96F3-5444ECB29763} 89 | 90 | "{40450F57-0AA3-4216-96F3-5444ECB29763}" 91 | 92 | 93 | ActiveVisuProfile 94 | IR0whWr8bwfwBwAAiD2qpQAAAABVAgAA37x72QAAAAABAAAAAAAAAAEaUwB5AHMAdABlAG0ALgBTAHQAcgBpAG4AZwACTHsAZgA5ADUAYgBiADQAMgA2AC0ANQA1ADIANAAtADQAYgA0ADUALQA5ADQAMAAwAC0AZgBiADAAZgAyAGUANwA3AGUANQAxAGIAfQADCE4AYQBtAGUABDBUAHcAaQBuAEMAQQBUACAAMwAuADEAIABCAHUAaQBsAGQAIAA0ADAAMgA0AC4ANwAFFlAAcgBvAGYAaQBsAGUARABhAHQAYQAGTHsAMQA2AGUANQA1AGIANgAwAC0ANwAwADQAMwAtADQAYQA2ADMALQBiADYANQBiAC0ANgAxADQANwAxADMAOAA3ADgAZAA0ADIAfQAHEkwAaQBiAHIAYQByAGkAZQBzAAhMewAzAGIAZgBkADUANAA1ADkALQBiADAANwBmAC0ANABkADYAZQAtAGEAZQAxAGEALQBhADgAMwAzADUANgBhADUANQAxADQAMgB9AAlMewA5AGMAOQA1ADgAOQA2ADgALQAyAGMAOAA1AC0ANAAxAGIAYgAtADgAOAA3ADEALQA4ADkANQBmAGYAMQBmAGUAZABlADEAYQB9AAoOVgBlAHIAcwBpAG8AbgALBmkAbgB0AAwKVQBzAGEAZwBlAA0KVABpAHQAbABlAA4aVgBpAHMAdQBFAGwAZQBtAE0AZQB0AGUAcgAPDkMAbwBtAHAAYQBuAHkAEAxTAHkAcwB0AGUAbQARElYAaQBzAHUARQBsAGUAbQBzABIwVgBpAHMAdQBFAGwAZQBtAHMAUwBwAGUAYwBpAGEAbABDAG8AbgB0AHIAbwBsAHMAEyhWAGkAcwB1AEUAbABlAG0AcwBXAGkAbgBDAG8AbgB0AHIAbwBsAHMAFCRWAGkAcwB1AEUAbABlAG0AVABlAHgAdABFAGQAaQB0AG8AcgAVIlYAaQBzAHUATgBhAHQAaQB2AGUAQwBvAG4AdAByAG8AbAAWFHYAaQBzAHUAaQBuAHAAdQB0AHMAFwxzAHkAcwB0AGUAbQAYGFYAaQBzAHUARQBsAGUAbQBCAGEAcwBlABkmRABlAHYAUABsAGEAYwBlAGgAbwBsAGQAZQByAHMAVQBzAGUAZAAaCGIAbwBvAGwAGyJQAGwAdQBnAGkAbgBDAG8AbgBzAHQAcgBhAGkAbgB0AHMAHEx7ADQAMwBkADUAMgBiAGMAZQAtADkANAAyAGMALQA0ADQAZAA3AC0AOQBlADkANAAtADEAYgBmAGQAZgAzADEAMABlADYAMwBjAH0AHRxBAHQATABlAGEAcwB0AFYAZQByAHMAaQBvAG4AHhRQAGwAdQBnAGkAbgBHAHUAaQBkAB8WUwB5AHMAdABlAG0ALgBHAHUAaQBkACBIYQBmAGMAZAA1ADQANAA2AC0ANAA5ADEANAAtADQAZgBlADcALQBiAGIANwA4AC0AOQBiAGYAZgBlAGIANwAwAGYAZAAxADcAIRRVAHAAZABhAHQAZQBJAG4AZgBvACJMewBiADAAMwAzADYANgBhADgALQBiADUAYwAwAC0ANABiADkAYQAtAGEAMAAwAGUALQBlAGIAOAA2ADAAMQAxADEAMAA0AGMAMwB9ACMOVQBwAGQAYQB0AGUAcwAkTHsAMQA4ADYAOABmAGYAYwA5AC0AZQA0AGYAYwAtADQANQAzADIALQBhAGMAMAA2AC0AMQBlADMAOQBiAGIANQA1ADcAYgA2ADkAfQAlTHsAYQA1AGIAZAA0ADgAYwAzAC0AMABkADEANwAtADQAMQBiADUALQBiADEANgA0AC0ANQBmAGMANgBhAGQAMgBiADkANgBiADcAfQAmFk8AYgBqAGUAYwB0AHMAVAB5AHAAZQAnVFUAcABkAGEAdABlAEwAYQBuAGcAdQBhAGcAZQBNAG8AZABlAGwARgBvAHIAQwBvAG4AdgBlAHIAdABpAGIAbABlAEwAaQBiAHIAYQByAGkAZQBzACgQTABpAGIAVABpAHQAbABlACkUTABpAGIAQwBvAG0AcABhAG4AeQAqHlUAcABkAGEAdABlAFAAcgBvAHYAaQBkAGUAcgBzACs4UwB5AHMAdABlAG0ALgBDAG8AbABsAGUAYwB0AGkAbwBuAHMALgBIAGEAcwBoAHQAYQBiAGwAZQAsEnYAaQBzAHUAZQBsAGUAbQBzAC1INgBjAGIAMQBjAGQAZQAxAC0AZAA1AGQAYwAtADQAYQAzAGIALQA5ADAANQA0AC0AMgAxAGYAYQA3ADUANgBhADMAZgBhADQALihJAG4AdABlAHIAZgBhAGMAZQBWAGUAcgBzAGkAbwBuAEkAbgBmAG8AL0x7AGMANgAxADEAZQA0ADAAMAAtADcAZgBiADkALQA0AGMAMwA1AC0AYgA5AGEAYwAtADQAZQAzADEANABiADUAOQA5ADYANAAzAH0AMBhNAGEAagBvAHIAVgBlAHIAcwBpAG8AbgAxGE0AaQBuAG8AcgBWAGUAcgBzAGkAbwBuADIMTABlAGcAYQBjAHkAMzBMAGEAbgBnAHUAYQBnAGUATQBvAGQAZQBsAFYAZQByAHMAaQBvAG4ASQBuAGYAbwA0MEwAbwBhAGQATABpAGIAcgBhAHIAaQBlAHMASQBuAHQAbwBQAHIAbwBqAGUAYwB0ADUaQwBvAG0AcABhAHQAaQBiAGkAbABpAHQAeQDQAAIaA9ADAS0E0AUGGgfQBwgaAUUHCQjQAAkaBEUKCwQDAAAABQAAAA0AAAAAAAAA0AwLrQIAAADQDQEtDtAPAS0Q0AAJGgRFCgsEAwAAAAUAAAANAAAAKAAAANAMC60BAAAA0A0BLRHQDwEtENAACRoERQoLBAMAAAAFAAAADQAAAAAAAADQDAutAgAAANANAS0S0A8BLRDQAAkaBEUKCwQDAAAABQAAAA0AAAAUAAAA0AwLrQIAAADQDQEtE9APAS0Q0AAJGgRFCgsEAwAAAAUAAAANAAAAAAAAANAMC60CAAAA0A0BLRTQDwEtENAACRoERQoLBAMAAAAFAAAADQAAAAAAAADQDAutAgAAANANAS0V0A8BLRDQAAkaBEUKCwQDAAAABQAAAA0AAAAAAAAA0AwLrQIAAADQDQEtFtAPAS0X0AAJGgRFCgsEAwAAAAUAAAANAAAAKAAAANAMC60EAAAA0A0BLRjQDwEtENAZGq0BRRscAdAAHBoCRR0LBAMAAAAFAAAADQAAAAAAAADQHh8tINAhIhoCRSMkAtAAJRoFRQoLBAMAAAADAAAAAAAAAAoAAADQJgutAAAAANADAS0n0CgBLRHQKQEtENAAJRoFRQoLBAMAAAADAAAAAAAAAAoAAADQJgutAQAAANADAS0n0CgBLRHQKQEtEJoqKwFFAAEC0AABLSzQAAEtF9AAHy0t0C4vGgPQMAutAQAAANAxC60XAAAA0DIarQDQMy8aA9AwC60CAAAA0DELrQMAAADQMhqtANA0Gq0A0DUarQA= 95 | 96 | 97 | {192FAD59-8248-4824-A8DE-9177C94C195A} 98 | 99 | "{192FAD59-8248-4824-A8DE-9177C94C195A}" 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | System.Collections.Hashtable 109 | {54dd0eac-a6d8-46f2-8c27-2f43c7e49861} 110 | System.String 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/POUs/MAIN.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 20 | 21 | fileTime.dwLowDateTime, timeHiDW=>fileTime.dwHighDateTime ); 26 | GVL.DatetimeUTC := FILETIME_TO_DT(fileTime); 27 | fbToLocal( in := fileTime, tzInfo := WEST_EUROPE_TZI ); 28 | GVL.Datetime := FILETIME_TO_DT( fbToLocal.out ); 29 | GVL.ActualDate := DT_TO_DATE(GVL.Datetime); 30 | GVL.ActualTime := DT_TO_TIME(GVL.Datetime); 31 | GVL.ActualLTime := TIME_TO_LTIME(GVL.ActualTime);]]> 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/POUs/TestFB1.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 21 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/POUs/TestFB1Device.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/POUs/TestFB1DeviceSubdevice.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/MainPLC/PlcTask.TcTTO: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10000 6 | 20 7 | 8 | MAIN 9 | 10 | {99a9352c-1710-4941-9e01-2ecaeb84328e} 11 | {70ccc488-6c79-4c36-8200-5623a8ba5c1e} 12 | {ad51be9b-15b7-449c-a801-4fce87db1f5e} 13 | {608552c4-40dc-4965-bddf-d245b88555ca} 14 | {6d9f1bc3-5d5a-4ceb-b93a-7c83366092d3} 15 | 16 | 17 | -------------------------------------------------------------------------------- /Tests/PlcProject/TwinCATDummy/TwinCATDummy.tsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | PlcTask 9 | 10 | 11 | 12 | 13 | 14 | 15 | MainPLC Instance 16 | {08500001-0000-0000-F000-000000000064} 17 | 18 | 19 | 0 20 | PlcTask 21 | 22 | #x02010030 23 | 24 | 20 25 | 10000000 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 20 | 21 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Windows; 4 | 5 | namespace TwinCatAdsTool.Gui 6 | { 7 | /// 8 | /// Interaction logic for App.xaml 9 | /// 10 | public partial class App : Application 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Commands/ReactiveRelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Reactive.Subjects; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Input; 9 | 10 | namespace TwinCatAdsTool.Gui.Commands 11 | { 12 | public class ReactiveRelayCommand : ICommand 13 | { 14 | private readonly Action execute; 15 | private readonly Predicate canExecute; 16 | 17 | public ReactiveRelayCommand(Action execute) 18 | : this(execute, null) 19 | { 20 | } 21 | 22 | public ReactiveRelayCommand(Action execute, Predicate canExecute) 23 | { 24 | if (execute == null) 25 | { 26 | throw new ArgumentNullException("execute"); 27 | } 28 | 29 | this.execute = execute; 30 | this.canExecute = canExecute; 31 | } 32 | 33 | [DebuggerStepThrough] 34 | public bool CanExecute(object parameter) 35 | { 36 | return canExecute == null || canExecute(parameter); 37 | } 38 | 39 | public event EventHandler CanExecuteChanged 40 | { 41 | add { CommandManager.RequerySuggested += value; } 42 | remove { CommandManager.RequerySuggested -= value; } 43 | } 44 | 45 | public void Execute(object parameter) 46 | { 47 | execute(parameter); 48 | executed.OnNext(parameter); 49 | } 50 | 51 | private readonly Subject executed = new Subject(); 52 | 53 | public IObservable Executed 54 | { 55 | get { return executed; } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Converters/BoolToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace TwinCatAdsTool.Gui.Converters 7 | { 8 | public class BoolToVisibilityConverter : IValueConverter 9 | { 10 | public Visibility IfTrue { get; set; } = Visibility.Visible; 11 | public Visibility IfFalse { get; set; } = Visibility.Collapsed; 12 | 13 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | if (value is bool) 16 | { 17 | return (bool) value ? IfTrue : IfFalse; 18 | } 19 | 20 | return DependencyProperty.UnsetValue; 21 | 22 | } 23 | 24 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 25 | { 26 | return DependencyProperty.UnsetValue; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Converters/ConnectionStateToBoolConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Data; 9 | using TwinCAT; 10 | 11 | namespace TwinCatAdsTool.Gui.Converters 12 | { 13 | public class ConnectionStateToBoolConverter : IValueConverter 14 | { 15 | public bool IfDisconnected { get; set; } = true; 16 | public bool IfConnected { get; set; } = false; 17 | 18 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | if (value is ConnectionState) 21 | { 22 | var connectionState = (ConnectionState) value; 23 | switch (connectionState) 24 | { 25 | case ConnectionState.None: 26 | case ConnectionState.Lost: 27 | case ConnectionState.Disconnected: 28 | return IfDisconnected; 29 | case ConnectionState.Connected: 30 | return IfConnected; 31 | default: 32 | return DependencyProperty.UnsetValue; 33 | 34 | } 35 | } 36 | 37 | return DependencyProperty.UnsetValue; 38 | 39 | } 40 | 41 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 42 | { 43 | return DependencyProperty.UnsetValue; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Converters/ConnectionStateToIconConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Windows; 5 | using System.Windows.Data; 6 | using TwinCAT; 7 | 8 | namespace TwinCatAdsTool.Gui.Converters 9 | { 10 | public class ConnectionStateToIconConverter : IValueConverter 11 | { 12 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 13 | { 14 | if (value is ConnectionState) 15 | { 16 | var connectionState = (ConnectionState)value; 17 | switch (connectionState) 18 | { 19 | case ConnectionState.None: 20 | case ConnectionState.Lost: 21 | return "minus"; 22 | case ConnectionState.Disconnected: 23 | return "unlink"; 24 | case ConnectionState.Connected: 25 | return "link"; 26 | default: 27 | return DependencyProperty.UnsetValue; 28 | 29 | } 30 | } 31 | 32 | return DependencyProperty.UnsetValue; 33 | 34 | } 35 | 36 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 37 | { 38 | return DependencyProperty.UnsetValue; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Converters/ConnectionStateToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | using TwinCAT; 6 | 7 | namespace TwinCatAdsTool.Gui.Converters 8 | { 9 | public class ConnectionStateToVisibilityConverter : IValueConverter 10 | { 11 | public Visibility IfDisconnected { get; set; } = Visibility.Visible; 12 | public Visibility IfConnected { get; set; } = Visibility.Collapsed; 13 | 14 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | if (value is ConnectionState) 17 | { 18 | var connectionState = (ConnectionState) value; 19 | switch (connectionState) 20 | { 21 | case ConnectionState.None: 22 | case ConnectionState.Lost: 23 | case ConnectionState.Disconnected: 24 | return IfDisconnected; 25 | case ConnectionState.Connected: 26 | return IfConnected; 27 | default: 28 | return DependencyProperty.UnsetValue; 29 | 30 | } 31 | } 32 | 33 | return DependencyProperty.UnsetValue; 34 | 35 | } 36 | 37 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 38 | { 39 | return DependencyProperty.UnsetValue; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Converters/DtToDateTimeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Windows.Data; 6 | using TwinCAT.PlcOpen; 7 | 8 | namespace TwinCatAdsTool.Gui.Converters 9 | { 10 | public class DtToDateTimeConverter : IValueConverter 11 | { 12 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 13 | { 14 | return DoConvert(value); 15 | } 16 | 17 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 18 | { 19 | return DoConvert(value); 20 | } 21 | 22 | private object DoConvert(object value) 23 | { 24 | if (value is DT dt) 25 | { 26 | return dt.Date; 27 | } 28 | 29 | if (value is DateTime dateTime) 30 | { 31 | return new DT(dateTime); 32 | } 33 | 34 | return value; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Converters/LTimeToTimeSpanConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Windows.Data; 5 | using TwinCAT.PlcOpen; 6 | 7 | namespace TwinCatAdsTool.Gui.Converters 8 | { 9 | public class LTimeToTimeSpanConverter : IValueConverter 10 | { 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | return DoConvert(value); 14 | } 15 | 16 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 17 | { 18 | return DoConvert(value); 19 | } 20 | 21 | private object DoConvert(object value) 22 | { 23 | if (value is LTIME lTime) 24 | { 25 | return lTime.Value; 26 | } 27 | 28 | if (value is TimeSpan timeSpan) 29 | { 30 | return new LTIME(timeSpan); 31 | } 32 | 33 | return value; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Converters/TimeToTimeSpanConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using TwinCAT.PlcOpen; 5 | 6 | namespace TwinCatAdsTool.Gui.Converters 7 | { 8 | public class TimeToTimeSpanConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | return DoConvert(value); 13 | } 14 | 15 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | return DoConvert(value); 18 | } 19 | 20 | private object DoConvert(object value) 21 | { 22 | if (value is TIME lTime) 23 | { 24 | return lTime.Value; 25 | } 26 | 27 | if (value is TimeSpan timeSpan) 28 | { 29 | return new TIME(timeSpan); 30 | } 31 | 32 | return value; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Extensions/ReactiveUiExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reactive.Disposables; 4 | using log4net; 5 | using ReactiveUI; 6 | 7 | namespace TwinCatAdsTool.Gui.Extensions 8 | { 9 | public static class ReactiveUiExtensions 10 | { 11 | public static T SetupErrorHandling(this T obj, ILog logger, CompositeDisposable disposables) where T : IDisposable, IHandleObservableErrors 12 | { 13 | return obj.SetupErrorHandling(logger, disposables, "Error in ReactiveCommand"); 14 | } 15 | 16 | public static T SetupErrorHandling(this T obj, ILog logger, CompositeDisposable disposables, string message) where T : IDisposable, IHandleObservableErrors 17 | { 18 | disposables.Add(obj.ThrownExceptions.Subscribe((Action)(ex => logger.Error(message, ex)))); 19 | disposables.Add((IDisposable)obj); 20 | return obj; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Extensions/TreeViewModelExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Reactive.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using DynamicData; 9 | using TwinCAT.TypeSystem; 10 | using TwinCatAdsTool.Gui.ViewModels; 11 | 12 | namespace TwinCatAdsTool.Gui.Extensions 13 | { 14 | public static class TreeViewModelExtension 15 | { 16 | public static ObservableCollection Flatten(this IEnumerable viewModels) 17 | { 18 | var results = new ObservableCollection(); 19 | results.AddRange(viewModels.Select(symbol => new TreeViewModel(symbol))); 20 | 21 | var childs = viewModels.SelectMany(vm => vm.SubSymbols); 22 | if (childs.Any()) 23 | { 24 | results.AddRange(childs.Flatten()); 25 | } 26 | 27 | return results; 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Extensions/VariableViewModelExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using TwinCatAdsTool.Gui.ViewModels; 7 | 8 | namespace TwinCatAdsTool.Gui.Extensions 9 | { 10 | public static class VariableViewModelExtension 11 | { 12 | // equal if viewModels have same properties, json values can be different 13 | public static bool HasEqualStructure(this IEnumerable viewModels1, IEnumerable viewModels2) 14 | { 15 | if (!viewModels1.Count().Equals(viewModels2.Count())) 16 | { 17 | return false; 18 | } 19 | 20 | foreach(var element in viewModels1) 21 | { 22 | if(viewModels2.Count(x => x.Name == element.Name) != 1) 23 | { 24 | return false; 25 | } 26 | } 27 | 28 | return true; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/GuiModuleCatalog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Ninject.Modules; 4 | 5 | namespace TwinCatAdsTool.Gui 6 | { 7 | public class GuiModuleCatalog : NinjectModule 8 | { 9 | public override void Load() 10 | { 11 | 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Properties/Resources.de.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | text/microsoft-resx 90 | 91 | 92 | 1.3 93 | 94 | 95 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 96 | 97 | 98 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 99 | 100 | 101 | Angezeigte Zeitspanne 102 | 103 | 104 | Backup nach {0} gespeichert 105 | 106 | 107 | Datei {0} erfolgreich geladen 108 | 109 | 110 | Fehler bei Laden von Datei 111 | 112 | 113 | Linke TextBox neu geladen 114 | 115 | 116 | Rechte TextBox neu geladen 117 | 118 | 119 | Lese persistente Variablen 120 | 121 | 122 | Verbindung hergestellt zu Gerät {0} mit Addresse {1} 123 | 124 | 125 | Problem bei Entfernen der Beobachtung von symbol {0} 126 | 127 | 128 | Fehler bei Suche 129 | 130 | 131 | Problem bei Neu-Laden der Variablen 132 | 133 | 134 | Problem mit Anlegen der Beobachtung von symbol {0} 135 | 136 | 137 | Probleme bei Änderung des Baums 138 | 139 | 140 | Dieser Typ ist nicht implementiert 141 | 142 | 143 | Das Symbol {0} wurde bereits zur Beobachtungsliste hinzugefügt 144 | 145 | 146 | Versuche JSON {0} mit Wert {1} zu schreiben 147 | 148 | 149 | Datei hat nicht die selbe Struktur wie Daten auf der Steuerung 150 | 151 | 152 | Fehler 153 | 154 | 155 | Änderung der Anzeige zum Wiederherstellen 156 | 157 | 158 | Sind Sie sicher dass Sie die aktuellen Variablen der Steuerung überschreiben wollen? 159 | 160 | 161 | Überschreiben Bestätigung 162 | 163 | 164 | Dieser Wert kann nur gelesen werden 165 | 166 | 167 | Wert kann nur gelesen werden 168 | 169 | 170 | Versuche {0} mit {1} zu schreiben 171 | 172 | 173 | Lese von Steuerung 174 | 175 | 176 | Schreibe nach Datei 177 | 178 | 179 | Lese von Datei 180 | 181 | 182 | Daten neu Laden 183 | 184 | 185 | Gib Symbolname zum Suchen ein 186 | 187 | 188 | Name 189 | 190 | 191 | Wert 192 | 193 | 194 | Neuer Wert 195 | 196 | 197 | Absenden 198 | 199 | 200 | Graph hinzufügen 201 | 202 | 203 | Graph entfernen 204 | 205 | 206 | Laden 207 | 208 | 209 | Schreiben 210 | 211 | 212 | Sicherung 213 | 214 | 215 | Wiederherstellen 216 | 217 | 218 | Vergleich 219 | 220 | 221 | Variablen 222 | 223 | 224 | Trennen 225 | 226 | 227 | Keine Einträge gefunden 228 | 229 | 230 | Verbinden 231 | 232 | 233 | Baum 234 | 235 | 236 | Suche 237 | 238 | 239 | Addresse 240 | 241 | 242 | Port 243 | 244 | 245 | Eine Software von 246 | 247 | 248 | Symbolliste in flat Format nutzen 249 | 250 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Resources/evopro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fbarresi/TwinCatAdsTool/68f4c027dfeef88694ba1f30caad2050eb27d599/TwinCatAdsTool.Gui/Resources/evopro.png -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Resources/twincat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fbarresi/TwinCatAdsTool/68f4c027dfeef88694ba1f30caad2050eb27d599/TwinCatAdsTool.Gui/Resources/twincat.png -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/TwinCatAdsTool.Gui.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net5.0-windows10.0.19041 6 | true 7 | true 8 | win10-x64 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModelLocator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Ninject; 4 | using Ninject.Parameters; 5 | using TwinCatAdsTool.Gui.ViewModels; 6 | using TwinCatAdsTool.Interfaces.Commons; 7 | using IInitializable = TwinCatAdsTool.Interfaces.Commons.IInitializable; 8 | 9 | namespace TwinCatAdsTool.Gui 10 | { 11 | public class ViewModelLocator : IViewModelFactory, IInstanceCreator 12 | { 13 | protected readonly IKernel Kernel; 14 | 15 | private static ViewModelLocator s_Instance; 16 | 17 | public ViewModelLocator() 18 | { 19 | BindServices(); 20 | } 21 | 22 | private void BindServices() 23 | { 24 | Kernel.Bind().To(); 25 | Kernel.Bind().To(); 26 | Kernel.Bind().To(); 27 | Kernel.Bind().To(); 28 | } 29 | 30 | public ViewModelLocator(IKernel kernel) 31 | { 32 | Kernel = kernel; 33 | kernel.Bind().ToConstant(this); 34 | BindServices(); 35 | } 36 | 37 | public static IInstanceCreator DesignInstanceCreator => s_Instance ?? (s_Instance = new ViewModelLocator()); 38 | 39 | public static IViewModelFactory DesignViewModelFactory => s_Instance ?? (s_Instance = new ViewModelLocator()); 40 | 41 | public MainWindowViewModel MainWindowViewModel => Kernel.Get(); 42 | 43 | public T Create() 44 | { 45 | var newObject = Kernel.Get(); 46 | InitializeInitialziable(newObject as IInitializable); 47 | return newObject; 48 | } 49 | 50 | public T CreateInstance(ConstructorArgument[] arguments) 51 | { 52 | var vm = Kernel.Get(arguments); 53 | InitializeInitialziable(vm as IInitializable); 54 | return vm; 55 | } 56 | 57 | public TVm CreateViewModel(T model) 58 | { 59 | var vm = Kernel.Get(new ConstructorArgument(@"model", model)); 60 | InitializeInitialziable(vm as IInitializable); 61 | return vm; 62 | } 63 | 64 | public TVm CreateViewModel() 65 | { 66 | var vm = Kernel.Get(); 67 | InitializeInitialziable(vm as IInitializable); 68 | return vm; 69 | } 70 | 71 | private static void InitializeInitialziable(IInitializable initializable) 72 | { 73 | initializable?.Init(); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/BackupViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Reactive; 5 | using System.Reactive.Linq; 6 | using System.Reactive.Subjects; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | using Newtonsoft.Json; 10 | using Newtonsoft.Json.Linq; 11 | using ReactiveUI; 12 | using TwinCAT; 13 | using TwinCatAdsTool.Gui.Properties; 14 | using TwinCatAdsTool.Interfaces.Extensions; 15 | using TwinCatAdsTool.Interfaces.Services; 16 | 17 | namespace TwinCatAdsTool.Gui.ViewModels 18 | { 19 | public class BackupViewModel : ViewModelBase 20 | { 21 | private readonly IClientService clientService; 22 | private readonly IPersistentVariableService persistentVariableService; 23 | private readonly Subject variableSubject = new Subject(); 24 | private string backupText; 25 | private ObservableAsPropertyHelper currentTaskHelper; 26 | 27 | public BackupViewModel(IClientService clientService, IPersistentVariableService persistentVariableService) 28 | { 29 | this.clientService = clientService; 30 | this.persistentVariableService = persistentVariableService; 31 | } 32 | 33 | public string BackupText 34 | { 35 | get => backupText; 36 | set 37 | { 38 | if (value == backupText) return; 39 | backupText = value; 40 | raisePropertyChanged(); 41 | } 42 | } 43 | 44 | public ReactiveCommand Read { get; set; } 45 | public ReactiveCommand Save { get; set; } 46 | 47 | public override void Init() 48 | { 49 | variableSubject 50 | .ObserveOnDispatcher() 51 | .Do(o => BackupText = o.ToString(Formatting.Indented)) 52 | .Retry() 53 | .Subscribe() 54 | .AddDisposableTo(Disposables) 55 | ; 56 | 57 | Read = ReactiveCommand.CreateFromTask(ReadVariables, canExecute: clientService.ConnectionState.Select(state => state == ConnectionState.Connected)) 58 | .AddDisposableTo(Disposables); 59 | 60 | Save = ReactiveCommand.CreateFromTask(SaveVariables, clientService.ConnectionState.Select(state => state == ConnectionState.Connected)) 61 | .AddDisposableTo(Disposables); 62 | 63 | currentTaskHelper = persistentVariableService.CurrentTask.ToProperty(this, vm => vm.CurrentTask); 64 | } 65 | 66 | public string CurrentTask => currentTaskHelper.Value; 67 | 68 | private async Task ReadVariables() 69 | { 70 | var persistentVariables = await persistentVariableService.ReadGlobalPersistentVariables( 71 | clientService.Client, 72 | clientService.TreeViewSymbols); 73 | variableSubject.OnNext(persistentVariables); 74 | Logger.Debug(Resources.ReadPersistentVariables); 75 | 76 | return Unit.Default; 77 | } 78 | 79 | private Task SaveVariables() 80 | { 81 | SaveFileDialog saveFileDialog1 = new SaveFileDialog(); 82 | saveFileDialog1.Filter = "Json|*.json"; 83 | saveFileDialog1.Title = "Save in a json file"; 84 | saveFileDialog1.FileName = $"Backup_{DateTime.Now:yyy-MM-dd-HHmmss}.json"; 85 | saveFileDialog1.RestoreDirectory = true; 86 | var result = saveFileDialog1.ShowDialog(); 87 | if (result == DialogResult.OK || result == DialogResult.Yes) 88 | { 89 | File.WriteAllText(saveFileDialog1.FileName, BackupText); 90 | Logger.Debug(string.Format(Resources.SavedBackupTo0Logging, saveFileDialog1.FileName)); 91 | } 92 | 93 | return Task.FromResult(Unit.Default); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/ConnectionCabViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.ObjectModel; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Reactive.Linq; 5 | using DynamicData; 6 | using System.Linq; 7 | using System.Reactive; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Threading; 11 | using ReactiveUI; 12 | using TwinCAT; 13 | using TwinCAT.Ads; 14 | using TwinCatAdsTool.Gui.Extensions; 15 | using TwinCatAdsTool.Gui.Properties; 16 | using TwinCatAdsTool.Interfaces.Extensions; 17 | using TwinCatAdsTool.Interfaces.Models; 18 | using TwinCatAdsTool.Interfaces.Services; 19 | 20 | namespace TwinCatAdsTool.Gui.ViewModels 21 | { 22 | public class ConnectionCabViewModel : ViewModelBase 23 | { 24 | private readonly IClientService clientService; 25 | private ObservableAsPropertyHelper connectionStateHelper; 26 | private int port = 851; 27 | private string selectedNetId; 28 | private NetId selectedAmsNetId; 29 | private ObservableAsPropertyHelper adsStatusHelper; 30 | 31 | 32 | public ConnectionCabViewModel(IClientService clientService) 33 | { 34 | this.clientService = clientService; 35 | } 36 | 37 | public ObservableCollection AmsNetIds { get; set; } = new ObservableCollection(); 38 | public ReactiveCommand Connect { get; set; } 39 | 40 | public ConnectionState ConnectionState => connectionStateHelper.Value; 41 | public ReactiveCommand Disconnect { get; set; } 42 | 43 | public int Port 44 | { 45 | get => port; 46 | set 47 | { 48 | if (value == port) return; 49 | port = value; 50 | raisePropertyChanged(); 51 | } 52 | } 53 | 54 | public NetId SelectedAmsNetId 55 | { 56 | get { return selectedAmsNetId; } 57 | 58 | set 59 | { 60 | if (selectedAmsNetId != value) 61 | { 62 | selectedAmsNetId = value; 63 | raisePropertyChanged(); 64 | } 65 | } 66 | } 67 | 68 | 69 | public string SelectedNetId 70 | { 71 | get => selectedNetId; 72 | set 73 | { 74 | if (selectedNetId != value) 75 | { 76 | selectedNetId = value; 77 | raisePropertyChanged(); 78 | } 79 | } 80 | } 81 | 82 | 83 | public override void Init() 84 | { 85 | Connect = ReactiveCommand.CreateFromTask(ConnectClient, canExecute: clientService.ConnectionState.Select(state => state != ConnectionState.Connected)) 86 | .AddDisposableTo(Disposables).SetupErrorHandling(Logger, Disposables); 87 | Disconnect = ReactiveCommand.CreateFromTask(DisconnectClient, canExecute: clientService.ConnectionState.Select(state => state == ConnectionState.Connected)) 88 | .AddDisposableTo(Disposables).SetupErrorHandling(Logger, Disposables); 89 | 90 | connectionStateHelper = clientService 91 | .ConnectionState 92 | .ObserveOnDispatcher() 93 | .ToProperty(this, model => model.ConnectionState); 94 | 95 | adsStatusHelper = clientService 96 | .AdsState 97 | .ObserveOnDispatcher() 98 | .ToProperty(this, model => model.AdsStatus); 99 | 100 | 101 | clientService.DevicesFound 102 | .Where(d => d != null) 103 | .ObserveOnDispatcher() 104 | .Do(devices => AmsNetIds.AddRange(devices)) 105 | .Subscribe() 106 | .AddDisposableTo(Disposables); 107 | 108 | AmsNetIds.Add(new NetId(){Address = "", Name = "*"}); 109 | SelectedAmsNetId = AmsNetIds.FirstOrDefault(); 110 | 111 | this.WhenAnyValue(vm => vm.SelectedAmsNetId) 112 | .ObserveOn(Dispatcher.CurrentDispatcher) 113 | .Do(s => SelectedNetId = s.Address) 114 | .Subscribe() 115 | .AddDisposableTo(Disposables); 116 | 117 | } 118 | 119 | public string AdsStatus => adsStatusHelper.Value; 120 | 121 | private async Task ConnectClient() 122 | { 123 | try 124 | { 125 | await clientService.Connect(SelectedNetId, Port); 126 | Logger.Debug(string.Format(Resources.ClientConnectedToDevice0WithAddress1, SelectedAmsNetId?.Name, 127 | SelectedAmsNetId?.Address)); 128 | } 129 | catch (Exception ex) when (ex.InnerException is DllNotFoundException && ex.InnerException.Source == "TwinCAT.Ads") 130 | { 131 | Logger.Error("Dll not found TwinCAT.Ads"); 132 | MessageBox.Show("Dll for TwinCAT.Ads not found. Have you installed the drivers?"); 133 | } 134 | } 135 | 136 | private async Task DisconnectClient() 137 | { 138 | await clientService.Disconnect(); 139 | Logger.Debug("Client disconnected"); 140 | } 141 | } 142 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/GraphViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Reactive.Linq; 5 | using DynamicData; 6 | using System.Linq; 7 | using System.Reactive; 8 | using System.Reactive.Disposables; 9 | using System.Threading.Tasks; 10 | using OxyPlot; 11 | using OxyPlot.Axes; 12 | using OxyPlot.Series; 13 | using ReactiveUI; 14 | using TwinCatAdsTool.Interfaces.Extensions; 15 | 16 | namespace TwinCatAdsTool.Gui.ViewModels 17 | { 18 | public class GraphViewModel : ViewModelBase 19 | { 20 | readonly Dictionary> dataPoints = new Dictionary>(); 21 | 22 | private readonly SourceCache symbolCache = new SourceCache(x => x.Name); 23 | private PlotModel plotModel; 24 | private TimeSpan expiresAfter = TimeSpan.FromMinutes(10); 25 | private bool pause = false; 26 | 27 | 28 | public TimeSpan ExpiresAfter { 29 | get { return expiresAfter; } 30 | set 31 | { 32 | pause = true; 33 | expiresAfter = value; 34 | raisePropertyChanged(); 35 | pause = false; 36 | } 37 | } 38 | 39 | 40 | public PlotModel PlotModel 41 | { 42 | get { return plotModel; } 43 | set 44 | { 45 | plotModel = value; 46 | raisePropertyChanged(); 47 | } 48 | } 49 | 50 | private IObservableCache SymbolCache => symbolCache.AsObservableCache(); 51 | 52 | public void AddSymbol(SymbolObservationViewModel symbol) 53 | { 54 | var symbolInLineSeries = PlotModel.Series.FirstOrDefault(series => series.Title == symbol.Name); 55 | if (symbolInLineSeries == null) 56 | { 57 | symbolCache.AddOrUpdate(symbol); 58 | } 59 | } 60 | 61 | public override void Init() 62 | { 63 | PlotModel = CreateDefaultPlotModel(); 64 | 65 | SymbolCache.Connect() 66 | .Transform(CreateSymbolLineSeries) 67 | .ObserveOnDispatcher() 68 | .DisposeMany() 69 | .Subscribe() 70 | .AddDisposableTo(Disposables); 71 | 72 | var axis = new DateTimeAxis 73 | { 74 | Position = AxisPosition.Bottom, 75 | StringFormat = "hh:mm:ss", 76 | IsZoomEnabled = false 77 | }; 78 | 79 | PlotModel.Axes.Add(axis); 80 | } 81 | 82 | private static PlotModel CreateDefaultPlotModel() 83 | { 84 | return new PlotModel 85 | { 86 | LegendBorder = OxyColor.FromRgb(0x80, 0x80, 0x80), 87 | LegendBorderThickness = 1, 88 | LegendBackground = OxyColor.FromRgb(0xFF, 0xFF, 0xFF), 89 | LegendPosition = LegendPosition.LeftBottom 90 | }; 91 | } 92 | 93 | public void RemoveSymbol(SymbolObservationViewModel symbol) 94 | { 95 | symbolCache.Remove(symbol.Name); 96 | 97 | var seriesToRemove = PlotModel.Series.FirstOrDefault(series => series.Title == symbol.Name); 98 | if (seriesToRemove != null) 99 | { 100 | PlotModel.Series.Remove(seriesToRemove); 101 | } 102 | 103 | var axisToRemove = PlotModel.Axes.FirstOrDefault(axis => axis.Key == symbol.Name); 104 | if (axisToRemove != null) 105 | { 106 | PlotModel.Axes.Remove(axisToRemove); 107 | } 108 | 109 | RescaleAxisDistances(); 110 | } 111 | 112 | private IDisposable CreateSymbolLineSeries(SymbolObservationViewModel symbol) 113 | { 114 | var lineSeries = CreateLineSeriesAndAxis(symbol); 115 | var disposable = new CompositeDisposable(); 116 | 117 | RescaleAxisDistances(); 118 | 119 | dataPoints[symbol.Name] = new List {DateTimeAxis.CreateDataPoint(DateTime.Now, Convert.ToDouble(symbol.Value))}; 120 | 121 | 122 | Observable.FromEventPattern( 123 | handler => handler.Invoke, 124 | h => symbol.PropertyChanged += h, 125 | h => symbol.PropertyChanged -= h) 126 | .Where(args => args.EventArgs.PropertyName == "Value" && pause == false) 127 | .ObserveOnDispatcher() 128 | .Subscribe(x => { UpdateDatapoints(symbol); }).AddDisposableTo(disposable); 129 | 130 | 131 | Observable.Interval(TimeSpan.FromSeconds(1)) 132 | .Where(x => pause == false) 133 | .ObserveOnDispatcher() 134 | .Subscribe(x => { UpdateLineseries(symbol, lineSeries); }) 135 | .AddDisposableTo(disposable); 136 | 137 | raisePropertyChanged("PlotModel"); 138 | 139 | // Need to invalidate oxyplot graph after removal of line series in order to have it really removed from UI 140 | Disposable.Create(() => PlotModel.InvalidatePlot(true)) 141 | .AddDisposableTo(disposable); 142 | 143 | return disposable; 144 | } 145 | 146 | private void UpdateLineseries(SymbolObservationViewModel symbol, LineSeries lineSeries) 147 | { 148 | var newPoints = dataPoints[symbol.Name] 149 | .Where(point => !lineSeries.Points.Select(oldPoint => oldPoint.X).Contains(point.X)); 150 | if (!newPoints.Any() && dataPoints[symbol.Name].Any()) 151 | { 152 | var lastPoint = dataPoints[symbol.Name].LastOrDefault(); 153 | newPoints = new[] {DateTimeAxis.CreateDataPoint(DateTime.Now, lastPoint.Y)}; 154 | } 155 | 156 | lineSeries.Points.AddRange(newPoints); 157 | 158 | var expireLimit = DateTimeAxis.ToDouble(DateTime.Now.Subtract(ExpiresAfter)); 159 | lineSeries.Points.RemoveAll(point => point.X < expireLimit); 160 | 161 | PlotModel.InvalidatePlot(true); 162 | raisePropertyChanged("PlotModel"); 163 | } 164 | 165 | private void UpdateDatapoints(SymbolObservationViewModel symbol) 166 | { 167 | var refreshTime = DateTime.Now; 168 | dataPoints[symbol.Name].Add(DateTimeAxis.CreateDataPoint(refreshTime, Convert.ToDouble(symbol.Value))); 169 | 170 | var expireLimit = DateTimeAxis.ToDouble(DateTime.Now.Subtract(ExpiresAfter)); 171 | dataPoints[symbol.Name].RemoveAll(point => point.X < expireLimit); 172 | } 173 | 174 | private LineSeries CreateLineSeriesAndAxis(SymbolObservationViewModel symbol) 175 | { 176 | var lineSeries = new LineSeries(); 177 | lineSeries.Title = symbol.Name; 178 | 179 | var index = PlotModel.Axes.Count - 1; 180 | 181 | var axis = new LinearAxis 182 | { 183 | AxislineThickness = 2, 184 | AxislineColor = PlotModel.DefaultColors[index], 185 | MinorTickSize = 4, 186 | MajorTickSize = 7, 187 | TicklineColor = PlotModel.DefaultColors[index], 188 | TextColor = PlotModel.DefaultColors[index], 189 | AxisDistance = PlotModel.Axes.OfType().Count() * 50, 190 | Position = AxisPosition.Left, 191 | IsZoomEnabled = false, 192 | Key = symbol.Name, 193 | Tag = symbol.Name, 194 | MinimumPadding = 0.1, 195 | MaximumPadding = 0.1 196 | }; 197 | 198 | lineSeries.YAxisKey = symbol.Name; 199 | 200 | PlotModel.Axes.Add(axis); 201 | PlotModel.Series.Add(lineSeries); 202 | return lineSeries; 203 | } 204 | 205 | private void RescaleAxisDistances() 206 | { 207 | for (var i = 0; i < PlotModel.Axes.OfType().Count(); i++) 208 | { 209 | PlotModel.Axes.OfType().Skip(i).First().AxisDistance = i * 50; 210 | } 211 | } 212 | } 213 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | using TwinCatAdsTool.Interfaces; 5 | using TwinCatAdsTool.Interfaces.Commons; 6 | using TwinCatAdsTool.Interfaces.Extensions; 7 | 8 | namespace TwinCatAdsTool.Gui.ViewModels 9 | { 10 | public class MainWindowViewModel : ViewModelBase 11 | { 12 | private readonly IViewModelFactory viewModelFactory; 13 | private string version; 14 | 15 | public MainWindowViewModel(IViewModelFactory viewModelFactory) 16 | { 17 | this.viewModelFactory = viewModelFactory; 18 | } 19 | 20 | public ConnectionCabViewModel ConnectionCabViewModel { get; set; } 21 | public TabsViewModel TabsViewModel { get; set; } 22 | 23 | public string Version 24 | { 25 | get => version; 26 | set 27 | { 28 | if (value == version) return; 29 | version = value; 30 | raisePropertyChanged(); 31 | } 32 | } 33 | 34 | public override void Init() 35 | { 36 | Logger.Debug("Initialize main window view model"); 37 | 38 | 39 | Version = $"v{Constants.Version}"; 40 | 41 | ConnectionCabViewModel = viewModelFactory.CreateViewModel(); 42 | ConnectionCabViewModel.AddDisposableTo(Disposables); 43 | 44 | TabsViewModel = viewModelFactory.CreateViewModel(); 45 | TabsViewModel.AddDisposableTo(Disposables); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/ObserverViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.ObjectModel; 3 | using System.Reactive.Linq; 4 | using System.Linq; 5 | using System.Windows; 6 | using TwinCAT.PlcOpen; 7 | using TwinCAT.TypeSystem; 8 | using TwinCatAdsTool.Gui.Properties; 9 | using TwinCatAdsTool.Interfaces.Commons; 10 | using TwinCatAdsTool.Interfaces.Extensions; 11 | using TwinCatAdsTool.Interfaces.Services; 12 | 13 | namespace TwinCatAdsTool.Gui.ViewModels 14 | { 15 | public class ObserverViewModel : ViewModelBase 16 | { 17 | private readonly ISelectionService symbolSelection; 18 | private readonly IViewModelFactory viewModelFactory; 19 | 20 | public ObserverViewModel(IViewModelFactory viewModelFactory, ISelectionService symbolSelection) 21 | { 22 | this.viewModelFactory = viewModelFactory; 23 | this.symbolSelection = symbolSelection; 24 | } 25 | 26 | public ObservableCollection ViewModels { get; set; } = new ObservableCollection(); 27 | 28 | public override void Init() 29 | { 30 | ViewModels.Clear(); 31 | symbolSelection.Elements 32 | .ObserveOnDispatcher() 33 | .Do(CreateViewModelOrShowMessage) 34 | .Subscribe() 35 | .AddDisposableTo(Disposables); 36 | } 37 | 38 | private void CreateViewModelOrShowMessage(ISymbol symbol) 39 | { 40 | if (ViewModels.All(viewModel => viewModel.Model != symbol)) 41 | { 42 | switch (symbol.TypeName) 43 | { 44 | case "BOOL": 45 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 46 | break; 47 | case "BYTE": 48 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 49 | break; 50 | case "WORD": 51 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 52 | break; 53 | case "DWORD": 54 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 55 | break; 56 | case "SINT": 57 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 58 | break; 59 | case "USINT": 60 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 61 | break; 62 | case "INT": 63 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 64 | break; 65 | case "UINT": 66 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 67 | break; 68 | case "DINT": 69 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 70 | break; 71 | case "UDINT": 72 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 73 | break; 74 | case "REAL": 75 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 76 | break; 77 | case "LREAL": 78 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 79 | break; 80 | case "STRING": 81 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 82 | break; 83 | case "DATE_AND_TIME": 84 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 85 | break; 86 | case "LTIME": 87 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 88 | break; 89 | case "TIME": 90 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 91 | break; 92 | default: 93 | if (symbol.TypeName.ToUpper().StartsWith("STRING")) 94 | { 95 | ViewModels.Add(viewModelFactory.CreateViewModel>(symbol)); 96 | break; 97 | } 98 | 99 | ViewModels.Add(viewModelFactory.CreateViewModel(symbol)); 100 | var exception = new NotImplementedException(Resources.ThisTypeIsNotImplemented); 101 | Logger.Error(exception.Message, exception); 102 | break; 103 | } 104 | } 105 | else 106 | { 107 | MessageBox.Show(string.Format(Resources.TheSymbol0HasAlreadyBeenAddedToTheListOfObservables, symbol?.InstanceName), "Symbol already observed", MessageBoxButton.OK); 108 | } 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/RestoreViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.IO; 5 | using System.Reactive.Linq; 6 | using DynamicData; 7 | using System.Reactive; 8 | using System.Reactive.Subjects; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Forms; 12 | using Newtonsoft.Json; 13 | using Newtonsoft.Json.Linq; 14 | using ReactiveUI; 15 | using TwinCAT; 16 | using TwinCAT.JsonExtension; 17 | using TwinCatAdsTool.Gui.Properties; 18 | using TwinCatAdsTool.Interfaces.Extensions; 19 | using TwinCatAdsTool.Interfaces.Services; 20 | using MessageBox = System.Windows.MessageBox; 21 | using OpenFileDialog = Microsoft.Win32.OpenFileDialog; 22 | 23 | namespace TwinCatAdsTool.Gui.ViewModels 24 | { 25 | public class RestoreViewModel : ViewModelBase 26 | { 27 | private readonly BehaviorSubject canWrite = new BehaviorSubject(false); 28 | private readonly IClientService clientService; 29 | private readonly BehaviorSubject fileVariableSubject = new BehaviorSubject(new JObject()); 30 | private readonly BehaviorSubject liveVariableSubject = new BehaviorSubject(new JObject()); 31 | private readonly IPersistentVariableService persistentVariableService; 32 | private ObservableCollection displayVariables; 33 | private ObservableCollection fileVariables; 34 | private ObservableCollection liveVariables; 35 | 36 | public RestoreViewModel(IClientService clientService, IPersistentVariableService persistentVariableService) 37 | { 38 | this.clientService = clientService; 39 | this.persistentVariableService = persistentVariableService; 40 | } 41 | 42 | public ObservableCollection DisplayVariables 43 | { 44 | get => displayVariables ?? (displayVariables = new ObservableCollection()); 45 | set 46 | { 47 | if (value == displayVariables) 48 | { 49 | return; 50 | } 51 | 52 | liveVariables = value; 53 | raisePropertyChanged(); 54 | } 55 | } 56 | 57 | public ObservableCollection FileVariables 58 | { 59 | get => fileVariables ?? (fileVariables = new ObservableCollection()); 60 | set 61 | { 62 | if (value == fileVariables) 63 | { 64 | return; 65 | } 66 | 67 | fileVariables = value; 68 | raisePropertyChanged(); 69 | } 70 | } 71 | 72 | public ObservableCollection LiveVariables 73 | { 74 | get => liveVariables ?? (liveVariables = new ObservableCollection()); 75 | set 76 | { 77 | if (value == liveVariables) return; 78 | liveVariables = value; 79 | raisePropertyChanged(); 80 | } 81 | } 82 | 83 | public ReactiveCommand Load { get; set; } 84 | public ReactiveCommand Write { get; set; } 85 | 86 | public override void Init() 87 | { 88 | fileVariableSubject 89 | .ObserveOnDispatcher() 90 | .Do(x => UpdateVariables(x, FileVariables)) 91 | .Do(x => UpdateDisplayIfMatching()) 92 | .Retry() 93 | .Subscribe() 94 | .AddDisposableTo(Disposables) 95 | ; 96 | 97 | canWrite.Subscribe().AddDisposableTo(Disposables); 98 | 99 | 100 | Load = ReactiveCommand.CreateFromTask(LoadVariables, canExecute: clientService.ConnectionState.Select(state => state == ConnectionState.Connected)) 101 | .AddDisposableTo(Disposables); 102 | 103 | Write = ReactiveCommand.CreateFromTask(WriteVariables, canWrite.Select(x => x)) 104 | .AddDisposableTo(Disposables); 105 | } 106 | 107 | private void AddVariable(IEnumerable token, ObservableCollection variables) 108 | { 109 | try 110 | { 111 | foreach (var prop in token) 112 | { 113 | if (prop.Value is JObject) 114 | { 115 | var variable = new VariableViewModel(); 116 | variable.Name = prop.Name; 117 | variable.Json = prop.Value.ToString(); 118 | variables.Add(variable); 119 | } 120 | } 121 | } 122 | finally 123 | { 124 | raisePropertyChanged("LiveVariables"); 125 | } 126 | } 127 | 128 | 129 | private async Task LoadVariables() 130 | { 131 | await LoadVariablesFromFile(); 132 | 133 | return Unit.Default; 134 | } 135 | 136 | private Task LoadVariablesFromFile() 137 | { 138 | OpenFileDialog openFileDialog = new OpenFileDialog(); 139 | openFileDialog.Filter = "Json files (*.json)|*.json"; 140 | openFileDialog.RestoreDirectory = true; 141 | if (openFileDialog.ShowDialog() == true) 142 | { 143 | JObject json = JObject.Parse(File.ReadAllText(openFileDialog.FileName)); 144 | fileVariableSubject.OnNext(json); 145 | canWrite.OnNext(true); 146 | } 147 | 148 | return Task.FromResult(Unit.Default); 149 | } 150 | 151 | private void UpdateDisplayIfMatching() 152 | { 153 | DisplayVariables.Clear(); 154 | var array = new VariableViewModel[FileVariables.Count]; 155 | FileVariables.CopyTo(array, 0); 156 | DisplayVariables.AddRange(array); 157 | 158 | raisePropertyChanged("DisplayVariables"); 159 | } 160 | 161 | private void UpdateVariables(JObject json, ObservableCollection viewModels) 162 | { 163 | viewModels.Clear(); 164 | AddVariable(json.Properties(), viewModels); 165 | Logger.Debug(Resources.UpdatedRestoreView); 166 | } 167 | 168 | private async Task WriteVariables() 169 | { 170 | MessageBoxResult messageBoxResult = MessageBox.Show(Resources.AreYouSureYouWantToOverwriteTheLiveVariablesOnThePLC, Resources.OverwriteConfirmation, MessageBoxButton.YesNo); 171 | if (messageBoxResult == MessageBoxResult.Yes) 172 | { 173 | foreach (var variable in DisplayVariables) 174 | { 175 | var jObject = await JObject.LoadAsync(new JsonTextReader(new StringReader(variable.Json))); 176 | 177 | foreach (var p in jObject.Properties()) 178 | { 179 | try 180 | { 181 | Logger.Debug($"Restoring variable '{variable.Name}.{p.Name}' from backup..."); 182 | switch (p.Value) 183 | { 184 | case JObject value: 185 | await clientService.Client.WriteJson(variable.Name + "." + p.Name, value, force: true); 186 | break; 187 | case JArray array: 188 | await clientService.Client.WriteJson(variable.Name + "." + p.Name, array, force: true); 189 | break; 190 | case JValue: 191 | await clientService.Client.WriteAsync(variable.Name + "." + p.Name, p.Value); 192 | break; 193 | default: 194 | Logger.Error( 195 | $"Unable to write variable '{variable.Name}.{p.Name} := {p.Value.ToString(Formatting.None)}' from backup: no type case match!"); 196 | break; 197 | } 198 | } 199 | catch (Exception ex) 200 | { 201 | Logger.Error($"Unable to write variable '{variable.Name}.{p.Name} := {p.Value.ToString(Formatting.None)}' from backup!", ex); 202 | MessageBox.Show($"{variable.Name}.{p.Name} := {p.Value.ToString(Formatting.None)} \n {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); 203 | } 204 | } 205 | 206 | } 207 | } 208 | 209 | return Unit.Default; 210 | } 211 | } 212 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/SearchResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using TwinCAT.TypeSystem; 5 | 6 | namespace TwinCatAdsTool.Gui.ViewModels 7 | { 8 | public struct SearchResult : IEquatable 9 | { 10 | public string SearchTerm { get; set; } 11 | public IEnumerable Results { get; set; } 12 | 13 | public bool Equals(SearchResult other) 14 | { 15 | return string.Equals(SearchTerm, other.SearchTerm) && Equals(Results, other.Results); 16 | } 17 | 18 | public override bool Equals(object obj) 19 | { 20 | return obj is SearchResult other && Equals(other); 21 | } 22 | 23 | public override int GetHashCode() 24 | { 25 | unchecked 26 | { 27 | return ((SearchTerm != null ? SearchTerm.GetHashCode() : 0) * 397) ^ (Results != null ? Results.GetHashCode() : 0); 28 | } 29 | } 30 | 31 | public static bool operator ==(SearchResult left, SearchResult right) 32 | { 33 | return left.Equals(right); 34 | } 35 | 36 | public static bool operator !=(SearchResult left, SearchResult right) 37 | { 38 | return !left.Equals(right); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/SymbolObservationViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reactive.Linq; 3 | using System.Linq; 4 | using System.Reactive; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using ReactiveUI; 9 | using TwinCAT; 10 | using TwinCAT.Ads.Reactive; 11 | using TwinCAT.TypeSystem; 12 | using TwinCatAdsTool.Gui.Properties; 13 | using TwinCatAdsTool.Interfaces.Extensions; 14 | using TwinCatAdsTool.Interfaces.Logging; 15 | using TwinCatAdsTool.Interfaces.Services; 16 | 17 | 18 | namespace TwinCatAdsTool.Gui.ViewModels 19 | { 20 | public abstract class SymbolObservationViewModel : ViewModelBase 21 | { 22 | protected readonly IClientService ClientService; 23 | private ObservableAsPropertyHelper helper; 24 | 25 | protected SymbolObservationViewModel(ISymbol model, IClientService clientService) 26 | { 27 | ClientService = clientService; 28 | Model = model; 29 | } 30 | 31 | public ReactiveCommand CmdSubmit { get; private set; } 32 | public ISymbol Model { get; set; } 33 | public string Name { get; set; } 34 | public string FullName { get; set; } 35 | 36 | public bool SupportsGraph => GetSupportsGraph(); 37 | public bool SupportsSubmit => GetSupportsSubmit(); 38 | 39 | public object Value => helper.Value; 40 | 41 | public override void Init() 42 | { 43 | Name = Model.InstanceName; 44 | FullName = Model.InstancePath; 45 | try 46 | { 47 | var readSymbolInfo = ClientService.Client.ReadSymbol(Model.InstancePath); 48 | var initialValue = ClientService.Client.ReadValue(readSymbolInfo); 49 | var observable = ((IValueSymbol) Model).WhenValueChanged().StartWith(initialValue); 50 | 51 | var obsLogger = LoggerFactory.GetObserverLogger(); 52 | 53 | observable 54 | .Do(value => obsLogger.Debug($"{FullName} value changed to: '{value.ToString()}'")) 55 | .Subscribe() 56 | .AddDisposableTo(Disposables); 57 | 58 | helper = observable.ToProperty(this, m => m.Value); 59 | 60 | CmdSubmit = ReactiveCommand.CreateFromTask(_ => SubmitSymbol(), 61 | ClientService.ConnectionState.Select(s => s == ConnectionState.Connected)) 62 | .AddDisposableTo(Disposables); 63 | } 64 | catch (Exception e) 65 | { 66 | Logger.Error($"Error while initializing vm for {Model.InstanceName}. Control will not be usable.", e); 67 | } 68 | } 69 | 70 | protected abstract bool GetSupportsGraph(); 71 | protected abstract bool GetSupportsSubmit(); 72 | protected abstract Task SubmitSymbol(); 73 | } 74 | 75 | public class SymbolObservationDefaultViewModel : SymbolObservationViewModel 76 | { 77 | public SymbolObservationDefaultViewModel(ISymbol model, IClientService clientService) : base(model, clientService) 78 | { 79 | } 80 | 81 | protected override bool GetSupportsGraph() 82 | { 83 | return false; 84 | } 85 | 86 | protected override bool GetSupportsSubmit() 87 | { 88 | return false; 89 | } 90 | 91 | protected override Task SubmitSymbol() 92 | { 93 | throw new NotImplementedException(); 94 | } 95 | } 96 | 97 | public class SymbolObservationViewModel : SymbolObservationViewModel 98 | { 99 | private T newValue; 100 | 101 | public SymbolObservationViewModel(ISymbol model, IClientService clientService) : base(model, clientService) 102 | { 103 | } 104 | 105 | public T NewValue 106 | { 107 | get => newValue; 108 | set 109 | { 110 | newValue = value; 111 | raisePropertyChanged(); 112 | } 113 | } 114 | 115 | public override void Init() 116 | { 117 | base.Init(); 118 | NewValue = (T) Value; 119 | } 120 | 121 | protected override bool GetSupportsGraph() 122 | { 123 | return (typeof(T) == typeof(int)) 124 | || (typeof(T) == typeof(short)) 125 | || (typeof(T) == typeof(bool)) 126 | || (typeof(T) == typeof(float)) 127 | || (typeof(T) == typeof(double)) 128 | || (typeof(T) == typeof(byte)) 129 | || (typeof(T) == typeof(ushort)) 130 | || (typeof(T) == typeof(uint)) 131 | || (typeof(T) == typeof(sbyte)); 132 | } 133 | 134 | protected override bool GetSupportsSubmit() 135 | { 136 | return true; 137 | } 138 | 139 | protected override Task SubmitSymbol() 140 | { 141 | Write(NewValue); 142 | return Task.FromResult(Unit.Default); 143 | } 144 | 145 | private void Write(T value) 146 | { 147 | if (Model.IsReadOnly) 148 | { 149 | MessageBox.Show(Resources.ThisValueIsReadOnly, Resources.ReadOnlyValue, MessageBoxButton.OK); 150 | return; 151 | } 152 | 153 | var variableHandle = ClientService.Client.CreateVariableHandle(Model.InstancePath); 154 | 155 | if (typeof(T) == typeof(string)) 156 | { 157 | Logger.Debug(string.Format(Resources.TryingToWriteTo0WithValue1, Model?.InstancePath, (value as string))); 158 | ClientService.Client.WriteAnyString(variableHandle, value as string, (value as string).Length, Encoding.Default); 159 | } 160 | else 161 | { 162 | Logger.Debug(string.Format(Resources.TryingToWriteTo0WithValue1, Model?.InstancePath, value)); 163 | ClientService.Client.WriteAny(variableHandle, value); 164 | } 165 | } 166 | } 167 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/TabsViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using TwinCatAdsTool.Interfaces.Commons; 4 | using TwinCatAdsTool.Interfaces.Extensions; 5 | 6 | namespace TwinCatAdsTool.Gui.ViewModels 7 | { 8 | public class TabsViewModel : ViewModelBase 9 | { 10 | private readonly IViewModelFactory viewModelFactory; 11 | 12 | public TabsViewModel(IViewModelFactory viewModelFactory) 13 | { 14 | this.viewModelFactory = viewModelFactory; 15 | } 16 | 17 | public BackupViewModel BackupViewModel { get; set; } 18 | public CompareViewModel CompareViewModel { get; set; } 19 | 20 | public ExploreViewModel ExploreViewModel { get; set; } 21 | 22 | public RestoreViewModel RestoreViewModel { get; set; } 23 | 24 | public override void Init() 25 | { 26 | BackupViewModel = viewModelFactory.CreateViewModel(); 27 | BackupViewModel.AddDisposableTo(Disposables); 28 | 29 | CompareViewModel = viewModelFactory.CreateViewModel(); 30 | CompareViewModel.AddDisposableTo(Disposables); 31 | 32 | 33 | ExploreViewModel = viewModelFactory.CreateViewModel(); 34 | ExploreViewModel.AddDisposableTo(Disposables); 35 | 36 | 37 | RestoreViewModel = viewModelFactory.CreateViewModel(); 38 | RestoreViewModel.AddDisposableTo(Disposables); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/TreeViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using TwinCAT.TypeSystem; 4 | 5 | namespace TwinCatAdsTool.Gui.ViewModels 6 | { 7 | public class TreeViewModel 8 | { 9 | public TreeViewModel(ISymbol model) 10 | { 11 | Model = model; 12 | Name = model.InstanceName; 13 | } 14 | 15 | public ISymbol Model { get; } 16 | public string Name { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/VariableViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace TwinCatAdsTool.Gui.ViewModels 5 | { 6 | public class VariableViewModel 7 | { 8 | public string Json { get; set; } 9 | public string Name { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/ViewModels/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Linq; 4 | using System.Reactive.Disposables; 5 | using System.Runtime.CompilerServices; 6 | using JetBrains.Annotations; 7 | using log4net; 8 | using ReactiveUI; 9 | using TwinCatAdsTool.Interfaces.Commons; 10 | using TwinCatAdsTool.Interfaces.Logging; 11 | 12 | namespace TwinCatAdsTool.Gui.ViewModels 13 | { 14 | public abstract class ViewModelBase : ReactiveObject, IDisposable, IInitializable 15 | { 16 | protected CompositeDisposable Disposables = new CompositeDisposable(); 17 | private bool disposed; 18 | private string title; 19 | 20 | public string Title 21 | { 22 | get => title; 23 | set 24 | { 25 | if (value == title) return; 26 | title = value; 27 | raisePropertyChanged(); 28 | } 29 | } 30 | 31 | protected ILog Logger { get; } = LoggerFactory.GetLogger(); 32 | 33 | public virtual void Dispose() 34 | { 35 | Dispose(true); 36 | } 37 | 38 | public abstract void Init(); 39 | 40 | [SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "Disposables")] 41 | protected virtual void Dispose(bool disposing) 42 | { 43 | if (disposed) 44 | { 45 | return; 46 | } 47 | 48 | Disposables?.Dispose(); 49 | Disposables = null; 50 | 51 | disposed = true; 52 | } 53 | 54 | [NotifyPropertyChangedInvocator] 55 | // ReSharper disable once InconsistentNaming 56 | protected void raisePropertyChanged([CallerMemberName] string propertyName = "") 57 | { 58 | this.RaisePropertyChanged(propertyName); 59 | } 60 | 61 | ~ViewModelBase() 62 | { 63 | Dispose(false); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/BackupView.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 31 | 32 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/BackupView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace TwinCatAdsTool.Gui.Views 17 | { 18 | /// 19 | /// Interaction logic for BackupView.xaml 20 | /// 21 | public partial class BackupView : UserControl 22 | { 23 | public BackupView() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/CompareView.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 87 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/ConnectionCabView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace TwinCatAdsTool.Gui.Views 17 | { 18 | /// 19 | /// Interaction logic for ConnectionCabView.xaml 20 | /// 21 | public partial class ConnectionCabView : UserControl 22 | { 23 | public ConnectionCabView() 24 | { 25 | InitializeComponent(); 26 | } 27 | 28 | private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e) 29 | { 30 | System.Diagnostics.Process.Start("http://www.evopro-ag.de"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/ExploreView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace TwinCatAdsTool.Gui.Views 17 | { 18 | /// 19 | /// Interaction logic for ExploreView.xaml 20 | /// 21 | public partial class ExploreView : UserControl 22 | { 23 | public ExploreView() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/GraphView.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 29 | 30 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/GraphView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace TwinCatAdsTool.Gui.Views 17 | { 18 | /// 19 | /// Interaction logic for GraphView.xaml 20 | /// 21 | public partial class GraphView : UserControl 22 | { 23 | public GraphView() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | sponsored by 34 | 35 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Windows; 4 | using MahApps.Metro.Controls; 5 | 6 | namespace TwinCatAdsTool.Gui.Views 7 | { 8 | /// 9 | /// Interaction logic for MainWindow.xaml 10 | /// 11 | public partial class MainWindow : MetroWindow 12 | { 13 | public MainWindow() 14 | { 15 | InitializeComponent(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /TwinCatAdsTool.Gui/Views/RestoreView.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |