<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Backup variable to a file.</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/0705dad894/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/0705dad894/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/0705dad894/</id><updated>2020-02-27T23:31:04.195000Z</updated><subtitle>Recent posts to Backup variable to a file.</subtitle><entry><title>Backup variable to a file.</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/0705dad894/?limit=25#a76a" rel="alternate"/><published>2020-02-27T23:31:04.195000Z</published><updated>2020-02-27T23:31:04.195000Z</updated><author><name>D.Hauer</name><uri>https://forge.codesys.com/u/d-hauer/</uri></author><id>https://forge.codesys.com37d6f1dadcad1997e93f3a31bc40456de3d7971c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;The INI format is my exchange format (PC and/or human), internally I use the same method like you.&lt;/p&gt;
&lt;p&gt;Increases speed dramatically &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Backup variable to a file.</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/0705dad894/?limit=25#515d" rel="alternate"/><published>2020-02-27T23:31:02.463000Z</published><updated>2020-02-27T23:31:02.463000Z</updated><author><name>spfeif</name><uri>https://forge.codesys.com/u/spfeif/</uri></author><id>https://forge.codesys.comfe6eb9a9ad4e8fdab605b5f197565d76e4b0e26b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Do you care what the format of the saved file is? In other words do you need to open it and have the file immediately human readable like your INI file or read by another PC program that uses ini files? The reason I ask is reading and writing files is easy with the SysLibFile. You can create a structure in CoDeSys then read and write the data of the structure to a file.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;TYPE&lt;/span&gt; &lt;span class="k"&gt;Parameters&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;STRUCT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;rSpeedPercent&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;REAL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;rPitch&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;REAL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;uID&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;BYTE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;sSpeed_Ref&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_STRUCT&lt;/span&gt;
&lt;span class="n"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now you can use the address operator to point to the structure and set the number of bytes = 11 and the library will automatically read these variables from the file and populate the structure correctly. Working with strings in a PLC is not optimal and I would strongly discourage it unless absolutely necessary.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Backup variable to a file.</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/0705dad894/?limit=25#6d03" rel="alternate"/><published>2020-02-27T23:30:57.795000Z</published><updated>2020-02-27T23:30:57.795000Z</updated><author><name>D.Hauer</name><uri>https://forge.codesys.com/u/d-hauer/</uri></author><id>https://forge.codesys.com4b3d2f62e556d0479c7b40b8baa82c0b7c6b3555</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;good idea,&lt;/p&gt;
&lt;p&gt;i do type conversion after reading KeyValue as string, this works&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Backup variable to a file.</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/0705dad894/?limit=25#cf68" rel="alternate"/><published>2020-02-27T23:30:56.119000Z</published><updated>2020-02-27T23:30:56.119000Z</updated><author><name>swtroelofs</name><uri>https://forge.codesys.com/u/swtroelofs/</uri></author><id>https://forge.codesys.come5d81dca4dfbe29f98466d7b1ac5172c7aef5a96</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks for your reply!&lt;/p&gt;
&lt;p&gt;Now I know I've got a lot of work to do &lt;/p&gt;
&lt;p&gt;I've done some testing and I think this method works the best:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;strKey&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Parking.rSpeedPercent'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;strValue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;DINT_TO_STRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Parking&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rSpeedPercent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;INI_Setkey_STRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strFilename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;strSection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;strKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;strValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;One more note: When I want to read the data from a file the INI_Getkey_STRING function works correctly. &lt;/p&gt;
&lt;p&gt;Only the other functions (INI_Getkey_BIN, INI_Getkey_DINT, INI_Getkey_DWORD) all crash the PLC. &lt;/p&gt;
&lt;p&gt;The PLC gives the error: &lt;/p&gt;
&lt;p&gt;Runtime error #81 (Access violation&lt;/p&gt;
&lt;p&gt;Task = PLC_PRG_TASK)&lt;/p&gt;
&lt;p&gt;I think I will keep using the INI_Getkey_STRING function.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Backup variable to a file.</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/0705dad894/?limit=25#97d5" rel="alternate"/><published>2020-02-27T23:30:51.475000Z</published><updated>2020-02-27T23:30:51.475000Z</updated><author><name>D.Hauer</name><uri>https://forge.codesys.com/u/d-hauer/</uri></author><id>https://forge.codesys.come86fa4b6ee641a0cebae46b993411f6345380755</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;There is no NAME_OF function in Berghof libraries.&lt;/p&gt;
&lt;p&gt;IMHO the Name of your variable has to be hard coded as string.&lt;/p&gt;
&lt;p&gt;The easiest way is to convert your variables with functions like UINT_TO_STRING.&lt;/p&gt;
&lt;p&gt;By pressing F2 in a source file you'll get all the available conversion functions implemented in CoDeSys&lt;/p&gt;
&lt;p&gt;the INI lib should come with your Berghof Target.&lt;/p&gt;
&lt;p&gt;I use this lib very frequently. But until now I haven't found a way to automatically generate Names and parse them back again. This still has to be done manually.&lt;/p&gt;
&lt;p&gt;hope this helps  &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Backup variable to a file.</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/0705dad894/?limit=25#c406" rel="alternate"/><published>2020-02-27T23:30:49.795000Z</published><updated>2020-02-27T23:30:49.795000Z</updated><author><name>swtroelofs</name><uri>https://forge.codesys.com/u/swtroelofs/</uri></author><id>https://forge.codesys.com394d4954bd6d4711c5f10f8f685aa35606b473fc</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;Here's a question:&lt;/p&gt;
&lt;p&gt;I've got a program with a couple hundred variables. For our customer it is important &lt;/p&gt;
&lt;p&gt;to be able to save those settings to a file, and load new settings from a file. I'm &lt;/p&gt;
&lt;p&gt;looking for the easiest way to program this. &lt;/p&gt;
&lt;p&gt;Is it possible to read the name of a variable as a string? &lt;/p&gt;
&lt;p&gt;For example: I've got a variable: rPitch with a value of 3. I would like to&lt;/p&gt;
&lt;p&gt;program something like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;CONCAT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CONCAT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NAME_OF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rPitch&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="s1"&gt;'='&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;rPitch&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;with the result: 'rPitch=3'&lt;/p&gt;
&lt;p&gt;Only thing is, the NAME_OF command does not exist &lt;br/&gt;
Anybody got any idea's?&lt;/p&gt;
&lt;p&gt;One more thing: I've got the library: 'ini_file_v10'. It allows me to create .ini files. &lt;br/&gt;
Has anybody got any experience with this library? Or does it only come with my &lt;br/&gt;
PLC (Berghof)?&lt;/p&gt;
&lt;p&gt;Thanks!```&lt;/p&gt;
&lt;p&gt;```&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>