/// <summary>
 /// The users program should call this if a flash storage device has been attached which may contain credentials for the home network in the file specified by CredentialsFilename  
 /// The flash storage wil be searched for the CredentialsFilename file, and if this does not exist it will be created with instructions for use.
 /// </summary>
 /// <param name="storageDevice">The storage device.</param>
 public void StorageAttached(GT.StorageDevice storageDevice)
 {
     var file = storageDevice.Open(CredentialsFilename, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
     if (file.Length == 0)
     {
         // write to file
         file.Write(Encoding.UTF8.GetBytes(storageInstructions), 0, storageInstructions.Length);
         file.Close();
         Debug.Print("No credentials file on storage device; wrote instructions");
     }
     else
     {
         byte[] buf = new byte[(int)file.Length];
         int len = file.Read(buf, 0, (int)file.Length);
         if (len != file.Length)
         {
             Debug.Print("Error: cannot read credentials file " + CredentialsFilename);
         }
         else
         {
             string fileContents = new string(Encoding.UTF8.GetChars(buf));
             bool newnetwork = false;
             foreach (string s in fileContents.Split('\n'))
             {
                 var strim = s.Trim();
                 if (strim.Length < 2 || strim.Substring(0, 2) == "//") continue;
                 if (ParseSSIDKey(strim))
                 {
                     newnetwork = true;
                 }
                 else
                 {
                     Debug.Print("Error: invalid line in credentials file: " + strim);
                 }
             }
             if (newnetwork)
             {
                 SaveData();
                 SetLed();
             }
         }
     }
 }