public RemoteControlForm() { InitializeComponent(); MessageBuilder messageBuilder = new MessageBuilder(); serialMessenger = new SerialMessenger(port, speed, messageBuilder); MessageBox.Show("Ready, Set, Go!", "Get Ready!", MessageBoxButtons.OK); readMessageTimer = new Timer(); readMessageTimer.Interval = 500; readMessageTimer.Tick += new EventHandler(ReadMessageTimer_Tick); MessageBox.Show("Ready Set go!", "Get Ready", MessageBoxButtons.OK); try { serialMessenger.Connect(); readMessageTimer.Enabled = true; Console.WriteLine("Connected!"); } catch (Exception exception) { MessageBox.Show(exception.Message); } Console.WriteLine(); }
/// <summary> /// Wets up the Timer and SerialMessengers, /// </summary> public Form1() { InitializeComponent(); SerialMessangerCreationDialog(); readMessageTimer = new Timer(); readMessageTimer.Interval = 10; readMessageTimer.Tick += new EventHandler(ReadMessageTimer_Tick); try { serialMessengerlock.Connect(); serialMessengerTv.Connect(); readMessageTimer.Enabled = true; } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private void btnSetSchoolAlarm_Click(object sender, EventArgs e) { // Make sure the departure time is correct if (departure.Date == DateTime.Today.Date && lbCountdown.Text == "00:00:00" || departure.Day == 1 && departure.Month == 1 && departure.Year == 0001) { MessageBox.Show("Log in with your Fontys account and fill in a correct living place and show the travel info"); } else // Departure time is correct { string prepTimeString = ""; int prepTimeInt = Convert.ToInt32(nudPrepTime.Value); if (prepTimeInt == 0) // If no prep time is filled in { MessageBox.Show("Please fill in your estimated prep time"); } else { if (prepTimeInt != 0 && prepTimeInt < 60) // If prep time is within 1 hour { prepTimeString = "00:" + prepTimeInt.ToString() + ":00"; } else if (prepTimeInt >= 60 && prepTimeInt < 120) // If prep time is between 1 and 2 hours { prepTimeInt = prepTimeInt - 60; prepTimeString = "01:" + prepTimeInt.ToString() + ":00"; } else if (prepTimeInt >= 120 && prepTimeInt < 180) // If prep time is between 2 and 3 hours { prepTimeInt = prepTimeInt - 120; prepTimeString = "02:" + prepTimeInt.ToString() + ":00"; } else if (prepTimeInt >= 180 && prepTimeInt < 240) // If prep time is between 3 and 4 hours { prepTimeInt = prepTimeInt - 180; prepTimeString = "03:" + prepTimeInt.ToString() + ":00"; } DateTime prepTimeDateTime = Convert.ToDateTime(prepTimeString); TimeSpan schoolAlarm = departure.Subtract(prepTimeDateTime); string alarm = schoolAlarm.Hours.ToString("00") + ":" + schoolAlarm.Minutes.ToString("00") + ":" + schoolAlarm.Seconds.ToString("00"); //alarm = "11:11:00"; // For testing the alarm MessageBox.Show("School alarm set on: " + alarm); // Arduino code try // Connect { serialMessenger.Connect(); } catch (Exception exception) { MessageBox.Show(exception.Message); } // Send message serialMessenger.SendMessage(alarm); // Disconnect try { serialMessenger.Disconnect(); } catch (Exception exception) { MessageBox.Show(exception.Message); } } } }