Jump to content

Writing data to CSV file on SD card and size full reached


Recommended Posts

I am learning and first time trying program SD functions on V1040,  created delimiter lines to write to a CSV file on SD card,  I am using a 8G SD card. On the ladders how should program when the file size reaches to maximum and SD card is full.  Is it possible to program like writing to data table by scrolling down and only writing first row then let the last out of the table.  But how to do this on SD card?  I simply don't want data logging stopped when SD is full. Is this possible?  Could any one help to explain or show an example?

Link to comment
Share on other sites

Each individual folder within the SD card can contain a maximum of 64 files. If you attempt to save an additional file it will not be saved to the SD folder as it is full. To prevent this form happening it is recommended to track how many files have been saved. Each time a file is saved you can increment a value within the logic. When a value of 64 is reached you can then start saving to a different folder. Once all the folders are full you will then need to removed the files from the card.

 

You can choose to indirectly save to each file folder using a value. The numeric addresses for the SD folder are as follows:

 

  • Alarms: 0
  • DT main folder: 1
  • DT1–4: 101 to 103
  • Log: 3
  • System: 4
  • User_app: 5
  • Trends main folder - 600
  • Trends1-4: 600 to 603
  • SdBLocks: 9
  • Excel main folder: 100
  • Excel1-4: 1000 to 1003
  • Web: 11
Link to comment
Share on other sites

If I only write to one file under EXCEL1 folder, writing one line say every 10 seconds,  I assumed the size of this file will reaches maximum size of the SD card, am I right?  My question is what does the PLC do when SD is full? does it generate a fault or alarm and stop running or does nothing and the rest of ladders will be still running?   This is important. We don't want program stop because of this.

Link to comment
Share on other sites

Have you calculated how much data you're actually producing to see if it's worth it to worry?

 

I only ask because I have CSV files I've been generating over the last year where each line contains 50-60 characters, including commas.  I have 302,000 lines of data which only make up 17MB of file space.  With 8GB I could hold roughly 143,800,000 lines of data which would take me 476 years to generate at the current pace.

 

You're more likely to run into file system file size limits with and SD card as FAT32, depending on the version is limited to 2GB, 4GB, or 256GB.  Most likely you're going to be limited to 2GB or 4GB on the SD card base FAT32 file system.

 

Link to comment
Share on other sites

I do apologize for the additional post without editing but my previous post was not approved yet.

 

Alternatively, you can use SI66, bit 3, error writing to file, and bit 6, SD card full bit, to evaluate the state of your card.

 

Pages 228-233 in the Ladder Programming manual has a complete list of the system bits for SD functions you can use.

 

*edit*

 

SDW59 reports remaining space on the SD card as the number of 512 byte chunks.   If SDW59 reads 20, you then have 20x512 = 10,240 bytes of space remaining.
 

Another thing to consider, which I found in another post, the PLC writes to the card in 512 byte chunks regardless of the data written.  To use it better you need to approach the write operation differently.


 

Link to comment
Share on other sites

Thanks a lot for the cantcliff's comments. It is very helpful. 

 

The time it takes to fill up SD depends on three figures: SD capacity, bytes used to write each line and write interval.  If your interval is 1 seconds, and data of 500 bytes each line, it will not take many years to fill full.

 

I feel that reading SDW59 is a good solution.  For instance, if SDW59 reads 10, so only 5120 bytes remaining, then I may use this to create a bit to show an alert on HMI also stopped from writing data to SD.  

 

But I am just curious to know how the SD write function block was defined when SD is full.  I believe the function shall check this every time trying to write to SD.  I just could not find more information on manual to indicate what program will behave when SD is full.  Must I use controls such as reading SDW59 or other method to monitor SD space on every program scan?  I also looked the SD examples and watched webinars. I don't not feel clear about this.  

 

Simply my questions are:

 

  1) What does the block or program do if SD is full during scan?

  2) Do I have to monitor the remaining space on SD card? Or is it also safe without?

 

I am sure Unitronics R&D team would be able to provide more information on this?  

 

I concern about this as I have seen many applications are linked to  safety control system.  In this case, cause and effect can be crucial for the risk involved.

Link to comment
Share on other sites

Once the SD card is full you will not be able to write any additional data to the card.

 

As Cantcliff mentioned you can monitor SDW 59 which will shows the free space available on the SD card in 512 byte chunks. You can also monitor SI 66 which functions as a status message bitmap for the SD card. Bit 6 within SI 66 will go high when the card is full.

 

Mostly you will need to keep track of how many files have been written to each folder. You will need to write to an additonal file, or remove/delete files from the SD card in order to fill up space. Any logic to perform these actions will need to be implemented by the programmer.

Link to comment
Share on other sites

It is absolutely sure thing that you will not be able to write anything to SD when it is full.

 

Again, I will only need to write data on one file to SD, I don't see a point why make it complicated to build many files as you suggested.  Unless there is maximum size limitation for one file? Can you explain Alexander?

 

Of course I can monitor SDW59 or SI66 and so on to control program.  That does not answer my question.   

 

I am looking for answers to question 1 & 2 still.  

    1) What does the block or program do if SD is full during scan?    

    2) Do I have to monitor the remaining space on SD card? Or is it also safe without?
 
 
I am programming this product.  Function blocks are defined by manufacturer so they shall be able to answer.  Any technical support from Unitronics?
   
Please tell me if question is not clear. 
Link to comment
Share on other sites

I do work for Unitronics within the technical support team.

 

There is no way to write additional information to a full SD card. This is a hardware limitation with any type of memory storage device.

 

Each function block within our software related to SD functions will have a status message. The write to SD function utilizes a bitmap to indicate multiple status messages. In your case the Write SD Delimited line will have bit 4 go high which indicates that the SD card is full.

 

Monitoring SI 66, which is also a bitmap for the SD card you can see general information regarding the SD card. When you attempt to write to the card when it is full generally bit 3 and 5 will become active. Bit 3 indicates that the were an error writing to the file, and bit 5 indicates that the file was unable to be closed. This is likely due since the process was unable to complete all required steps.

 

If you are only writing a single file then you will not need to worry about switching to different folders, I only wanted to mention this in case you needed to perform other functions. We would still recommend monitoring the amount of space left on the card so that you do not run into a situation where the SD card is already full.

Link to comment
Share on other sites

  • 3 weeks later...

Ozone,

 

The reason that you can record more than one file is that exact reason. If you want to record something to 1 excel .CSV file and then something else to another, allowing multiple files allows you write to the specific files instead of stacking all the information into one file. Stacking it all in one file would probably result is space being used that doesn't necessarily need to be used (i.e. if I wanted to record item 1 and not 2 the .csv would still create a blank cell for me not recording anything).

 

As far as knowing when your SD card is full I would do some simple math, determine the rate which you retrieving data (1 recording is XX MBs) and then set a limit to where the PLC triggers an alarm that the SD card is close to being full allowing your user to replace / clear the SD card before it actually gets to the point where it can't record anymore.

 

^^ that being said, can someone confirm that when the SD card is full and the code calls for a recording that the code doesn't crash or get locked into a dump?

Link to comment
Share on other sites

dan_lorentz,

 

Surely it can be one by numbers of ways. But again I've been asking the same questions as you questioned too on your last line word.  

 

Alexander,

 

Could we have a straight answer(Yes or No) to the question " will the PLC or the code crash when SD is full ....?" 

Link to comment
Share on other sites

Ozone,

 

I hear you on not getting an answer, that is why I suggest using the register method to protect yourself so you can move forward with your project without waiting to find out. You could also use a certain register number (value), that once reached doesn't allow any writing to the SD card. Kind of a built in safety net.

Link to comment
Share on other sites

You can use SI66, bit 6, "SD is full" or SI68, bit 7, "Write error" to monitor your SD card.  Page 231 and 232 (PDF page 239 and 240) of the Ladder Programming PDF.

 

Whether or not the program crashes is dependent on how you write your program and use the above information.  Poorly written, it will crash, well written it will not.

Link to comment
Share on other sites

dan_lorentz,

 

Surely it can be one by numbers of ways. But again I've been asking the same questions as you questioned too on your last line word.  

 

Alexander,

 

Could we have a straight answer(Yes or No) to the question " will the PLC or the code crash when SD is full ....?" 

 

Hello Ozone,

When the SD card is full, bit 6 in SI66 will turn on. 

No PLC crashing (or other functionlities) is related to that case.

Link to comment
Share on other sites

  • 1 year later...

Hello everybody,

I have related question to this topic. Can it be programmed the way, that when SD card is full, the oldest .CSV file gets overwritten by the newest data? Or the only solution is to retrieve all files from SD and clear the card? I ask it because in my system we only need to check the content of SD when any fault occurs. So basically we would need info for last 3 months, in case of fault. So in normal operating mode it would be good to have the newest data, refreshing all the time.

Thank You.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...