<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to How to Save a csv file on SD Card</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f3cac91ce8/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f3cac91ce8/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f3cac91ce8/</id><updated>2020-02-27T22:41:35.405000Z</updated><subtitle>Recent posts to How to Save a csv file on SD Card</subtitle><entry><title>How to Save a csv file on SD Card</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f3cac91ce8/?limit=25#6228" rel="alternate"/><published>2020-02-27T22:41:35.405000Z</published><updated>2020-02-27T22:41:35.405000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.comb5d167c4d7b2f47fa023052adac23d9f5a156022</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; barkamharikrishna&lt;/p&gt;
&lt;p&gt;Please see belwo code to create csv file and write data to csv file &lt;/p&gt;
&lt;p&gt;VAR   &lt;br/&gt;
    s_filePath          : STRING := '/opt/CoDeSysControl/log/';             (&lt;em&gt;Path to save .csv file in to the ROM of controller    &lt;/em&gt;) &lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;t_handle := SysFileOpen(szFile := s_filePath,am := AM_APPEND_PLUS,pResult := ADR(t_error));&lt;br/&gt;
    S_WriteBuffer := (''); &lt;br/&gt;
    S_WriteBuffer := concat(S_WriteBuffer,WORD_TO_STRING(u16_ErrNum)); &lt;br/&gt;
    S_WriteBuffer := concat(S_WriteBuffer,'-'); &lt;br/&gt;
    S_WriteBuffer := concat(S_WriteBuffer, BYTE_TO_STRING(u8_ErrCode));&lt;br/&gt;
    S_WriteBuffer := concat(S_WriteBuffer,'-'); &lt;br/&gt;
    S_WriteBuffer := concat(S_WriteBuffer, BYTE_TO_STRING(u8_ErrClass));&lt;br/&gt;
    S_WriteBuffer := concat(S_WriteBuffer,'#'); &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;S_WriteBuffer&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&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;S_WriteBuffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'$n'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;SysFileWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hFile&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t_handle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;pbyBuffer&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;S_WriteBuffer&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;ulSize&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;S_WriteBuffer&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;pResult&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t_error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="n"&gt;SysFileClose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hFile&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t_handle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>How to Save a csv file on SD Card</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f3cac91ce8/?limit=25#b732" rel="alternate"/><published>2020-02-27T22:41:33.823000Z</published><updated>2020-02-27T22:41:33.823000Z</updated><author><name>InTheBox</name><uri>https://forge.codesys.com/u/inthebox/</uri></author><id>https://forge.codesys.comfbfe7f575dfa080ecbeaea000d4ea13f64395fcb</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thank you for the answers.&lt;br/&gt;
I just discovered that my ABB PLC doesn't give complete conformity to some standard CoDeSys libraries involved with hardware (SD-card handling in my case).&lt;br/&gt;
I'm gonna switch to ABB proprietary libraries.&lt;/p&gt;
&lt;p&gt;Bye.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to Save a csv file on SD Card</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f3cac91ce8/?limit=25#a400" rel="alternate"/><published>2020-02-27T22:41:29.395000Z</published><updated>2020-02-27T22:41:29.395000Z</updated><author><name>swtroelofs</name><uri>https://forge.codesys.com/u/swtroelofs/</uri></author><id>https://forge.codesys.com6cf0ea4591cdc7bef9b417e596c0f4cf1f9e4311</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have a PLC with a linux os. When I write a file to an USB stick I use the following path:&lt;br/&gt;
'/media/usb0/MyFile.csv'&lt;/p&gt;
&lt;p&gt;Also note that linux is CaSe sensitive. I once lost half a day because i used: '/Media/usb0/'  &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to Save a csv file on SD Card</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f3cac91ce8/?limit=25#83e0" rel="alternate"/><published>2020-02-27T22:41:27.783000Z</published><updated>2020-02-27T22:41:27.783000Z</updated><author><name>KiranK</name><uri>https://forge.codesys.com/u/kirank/</uri></author><id>https://forge.codesys.com79b5b2a2b1e2343837f97bbf6fac2e5698334de3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;InTheBox hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
No, I'm not.&lt;br/&gt;
Is the path "MyFile.csv" wrong too? Isn't it supposed to be in the current directory?&lt;br/&gt;
"SysFileOpen" should create the file if it doesn't exist.&lt;br/&gt;
This function returns a file number &amp;gt; 0, but even after writing and closing the file, I'm not able to find it. I tried with the "filedir" command too, with no results.&lt;br/&gt;
If my SD-Card contains a directory called "\Data\" (sub-directory of root), is it enough to indicate "\Data\MyFile.csv" as path?&lt;br/&gt;
I did this way but in the card there is no trace of the file, although the functions return no errors.&lt;br/&gt;
Thank you.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Hi,&lt;br/&gt;
As per my exp when the file SysFileOpen will not create a new file but it will return a value(u are right)&lt;br/&gt;
This will only open the file.&lt;br/&gt;
Path what u have specfied '\Data\MyFile.csv' is correct(u should use single quotes '')&lt;br/&gt;
Now i belive u are expecting that the system should read and creat a file then NO &lt;br/&gt;
it will just read the file and you have to specfy another file in the same directory say '\Data\MyFile1.csv' and use write function kindly refer the attched sample plc code for read/write functions.&lt;br/&gt;
I hope this should work&lt;br/&gt;
an tel me what happens ok&lt;br/&gt;
Regards&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=296" rel="nofollow"&gt;WriteReadFile.pro &lt;span&gt;&lt;span&gt;[32.43 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to Save a csv file on SD Card</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f3cac91ce8/?limit=25#854e" rel="alternate"/><published>2020-02-27T22:41:26.204000Z</published><updated>2020-02-27T22:41:26.204000Z</updated><author><name>InTheBox</name><uri>https://forge.codesys.com/u/inthebox/</uri></author><id>https://forge.codesys.com490902b90e9fe717883c9dc059b7ca1e0b2f8d23</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;KiranK hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Are u trying to run this in simulation mode at ur PC ?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;No, I'm not.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;KiranK hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
If NO, then I think you your path which u have specfied (e.g.: "C:.....\MyFile.csv") and relative (e.g.: "\MyFile.csv", "MyFile.csv"")  is wrong.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Is the path "MyFile.csv" wrong too? Isn't it supposed to be in the current directory?&lt;br/&gt;
"SysFileOpen" should create the file if it doesn't exist.&lt;br/&gt;
This function returns a file number &amp;gt; 0, but even after writing and closing the file, I'm not able to find it. I tried with the "filedir" command too, with no results.&lt;br/&gt;
If my SD-Card contains a directory called "\Data\" (sub-directory of root), is it enough to indicate "\Data\MyFile.csv" as path?&lt;br/&gt;
I did this way but in the card there is no trace of the file, although the functions return no errors.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to Save a csv file on SD Card</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f3cac91ce8/?limit=25#21a0" rel="alternate"/><published>2020-02-27T22:41:21.772000Z</published><updated>2020-02-27T22:41:21.772000Z</updated><author><name>KiranK</name><uri>https://forge.codesys.com/u/kirank/</uri></author><id>https://forge.codesys.comca0554aa4d60e16a1d554f6b2b520bd2fee1393a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;InTheBox hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Hi, I need to work with csv files and save them on SD-Card.&lt;br/&gt;
In "CoDeSys -&amp;gt; Help -&amp;gt; SD_WRITE" section there is this note:&lt;br/&gt;
Actually I found examples that don't seem to use this block.&lt;br/&gt;
If it is possible to write on SD-Cards just using SysFileOpen - SysFileWrite - SysFileClose, how can I know the "partition" on which the plc "mounts" the card? I tried many combinations of full (e.g.: "C:.....\MyFile.csv") and relative (e.g.: "\MyFile.csv", "MyFile.csv"") paths with no results.&lt;br/&gt;
Where am I wrong?&lt;br/&gt;
Thank you very much.&lt;br/&gt;
Alessandro&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Hi,&lt;br/&gt;
My first Question:&lt;br/&gt;
Are u trying to run this in simulation mode at ur PC ?&lt;br/&gt;
If yes then it is not possible .&lt;br/&gt;
If NO, then I think you your path which u have specfied (e.g.: "C:.....\MyFile.csv") and relative (e.g.: "\MyFile.csv", "MyFile.csv"")  is wrong.&lt;br/&gt;
You should mention in this way '\data\MyFile.csv' &lt;br/&gt;
data is the folder in which u have kept ur file &lt;br/&gt;
In your case kindly mention the name of the file in which the file is kept i have just given an example &lt;br/&gt;
Hope this helps &lt;br/&gt;
regards&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to Save a csv file on SD Card</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f3cac91ce8/?limit=25#161a" rel="alternate"/><published>2020-02-27T22:41:20.185000Z</published><updated>2020-02-27T22:41:20.185000Z</updated><author><name>InTheBox</name><uri>https://forge.codesys.com/u/inthebox/</uri></author><id>https://forge.codesys.com202de2a1218aefd9e72515823f0487f56afac52a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi, I need to work with csv files and save them on SD-Card.&lt;br/&gt;
In "CoDeSys -&amp;gt; Help -&amp;gt; SD_WRITE" section there is this note:&lt;/p&gt;
&lt;p&gt;Actually I found examples that don't seem to use this block.&lt;br/&gt;
If it is possible to write on SD-Cards just using SysFileOpen - SysFileWrite - SysFileClose, how can I know the "partition" on which the plc "mounts" the card? I tried many combinations of full (e.g.: "C:.....\MyFile.csv") and relative (e.g.: "\MyFile.csv", "MyFile.csv"") paths with no results.&lt;/p&gt;
&lt;p&gt;Where am I wrong?&lt;br/&gt;
Thank you very much.&lt;/p&gt;
&lt;p&gt;Alessandro&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>