CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Fri Jul 28, 2017 1:40 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Mar 23, 2012 12:46 pm 
Offline

Joined: Fri Mar 23, 2012 11:05 am
Posts: 3
Hi, I need to work with csv files and save them on SD-Card.
In "CoDeSys -> Help -> SD_WRITE" section there is this note:

Access to the SD Card is only possible by using the function blocks SD_WRITE and SD_READ.

Actually I found examples that don't seem to use this block.
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.

Where am I wrong?
Thank you very much.

Alessandro


Top
   
PostPosted: Fri Mar 23, 2012 1:47 pm 
Offline

Joined: Mon Mar 12, 2012 11:25 am
Posts: 18
InTheBox wrote:
Hi, I need to work with csv files and save them on SD-Card.
In "CoDeSys -> Help -> SD_WRITE" section there is this note:

Access to the SD Card is only possible by using the function blocks SD_WRITE and SD_READ.

Actually I found examples that don't seem to use this block.
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.

Where am I wrong?
Thank you very much.

Alessandro


Hi,
My first Question:
Are u trying to run this in simulation mode at ur PC ?
If yes then it is not possible .
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.
You should mention in this way '\data\MyFile.csv'
data is the folder in which u have kept ur file
In your case kindly mention the name of the file in which the file is kept i have just given an example
Hope this helps :)
regards


Top
   
PostPosted: Fri Mar 23, 2012 2:24 pm 
Offline

Joined: Fri Mar 23, 2012 11:05 am
Posts: 3
KiranK wrote:
Are u trying to run this in simulation mode at ur PC ?

No, I'm not.

KiranK wrote:
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.

Is the path "MyFile.csv" wrong too? Isn't it supposed to be in the current directory?
"SysFileOpen" should create the file if it doesn't exist.
This function returns a file number > 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.
If my SD-Card contains a directory called "\Data\" (sub-directory of root), is it enough to indicate "\Data\MyFile.csv" as path?
I did this way but in the card there is no trace of the file, although the functions return no errors.

Thank you.


Top
   
PostPosted: Fri Mar 23, 2012 3:52 pm 
Offline

Joined: Mon Mar 12, 2012 11:25 am
Posts: 18
InTheBox wrote:
KiranK wrote:
Are u trying to run this in simulation mode at ur PC ?

No, I'm not.

KiranK wrote:
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.

Is the path "MyFile.csv" wrong too? Isn't it supposed to be in the current directory?
"SysFileOpen" should create the file if it doesn't exist.
This function returns a file number > 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.
If my SD-Card contains a directory called "\Data\" (sub-directory of root), is it enough to indicate "\Data\MyFile.csv" as path?
I did this way but in the card there is no trace of the file, although the functions return no errors.

Thank you.


Hi,
As per my exp when the file SysFileOpen will not create a new file but it will return a value(u are right)
This will only open the file.
Path what u have specfied '\Data\MyFile.csv' is correct(u should use single quotes '')
Now i belive u are expecting that the system should read and creat a file then NO
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.
I hope this should work
an tel me what happens ok
Regards


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Tue Mar 27, 2012 9:39 am 
Offline

Joined: Thu Apr 24, 2008 11:15 am
Posts: 23
I have a PLC with a linux os. When I write a file to an USB stick I use the following path:
'/media/usb0/MyFile.csv'

Also note that linux is CaSe sensitive. I once lost half a day because i used: '/Media/usb0/' :?


Top
   
PostPosted: Tue Mar 27, 2012 9:58 am 
Offline

Joined: Fri Mar 23, 2012 11:05 am
Posts: 3
Thank you for the answers.
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).
I'm gonna switch to ABB proprietary libraries.

Bye.


Top
   
PostPosted: Fri Aug 26, 2016 6:45 am 
Offline

Joined: Thu Jun 09, 2016 5:32 am
Posts: 36
Location: memmingen,germany
Please see belwo code to create csv file and write data to csv file

VAR
s_filePath : STRING := '/opt/CoDeSysControl/log/'; (*Path to save .csv file in to the ROM of controller *)
END_VAR



t_handle := SysFileOpen(szFile := s_filePath,am := AM_APPEND_PLUS,pResult := ADR(t_error));
S_WriteBuffer := ('');
S_WriteBuffer := concat(S_WriteBuffer,WORD_TO_STRING(u16_ErrNum));
S_WriteBuffer := concat(S_WriteBuffer,'-');
S_WriteBuffer := concat(S_WriteBuffer, BYTE_TO_STRING(u8_ErrCode));
S_WriteBuffer := concat(S_WriteBuffer,'-');
S_WriteBuffer := concat(S_WriteBuffer, BYTE_TO_STRING(u8_ErrClass));
S_WriteBuffer := concat(S_WriteBuffer,'#');

S_WriteBuffer := concat(S_WriteBuffer,'$n');
SysFileWrite(hFile := t_handle,pbyBuffer := ADR(S_WriteBuffer),ulSize := len(S_WriteBuffer),pResult := ADR(t_error));
SysFileClose(hFile := t_handle);


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited