It happen the last time after the second time i started debugging again
here is the complete program
using System;
using System.IO;
using GHI.Hardware.G120;
using GHI.Premium.IO;
using GHI.Premium.USBClient;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
namespace ImpulseTester
{
public partial class Program
{
private const string FileName = @ "\SD\Test.TXT";
private readonly GT.Timer CkBTN = new GT.Timer(1000);
private readonly GT.Timer PressureReadtmr = new GT.Timer(100);
private readonly InputPort btn = new InputPort(Pin.P0_13, true, Port.ResistorMode.PullUp);
private readonly OutputPort led = new OutputPort(Pin.P3_26, false);
private readonly GT.Timer noSDtmr = new GT.Timer(500);
private readonly AnalogInput psi = new AnalogInput(Cpu.AnalogChannel.ANALOG_6);
private Boolean btnpos;
private DateTime dt;
private USBC_MassStorage ms;
private PersistentStorage sd;
private Boolean started;
private Stream stream;
// This method is run when the mainboard is powered up or reset.
private void ProgramStarted()
{
Debug.Print("Program Started");
ms = USBClientController.StandardDevices.StartMassStorage();
sd = new PersistentStorage("SD");
//sd.MountFileSystem();
////sd.UnmountFileSystem();
//VolumeInfo.GetVolumes()[0].Format("FAT", 0);
try
{
// sd.UnmountFileSystem();
ms.AttachLun(0, sd, " ", " ");
ms.EnableLun(0);
}
catch (Exception)
{
}
CkBTN.Tick += CkBTN_Tick;
PressureReadtmr.Tick += PressureReadtmr_Tick;
noSDtmr.Tick += noSDtmr_Tick;
CkBTN.Start();
}
private void noSDtmr_Tick(GT.Timer timer)
{
if (led.Read())
{
led.Write(false);
}
else
{
led.Write(true);
}
}
private void PressureReadtmr_Tick(GT.Timer timer)
{
try
{
using (Stream fs = File.Open(FileName, FileMode.Append))
using (var writer = new StreamWriter(fs))
{
//= 509.52x - 3.5777
writer.WriteLine(((DateTime.Now.Ticks - dt.Ticks) / 600000000.0).ToString("N3") + "," +
((509.52 * double.Parse(psi.Read().ToString("N3"))) - 8).ToString("N0"));
writer.Flush();
}
//stream.Flush();
//Debug.Print(((DateTime.Now.Ticks - dt.Ticks)/600000000.0).ToString("N3") + "," +
// ((509.52*double.Parse(psi.Read().ToString("N3"))) - 8).ToString("N0"));
//// ((psi.Read() - 0.0155)*2406).ToString("N0"));
}
catch (Exception)
{
PressureReadtmr.Stop();
stream.Flush();
stream.Dispose();
led.Write(false);
// Mainboard.UnmountStorageDevice("SD");
ms = USBClientController.StandardDevices.StartMassStorage();
sd.UnmountFileSystem();
ms.AttachLun(0, sd, " ", " ");
ms.EnableLun(0);
started = false;
noSDtmr.Start();
}
}
private void CkBTN_Tick(GT.Timer timer)
{
btnpos = btn.Read();
if (started && btnpos)
{
// Mainboard.UnmountStorageDevice("SD");
sd.UnmountFileSystem();
ms.AttachLun(0, sd, " ", " ");
ms.EnableLun(0);
PressureReadtmr.Stop();
led.Write(false);
started = false;
noSDtmr.Stop();
}
else if (!started && !btnpos && !noSDtmr.IsRunning)
{
try
{
ms.DisableLun(0);
sd.MountFileSystem();
// Mainboard.MountStorageDevice("SD");
dt = DateTime.Now;
started = true;
led.Write(true);
stream = File.Create(FileName);
stream.Dispose();
// writer = new StreamWriter(stream);
PressureReadtmr.Start();
}
catch (Exception)
{
// Mainboard.UnmountStorageDevice("SD");
started = false;
noSDtmr.Start();
// Mainboard.UnmountStorageDevice("SD");
sd.UnmountFileSystem();
ms.AttachLun(0, sd, " ", " ");
ms.EnableLun(0);
}
}
else if (btnpos && noSDtmr.IsRunning)
{
// Mainboard.UnmountStorageDevice("SD");
ms = USBClientController.StandardDevices.StartMassStorage();
sd.UnmountFileSystem();
ms.AttachLun(0, sd, " ", " ");
ms.EnableLun(0);
noSDtmr.Stop();
led.Write(false);
}
}
}
}
@ GHI is anyone looking into this?
i actually sent this device out to a colleague to use in a different location and am crossing my fingers that it wont happen there and is only happening during the debug.