Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();

            speechSynthesizer = new SpeechSynthesizer();
            speechSynthesizer.SetOutputToDefaultAudioDevice();

            var timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(1)
            };

            timer.Tick += Timer_Tick;
            timer.Start();

            // Display today's sunset/sunrise times:

            DateTime sunriseToday, sunsetToday;

            SunTimes.GetSunTimes(out sunriseToday, out sunsetToday);

            lblSunriseVal.Content = sunriseToday.ToShortTimeString();
            lblSunsetVal.Content  = sunsetToday.ToShortTimeString();


            // We dont really have a way to get the current state of the AC & DC bus
            // So we just initialize the switches to 'off' state which may not be the true
            // state of the Netduino.

            BtnDCBus.IsChecked = false;
            BtnACBus.IsChecked = false;

            BtnDCBus.Checked   += BtnDCBus_Checked;
            BtnDCBus.Unchecked += BtnDCBus_Unchecked;

            BtnACBus.Checked   += BtnACBus_Checked;
            BtnACBus.Unchecked += BtnACBus_Unchecked;


            // Read in the configurtion:
            var deviceIP = string.Empty;

            try
            {
                deviceIP = ConfigurationManager.AppSettings["deviceIPAddress"];
            }
            catch (ConfigurationErrorsException)
            {
                MessageBox.Show("Error Reading Configuration File");
            }


            netDuino = NetDuinoPlus.Instance(deviceIP);
        }
        public CharonApplication(bool consoleMode)
        {
            speechSynthesizer = new SpeechSynthesizer();
            speechSynthesizer.SetOutputToDefaultAudioDevice();


            CharonApplication.consoleMode = consoleMode;


            if (CharonApplication.consoleMode)
            {
                Console.WriteLine($"Started Charon Service in console mode {DateTime.Now}");
                Console.WriteLine("Press any key to exit...");
                Console.WriteLine();
            }
            else
            {
                logger.Info($"Started Charon Service (No Console) {DateTime.Now}");
            }


            // Read in the configuration:
            var deviceIP = string.Empty;

            try
            {
                deviceIP = ConfigurationManager.AppSettings["deviceIPAddress"];

                dcBusOnTimeOffset = Convert.ToInt16(ConfigurationManager.AppSettings["DCRelayOnTimeOffest"]);
                dcBusOffTime      = Convert.ToDateTime(ConfigurationManager.AppSettings["DCRelayOffTime"]);

                acBusOnTimeOffset = Convert.ToInt16(ConfigurationManager.AppSettings["DCRelayOnTimeOffest"]);
                acBusOffTime      = Convert.ToDateTime(ConfigurationManager.AppSettings["ACRelayOffTime"]);
            }
            catch (ConfigurationErrorsException)
            {
                LogMessage("Error Reading Configuration File...");
            }

            // Instantiate the device:
            netDuino = NetDuinoPlus.Instance(deviceIP);

            // and Run with it:
            Run();

            // if in the console mode, wait for the key press
            if (CharonApplication.consoleMode)
            {
                Console.ReadKey();
                Stop();
            }
        }