public static void Main() { DS1307 RTC = new DS1307(); // Comment this line out to set the time for the first time //RTC.SetTime(Year: 2012, Month: 5, Day: 27, Hour: 22, Minute: 52, Second: 0); // Synchronises the Netduino with the DS1307 RTC module RTC.Synchronize(); while (true) { Debug.Print(DateTime.Now.ToString()); Thread.Sleep(1000); } }
public static bool HW_Init() { ALLINIT = false; try { ALLINIT = true; ONLINE = false; // LEDS OutPorts = new OutputPort[6]; OutPorts[(int)PINS.led_A] = new OutputPort(Pins.GPIO_PIN_A0, false); // Buttons RS485 OutPorts[(int)PINS.led_B] = new OutputPort(Pins.GPIO_PIN_A1, false); // WatchDog OutPorts[(int)PINS.led_C] = new OutputPort(Pins.GPIO_PIN_A2, false); // Ethernet OutPorts[(int)PINS.led_D] = new OutputPort(Pins.GPIO_PIN_A3, false); // Reader OutPorts[(int)PINS.Out_D9] = new OutputPort(Pins.GPIO_PIN_D9, true); // OutPorts[(int)PINS.RxTx] = new OutputPort(Pins.GPIO_PIN_D4, false); // DebugPrint("PINS SETTINGS ...... inicialized"); // RTC try { rtc = new DS1307(); rtc.Synchronize(); DebugPrint("RTC ................ inicialized, date and time: " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss")); } catch { DebugPrint("RTC ................ failed"); } // WatchDog wdt = new WatchDog(); // Reader ALLINIT = Reader.Init(); ReaderFw = Reader.GetFirmware(); DebugPrint("RFID ............... " + ReaderFw); // SD card SecureDigital.TreeCheck(); DebugPrint("SECURE DIGITAL ..... inicialized"); // Read data from SD card new Settings().Read(); new Blocking().Read(); // RS485 bool buttons = ALLINIT = (!ALLINIT) ? false : Buttons.Init(); if (buttons) { Buttons.Write(ALL, Screen.main); DebugPrint("RS485 .............. inicialized"); } else { DebugPrint("RS485 .............. failed"); } if (IPAddress.GetDefaultLocalAddress() != IPAddress.Any) //&& entryIP.AddressList[0].ToString() != NetworkInterface.GetAllNetworkInterfaces()[0].GatewayAddress { MacAddress = HexMacToSring((NetworkInterface.GetAllNetworkInterfaces()[0]).PhysicalAddress); IpAddress = IPAddress.GetDefaultLocalAddress().ToString(); Thread.Sleep(100); NETWORK = true; DebugPrint("NETWORK ............ inicialized"); DebugPrint("IP ADDRESS ......... " + IpAddress); DebugPrint("MAC ADDRESS ........ " + MacAddress); } else { DebugPrint("NETWORK ............ failed"); NETWORK = false; ALLINIT = false; } DebugPrint("AVAILABLE MEMORY ... " + Debug.GC(false).ToString()); Thread.Sleep(1000); if (NETWORK) { DebugPrint("LOADING SETTINGS ... waiting"); // Posílám dotaz nanastavení 5x for (int i = 0; i < 5; i++) { if (!Ethernet.Request("sn=" + settings.sn.ToString() + "&event=100&init=1")) { Thread.Sleep(1000); continue; } break; } if (READ_SETTINGS) { Ethernet.UniqueId(); DebugPrint("LOADING SETTINGS ... loaded"); // Check for files for (int i = 1; i <= settings.positions; i++) { SecureDigital.FileExists(@"SD\bottles\", "btl_" + i.ToString()); SecureDigital.FileExists(@"SD\calibration\", "cal_" + i.ToString()); } // Check buttons present for (int i = 1; i <= settings.positions; i++) { string result = String.Empty; bool res = (Buttons.Write(i)); allbuttons = (!allbuttons) ? false : res; result = (res) ? " respond" : " not respond"; DebugPrint("Position " + i.ToString() + result); } DebugPrint("LOADING BOTTLES .... waiting"); // Posílám dotaz nanastavení 5x for (int i = 0; i < 5; i++) { if (!Ethernet.Request("sn=" + settings.sn.ToString() + "&event=101&init=1")) { Thread.Sleep(1000); continue; } break; } if (CH_BOTTLE_OK) { Ethernet.UniqueId(); ONLINE = true; DebugPrint("LOADING BOTTLES .... loaded"); DebugPrint("LOADING DATETIME ... waiting"); Ethernet.Request("sn=" + settings.sn.ToString() + "&event=400&init=1"); if (DATETIME_OK) { Ethernet.UniqueId(); } } else { ALLINIT = false; DebugPrint("\r\nCOMMUNICATION ERROR: READ BOTTLES -> NO ANSWARE\r\n"); } } else { ALLINIT = false; DebugPrint("\r\nCOMMUNICATION ERROR: READ SETTINGS -> NO ANSWARE\r\n"); } } return true; } catch (Exception e) { DebugPrint(e.Message + " | " + e.StackTrace); NETWORK = false; return false; } }
public static void Main() { #if SD_ENABLED // If your Netduino can't execute the next line of code, make sure you got at least firmware 4.1.1 beta 1 // See also: http://forums.netduino.com/index.php?/topic/1592-netduino-firmware-v411-beta-1/ StorageDevice.MountSD("SD", SPI_Devices.SPI1, Pins.GPIO_PIN_D10); // Determines the filename string filename = ""; int index = 0; do { filename = @"\SD\LOGGER" + Tools.ZeroFill(index, 2) + ".CSV"; ++index; } while (File.Exists(filename)); // Starts writing to the file FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); // Writes file headers writer.WriteLine("ticks,datetime,light,temp"); #endif // LEDs OutputPort red = new OutputPort(Pins.GPIO_PIN_D2, false); OutputPort green = new OutputPort(Pins.GPIO_PIN_D3, false); // An analog light sensor IADCPort light = new Netduino.ADC(Pins.GPIO_PIN_A0); light.RangeSet(0, 1024); // An analog temperature sensor Tmp36 temperature = new Tmp36(new Netduino.ADC(Pins.GPIO_PIN_A1)); // Time module (comment out SetTime once, to set the clock) DS1307 time = new DS1307(); /*time.SetTime( Day: 11, Month: 8, Year: 2012, Hour: 12, Minute: 0, Second: 0 );*/ time.Synchronize(); while (true) { // Green status LED ON green.Write(true); // Builds the output string output = ""; output += DateTime.Now.Ticks.ToString() + ", "; output += DateTime.Now.ToString() + ", "; output += light.RangeRead().ToString() + ", "; output += temperature.Temperature.ToString(); // Prints the output to the debugger Debug.Print(output); #if SD_ENABLED // Writes the output to the SD buffer writer.WriteLine(output); #endif // Green status LED OFF, Red status LED ON green.Write(false); red.Write(true); #if SD_ENABLED // Flushes the buffers to the SD card writer.Flush(); stream.Flush(); #endif // Red status LED OFF red.Write(false); // Sleeps for a second Thread.Sleep(1000); } }
public static bool HW_Init() { // LEDS OutPorts = new OutputPort[6]; OutPorts[(int)PINS.led_A] = new OutputPort(Pins.GPIO_PIN_A0, false); // Buttons RS485 OutPorts[(int)PINS.led_B] = new OutputPort(Pins.GPIO_PIN_A1, false); // WatchDog OutPorts[(int)PINS.led_C] = new OutputPort(Pins.GPIO_PIN_A2, false); // Ethernet OutPorts[(int)PINS.led_D] = new OutputPort(Pins.GPIO_PIN_A3, false); // Reader OutPorts[(int)PINS.Out_D9] = new OutputPort(Pins.GPIO_PIN_D9, true); // OutPorts[(int)PINS.RxTx] = new OutputPort(Pins.GPIO_PIN_D4, false); // DebugPrint("PINS SETTINGS ...... inicialized"); // RTC try { rtc = new DS1307(); rtc.Synchronize(); Program.start = DateTime.Now; DebugPrint("RTC ................ inicialized, date and time: " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss")); } catch { DebugPrint("RTC ................ failed"); } // WatchDog wdt = new WatchDog(); // Reader Reader.Init(); ReaderFw = Reader.GetFirmware(); DebugPrint("RFID ............... " + ReaderFw); // SD card SecureDigital.TreeCheck(); DebugPrint("SECURE DIGITAL ..... inicialized"); // RS485 if (Buttons.Init()) { Buttons.Write(ALL, Screen.main); DebugPrint("RS485 .............. inicialized"); } else { DebugPrint("RS485 .............. failed"); } DebugPrint("LOADING SETTINGS ... waiting"); // Read data from SD card new Settings().Read(); DebugPrint("LOADING SETTINGS ... loaded"); // Check for files for (int i = 1; i <= settings.positions; i++) { SecureDigital.FileExists(@"SD\bottles\", "btl_" + i.ToString()); SecureDigital.FileExists(@"SD\calibration\", "cal_" + i.ToString()); } // Check buttons present for (int i = 1; i <= settings.positions; i++) { string result = String.Empty; bool res = (Buttons.Write(i)); allbuttons = (!allbuttons) ? false : res; result = (res) ? " respond" : " not respond"; DebugPrint("Position " + i.ToString() + result); } DebugPrint("LOADING BOTTLES .... waiting"); // Posílám dotaz nanastavení 5x for (int i = 1; i <= settings.positions; i++) { bottleData.Clear(); Bottle btl = new Bottle(); btl.Read(i); bottleData.position = i; Buttons.SendSettings(); bottleData.Clear(); } DebugPrint("LOADING BOTTLES .... loaded"); return true; }