本文整理汇总了C#中Gadgeteer.Open方法的典型用法代码示例。如果您正苦于以下问题:C# Gadgeteer.Open方法的具体用法?C# Gadgeteer.Open怎么用?C# Gadgeteer.Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gadgeteer
的用法示例。
在下文中一共展示了Gadgeteer.Open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StorageAttached
/// <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();
}
}
}
}