Mikeaks

How to loop a datalog on NA5

7 posts in this topic

Hello Guys,

I would like to know if someone in here has made a VB script, there can delete files from the SD card in HMI?
the reason why I ask, is I have some data logging on the HMI for our customer, but I would like the data logging to go in a loop so if the  SD-card is full, it will
delete the oldest file instead of stop data logging.

who is there somebody there can show me an example on a VB for this :)?

Share this post


Link to post
Share on other sites

Here is a quick and dirty way to do it. Run it hourly as a scheduled event. Just change 6 to however many days you want to keep logs. 6 = 5 days, 23 = 22 days etc. You'll need to use this for every data set so if you have 3 data sets just cut and paste into 3 subroutines with the appropriate modifications to the directory. Every time you run it it deletes 1 folder only (if the folder is old enough) so if you have a massive backlog you need to delete I would do it manually first.

 

Sub clearCard
Dim List_Files As String()
Dim i As Integer

List_Files = System.IO.Directory.GetDirectories("\SDCard\Data Logging\Log Files\DataSet0")
'Change DataSet0 to whatever data set you need
Array.Sort(List_Files)

Array.Reverse(List_Files)


'This will sort so the most recent dates are at the start of the array
i =  List_Files.Length

    If i > 6 Then
        'Change 6 to whatever value you desire. This is essentially how many days you keep files. 5 days = 6       
                System.IO.Directory.Delete(List_Files(6), True)
    End If
    
End Sub

Edited by photovoltaic
clarity

Share this post


Link to post
Share on other sites

Thanks, @photovoltaic, I have one question about this. Do you write that I have to run I hourly?
is it the subroutine or the datalog( I have attached a picture of where I think you mean I have to change it to hourly)?

 
Right now when I run the code, I get this error:
 

Quote

IndexOutOfRangeException is thrown at clearCardFM01.
E_SYS_999: IndexOutOFRangeException 

 

datalog.jpg

Share this post


Link to post
Share on other sites

I will clarify a bit - so the folders that this macro looks at are the daily folders, you can have any setting in the update rate and "Start New Database File" section as long as you are saving the data at least once a day. Any longer than that and you need to make adjustments. I think your issue is from the Data Set name - in your multiview explorer under datalogging what did you name your dataset?

To test this I would use a button to trigger the script at first. Check how many daily log folders are on your SD card before you do this and then run it say 5 times and then check to see there are 5 fewer folders. Once you confirm operation then have the macro run from global events as an hourly interval.

Share this post


Link to post
Share on other sites

Thanks, I will try to use the idea you came with, and add a button to trigger it :).

The example I have shown it is named FM01, I have  6 different data set I have copied the code in for and I have modified the code to each dataset and set in different days they should delete here at the start. and it seems like I get the error when it is trying to delete the oldest file.
but let me come back to you when I have tried with a button to trig the script :)
 

Share this post


Link to post
Share on other sites

Thanks again @photovoltaic, I got it to work :).

I was wondering is their option or opportunity to access the SD card and see how much memory there's left on the card.
and then remove using the instruction to delete files if we are running out of space :)

Share this post


Link to post
Share on other sites

I'm not aware of any, but I'm far from a VB whiz.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now