Beispiel #1
0
        public static void LogTemperature(object obj)
        {
            LedRed.Write(true);
            var tickStart = Utility.GetMachineTime().Ticks;
            var now       = Clock.Get();

            ThermoCouple.Read();
            var elapsedMs    = (int)((Utility.GetMachineTime().Ticks - tickStart) / TimeSpan.TicksPerMillisecond);
            var date         = AddZeroPrefix(now.Year) + "/" + AddZeroPrefix(now.Month) + "/" + AddZeroPrefix(now.Day);
            var time         = AddZeroPrefix(now.Hour) + ":" + AddZeroPrefix(now.Minute) + ":" + AddZeroPrefix(now.Second) + ":" + AddZeroPrefix(elapsedMs);
            var celsius      = Shorten(ThermoCouple.Celsius.ToString());
            var farenheit    = Shorten(ThermoCouple.Farenheit.ToString());
            var latestRecord = date + "," + time + "," + celsius + "," + farenheit;

            Debug.Print(latestRecord);
            try {
                if (CardDetect.Read() == false)
                {
                    var filename = SdMountPoint + BuildTemperatureLogFilename(now);
                    if (File.Exists(filename) == false)
                    {
                        using (var tempLogFile = new StreamWriter(filename, true)) {
                            tempLogFile.WriteLine("date,time,celsius,fahrenheit");
                        }
                    }
                    using (var tempLogFile = new StreamWriter(filename, true)) {
                        if (Buffer.Count != 0)
                        {
                            foreach (var bufferedLine in Buffer)
                            {
                                tempLogFile.WriteLine(bufferedLine);
                            }
                            Buffer.Clear();
                        }
                        tempLogFile.WriteLine(latestRecord);
                        tempLogFile.Flush();
                    }
                }
                else
                {
                    LogLine("No card in reader. Buffering record.");
                    Buffer.Add(latestRecord);
                }
                LedRed.Write(false);
            } catch (OutOfMemoryException e) {
                LogLine("Memory full. Clearing buffer.");
                Buffer.Clear();
            } catch (IOException e) {
                LogLine("IO error. Resetting peripherals.");
                Buffer.Add(latestRecord);
                ResetPeripherals.Set();
            }
        }
Beispiel #2
0
 public void ReadTemp()
 {
     ThermoCouple.Read();
     if (ThermoCouple.Celsius >= 28)
     {
         RelayStatus = true;
     }
     else
     {
         RelayStatus = false;
     }
     Relay.Activate(RelayStatus);
 }
Beispiel #3
0
        public static void Main()
        {
            var thermocouple = new Max6675();
            var relay        = new Relay();

            relay.Initialize(GoSockets.Socket8);
            thermocouple.Initialize(GoSockets.Socket7);
            while (true)
            {
                thermocouple.Read();
                if (thermocouple.Celsius < 21)
                {
                    relay.Activate(true);
                }
                else
                {
                    relay.Activate(false);
                }
                Debug.Print("Temp C:" + Shorten(thermocouple.Celsius.ToString()) + " / F:" + Shorten(thermocouple.Farenheit.ToString()));
                Thread.Sleep(1000);
            }
        }
Beispiel #4
0
 public static void ReadTemp()
 {
     Temp.Read();
     ComPort.Send("Temp (C): " + Temp.Celsius.ToString() + ", " /*"\r\n"*/);
 }