CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Sun May 28, 2017 11:24 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
 Post subject: read big csv file
PostPosted: Wed Apr 05, 2017 8:37 am 
Offline
User avatar

Joined: Fri Jul 05, 2013 9:54 am
Posts: 58
in order to read a csv file, I usually use the FILE.Read FB from File from CAA_File.Library
Attachment:
05-04-2017 09-34-59.jpg


The read data is stored into the the ADR(buff) area: how get big amount of data? (buffer size >xxxxxxxxxxxxx): Get multiple file-read?how to split reading operations?


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


Top
   
 Post subject: Re: read big csv file
PostPosted: Thu May 11, 2017 10:34 pm 
Offline
User avatar

Joined: Fri May 08, 2015 10:18 pm
Posts: 17
Location: OKC, USA
Hi!

If I may hook into your thread..

Do you have any luck with this?
Are you able to do this with smaller csv files?
Where do you store your csv?


Top
   
 Post subject: Re: read big csv file
PostPosted: Fri May 12, 2017 8:59 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 105
Hi.

For reading csv, first i ask about csv size using sysfile.getsize, after that i make a __new(byte,size+1) over a byte pointer.

To read values, you can create an array of arrays of pointer to string (first array are rows). You can go over the big array pointing the strings after field separators and subst the field separator by an 0. (End line changes first array).

You can put all inside a fb and acces fields via get(x,y).

Don't forget to destroy dynamic memory previous a new read and destroy it in fb_exit.

To write csv, the dynamic array is a little bit mor complicated.


Top
   
 Post subject: Re: read big csv file
PostPosted: Sun May 14, 2017 10:50 pm 
Offline
User avatar

Joined: Fri May 08, 2015 10:18 pm
Posts: 17
Location: OKC, USA
Thanks for the explanation!

Any chance you could post some example code/project?

I got it to work, but am looking at individual bytes (ASCII) and combining/converting those to INTEGER values. I am sure there are more elegant ways of doing this..


Top
   
 Post subject: Re: read big csv file
PostPosted: Mon May 15, 2017 10:20 am 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 105
Hi.

this is a simplified example:

Attachment:
Captura de 2017-05-15 11-16-43.png


I recomend to you that a buffer be in a separate FB which manages the construction and destruction of it,

The same for the double array, an FB with the double array and get and set methods to control array bounds.

In array creation add 1 byte more to put the last string 0.


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


Top
   
 Post subject: Re: read big csv file
PostPosted: Mon May 15, 2017 1:34 pm 
Offline
User avatar

Joined: Fri May 08, 2015 10:18 pm
Posts: 17
Location: OKC, USA
Thank you so much! :)


Top
   
 Post subject: Re: read big csv file
PostPosted: Mon May 15, 2017 3:31 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 105
Hi.

I made some mistakes on last code (in _new):

Attachment:
Captura de 2017-05-15 16-27-40.png


That is a resume of my code. You have to manage errors on case of reading fail. And at the end parse code over strings is not filled.

I have not test it, it could contain some mistakes,


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


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 7 guests


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