I am working on a program which logs data to a SD. The filename contains the date and time.
When looking at the files on the SD I noticed that while the filename was correct, the creation date of the that showed up on a PC was wrong.
I also noticed that when creating a file on the SD, captialization is required for the filesystem name. \sd\ does not work. \SD\ does?
Following is a code sample which demonstrates how I am setting the real-time and .NETMF clock, writting to the SD, and looking at the resultant times for the new file.
using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.Hardware;
namespace SDTests
{
public class Program
{
public static void Main()
{
// see if real-time clock has been set
if (!RealTimeClock.IsTimeValid)
{
Debug.Print("Setting real-time clock");
RealTimeClock.SetTime(new DateTime(2010, 07, 03, 21, 30, 00));
}
else
{
Debug.Print("Real-time clock is valid");
}
// set the NETMF clock from the real-time clock
Utility.SetLocalTime(RealTimeClock.GetTime());
Debug.Print("Current time is " + DateTime.Now.ToString());
// wait for sd to be recognized
while (!PersistentStorage.DetectSDCard())
{
Thread.Sleep(100);
}
// mount sd
PersistentStorage sdPS = new PersistentStorage("SD");
sdPS.MountFileSystem();
//StreamWriter wr = new StreamWriter("\\sd\\Test.txt", false); // causes exception
StreamWriter wr = new StreamWriter("\\SD\\Test.txt", false);
// write to file
for (int i = 1; i <= 10; i++)
wr.WriteLine("Line " + i.ToString());
// close file
wr.Flush();
wr.Close();
VolumeInfo.GetVolumes()[0].FlushAll();
// see what is on SD
String[] files = Directory.GetFiles("\\SD\\");
for (int i = 0; i < files.Length; i++)
{
FileInfo info = new FileInfo(files[i]);
Debug.Print(files[i] + " CreationTime: " + info.CreationTime.ToString());
Debug.Print(files[i] + " LastAccessTime: " + info.LastAccessTime.ToString());
Debug.Print(files[i] + " LastWriteTime: " + info.LastWriteTime.ToString());
File.Delete(info.FullName);
}
Thread.Sleep(Timeout.Infinite);
}
}
}
The program output:
Real-time clock is valid
Current time is 07/03/2010 22:19:33
\SD\Test.txt CreationTime: 01/01/1985 00:28:49
\SD\Test.txt LastAccessTime: 01/01/1985 00:00:00
\SD\Test.txt LastWriteTime: 01/01/1985 00:28:48
What have I done wrong?
Thanks,
Mike