private void messageTimer_Tick(object sender, EventArgs e) { if (bouncerAMessenger.IsConnected) { EV3Message message = bouncerAMessenger.ReadMessage(); if (message != null) { switch (message.MailboxTitle) { case "Message": lbLog.Items.Add(message); lbLog.SelectedIndex = lbLog.Items.Count - 1; break; case "Tilt": tbTilt1.Text = message.ValueAsNumber.ToString(); break; case "Speed": tbSpeed.Text = message.ValueAsNumber.ToString(); break; } } } if (Convert.ToInt16(lbTimer.Text) < 10) { lbTimer.Text = (Convert.ToInt16(lbTimer.Text) + 1).ToString(); } else { lbTimer.Text = "0"; } }
private void receiveEV3Message() { if (mEV3Messenger.IsConnected) { EV3Message message = mEV3Messenger.ReadMessage(); if (message != null) { if (message.MailboxTitle == "Message") { //custom messages; } else if (message.MailboxTitle == "Speed") { SetCurrentSpeed(Convert.ToInt16(message.ValueAsNumber)); } else if (message.MailboxTitle == "Tag") { if (message.ToString() == "Finish") { //finish sequence } else { SetPowerUp(Convert.ToInt16(message.ValueAsNumber)); } } } } }
private void receiveButton_Click(object sender, EventArgs e) { // Try to get a message EV3Message message = messenger.ReadMessage(); // Check if there is a message received from the Brick if (message != null) { outputListBox.Items.Add("Message: " + message.ValueAsText); // Auto scroll the listbox outputListBox.TopIndex = outputListBox.Items.Count - 1; } else { MessageBox.Show("No message recieved from the Brick"); } }
//method public void SendInstruction(string order) { // Send a message to the Brick with title: MESSAGE and the message if (messenger.SendMessage("MESSAGE", order)) { //update output box EV3Message message = messenger.ReadMessage(); if (message != null) { status = message.ValueAsText.Split(); switch (status[3]) { default: status[3] = "Runway 1"; break; case "2": status[3] = "Pick-up Zone"; break; case "3": status[3] = "Runway 2"; break; case "4": status[3] = "Drop-off Zone"; break; case "5": status[3] = "Runway 3"; break; } // output list clear and update outputlistBox.Items.Clear(); outputlistBox.Items.Add("AGV: " + status[0]); outputlistBox.Items.Add("Load: " + status[1]); outputlistBox.Items.Add("Position: " + status[2]); outputlistBox.Items.Add("# of proxy triggers: " + status[3]); //outputlistBox.TopIndex = outputlistBox.Items.Count - 1; // no need for this //button disabling & enabling to default state btnStart.Enabled = true; btnPause.Enabled = false; btnStop.Enabled = false; } } }
public static bool UpdateMessageReciving() { if (messenger.IsConnected) { EV3Message message = messenger.ReadMessage(); if (message != null) { messages.Add(message); return(true); } } return(false); }
private void readTimer_Tick(object sender, EventArgs e) { if (messenger.IsConnected) { EV3Message message = messenger.ReadMessage(); if (message != null) { // a message was present and is read. receivedMessagesListBox.Items.Add(message); } } else { readTimer.Stop(); UpdateButtonsAndConnectionInfo(); } }
private void StatusChecker() { while (true) { string newText = Convert.ToString(messenger.ReadMessage()); // running on worker thread this.Invoke((MethodInvoker) delegate { if (newText.Contains("start")) { status_label.Text = "Running"; // runs on UI thread } else if (newText.Contains("stop")) { status_label.Text = "Idle"; } }); Thread.Sleep(10); } }
private void spelerev3_Tick(object sender, EventArgs e) { EV3Message message = ev3Messenger.ReadMessage(); if (message != null && message.MailboxTitle == "up") { if (speler1.Top >= bordertop.Bottom) { speler1.Location = new Point(speler1.Location.X, speler1.Location.Y - offset); } goalgemaakt(0); } else if (message != null && message.MailboxTitle == "down") { if (speler1.Bottom <= borderdown.Top) { speler1.Location = new Point(speler1.Location.X, speler1.Location.Y + offset); goalgemaakt(0); } } if (message != null && message.MailboxTitle == "up2") { if (speler2.Top >= bordertop.Bottom) { speler2.Location = new Point(speler2.Location.X, speler2.Location.Y - offset); } goalgemaakt(0); } else if (message != null && message.MailboxTitle == "down2") { if (speler2.Bottom <= borderdown.Top) { speler2.Location = new Point(speler2.Location.X, speler2.Location.Y + offset); goalgemaakt(0); } } }
private void spelerev3_Tick(object sender, EventArgs e) { EV3Message messagep1 = ev3Messenger1.ReadMessage(); EV3Message messagep2 = ev3Messenger2.ReadMessage(); if (winner != 1) { if (messagep1 != null && messagep1.MailboxTitle == "up") { if (speler1.Top >= bordertop.Bottom) { speler1.Location = new Point(speler1.Location.X, speler1.Location.Y - offsetP1); } if (puntenspeler1 < 10 && puntenspeler2 < 10) { goalgemaakt(0); } } else if (messagep1 != null && messagep1.MailboxTitle == "down") { if (speler1.Bottom <= borderdown.Top) { speler1.Location = new Point(speler1.Location.X, speler1.Location.Y + offsetP1); if (puntenspeler1 < 10 && puntenspeler2 < 10) { goalgemaakt(0); } } } if (gamemodep == 2) { if (messagep2 != null && messagep2.MailboxTitle == "up2") { if (speler2.Top >= bordertop.Bottom) { speler2.Location = new Point(speler2.Location.X, speler2.Location.Y - offsetP2); } goalgemaakt(0); } else if (messagep2 != null && messagep2.MailboxTitle == "down2") { if (speler2.Bottom <= borderdown.Top) { speler2.Location = new Point(speler2.Location.X, speler2.Location.Y + offsetP2); goalgemaakt(0); } } } } if (winner == 1 && (messagep1 != null && messagep1.MailboxTitle == "activatep1")) { this.Close(); } if (messagep1 != null && messagep1.MailboxTitle == "powerupp1") { // gedetecteerde powerup p1 if (messagep1.ValueAsNumber == 1) { powerup1 = 1; pu1p1.Visible = true; pu2p1.Visible = false; pu3p1.Visible = false; pu4p1.Visible = false; } if (messagep1.ValueAsNumber == 2) { powerup1 = 2; pu1p1.Visible = false; pu2p1.Visible = true; pu3p1.Visible = false; pu4p1.Visible = false; } if (messagep1.ValueAsNumber == 3) { powerup1 = 3; pu1p1.Visible = false; pu2p1.Visible = false; pu3p1.Visible = true; pu4p1.Visible = false; } if (messagep1.ValueAsNumber == 4) { powerup1 = 4; pu1p1.Visible = false; pu2p1.Visible = false; pu3p1.Visible = false; pu4p1.Visible = true; } } // pc control player 2 powerup if (pup2 != 0) { if (pup2 == 1) { powerup2 = 1; pu1p2.Visible = true; pu2p2.Visible = false; pu3p2.Visible = false; pu4p2.Visible = false; } if (pup2 == 2) { powerup2 = 2; pu1p2.Visible = false; pu2p2.Visible = true; pu3p2.Visible = false; pu4p2.Visible = false; } if (pup2 == 3) { powerup2 = 3; pu1p2.Visible = false; pu2p2.Visible = false; pu3p2.Visible = true; pu4p2.Visible = false; } if (pup2 == 4) { powerup2 = 4; pu1p2.Visible = false; pu2p2.Visible = false; pu3p2.Visible = false; pu4p2.Visible = true; } } // slaat powerup op in c# p2 if (messagep2 != null && messagep2.MailboxTitle == "powerupp2") { if (messagep2.ValueAsNumber == 1) { powerup2 = 1; pu1p2.Visible = true; pu2p2.Visible = false; pu3p2.Visible = false; pu4p2.Visible = false; } if (messagep2.ValueAsNumber == 2) { powerup2 = 2; pu1p2.Visible = false; pu2p2.Visible = true; pu3p2.Visible = false; pu4p2.Visible = false; } if (messagep2.ValueAsNumber == 3) { powerup2 = 3; pu1p2.Visible = false; pu2p2.Visible = false; pu3p2.Visible = true; pu4p2.Visible = false; } if (messagep2.ValueAsNumber == 4) { powerup2 = 4; pu1p2.Visible = false; pu2p2.Visible = false; pu3p2.Visible = false; pu4p2.Visible = true; } } if (messagep1 != null && messagep1.MailboxTitle == "activatep1") { // invisibility if (powerup1 == 1) { speler2.BackColor = Color.Black; invis2timer = 1; } // swap controls if (powerup1 == 2) { offsetP2 = -10; swap2timer = 1; } // speedshot if (powerup1 == 3) { speedshotp1 = 1; } // double damage if (powerup1 == 4) { hadouken = 1; Bal.BackColor = Color.DodgerBlue; ev3Messenger1.SendMessage("Hadouken", "Hadouken"); } powerup1 = 0; pu1p1.Visible = false; pu2p1.Visible = false; pu3p1.Visible = false; pu4p1.Visible = false; } if (gamemodep == 2) { if (messagep2 != null && messagep2.MailboxTitle == "activatep2" || pu2active == 1) { // invisibility if (powerup2 == 1) { speler1.BackColor = Color.Black; invis1timer = 1; } // swap controls if (powerup2 == 2) { offsetP1 = -10; swap1timer = 1; } // speedshot if (powerup2 == 3) { speedshotp2 = 1; } // double points if (powerup2 == 4) { hadouken = 1; Bal.BackColor = Color.DodgerBlue; ev3Messenger1.SendMessage("Hadouken", "Hadouken"); } powerup2 = 0; pu2active = 0; pu1p2.Visible = false; pu2p2.Visible = false; pu3p2.Visible = false; pu4p2.Visible = false; } } }
private void elapsedTime_Tick(object sender, EventArgs e) { timeInMilliseconds += 100; int etaMilliseconds; message = messenger.ReadMessage(); if (message != null) { if (message.ValueAsText == "Picked_Up") { isPickedUp = true; } else if (message.ValueAsText == "Dropped_Off") { isDropped = true; } } if (!isPickedUp && !isDropped) { txtStatus.Text = "Retreiving package"; if (avgTimePickUp - timeInMilliseconds < 0) { txtETA.Text = "The AGV is delayed"; } else { etaMilliseconds = (int)avgTimePickUp - timeInMilliseconds; txtETA.Text = string.Format(TimeSpan.FromMilliseconds(etaMilliseconds).Minutes + ":" + TimeSpan.FromMilliseconds(etaMilliseconds).Seconds); } } else if (isPickedUp && !isDropped) { if (avgTimeDropOff - timeInMilliseconds < 0) { txtETA.Text = "The AGV is delayed"; } else { etaMilliseconds = (int)avgTimeDropOff - timeInMilliseconds; txtETA.Text = string.Format(TimeSpan.FromMilliseconds(etaMilliseconds).Minutes + ":" + TimeSpan.FromMilliseconds(etaMilliseconds).Seconds); } if (firstTimePick) { timeInMilliseconds = 0; txtStatus.Text = "Delivering package"; stopwatch.Stop(); timespan = TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds); timeToPickUp.Add(timespan); lstPickUpHistory.Items.Add(timespan.Minutes + ":" + timespan.Seconds); firstTimePick = false; stopwatch.Reset(); stopwatch.Start(); using (StreamWriter sw = new StreamWriter("PickUpHistory.txt", true)) { sw.WriteLine(timespan.TotalMilliseconds); } } } else { if (firstTimeDrop) { txtETA.Text = "0:00"; txtStatus.Text = "Returning home"; stopwatch.Stop(); timespan = TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds); timeToDropOff.Add(timespan); lstDropOffHistory.Items.Add(timespan.Minutes + ":" + timespan.Seconds); firstTimeDrop = false; stopwatch.Reset(); using (StreamWriter sw = new StreamWriter("DropOffHistory.txt", true)) { sw.WriteLine(timespan.TotalMilliseconds); } } } }
private void MessageTimer_Tick(object sender, EventArgs e) { lboxPlayers.Items.Refresh(); labPlayerName.Content = ((Player)lboxPlayers.Items[lboxPlayers.SelectedIndex]).Name; labPlayerScore.Content = ((Player)lboxPlayers.Items[lboxPlayers.SelectedIndex]).Score.ToString(); labJackScore.Content = ((Player)lboxPlayers.Items[lboxPlayers.Items.Count - 1]).Score.ToString(); //Get the incoming messages // Get the messages with 1 sec interval if (ev3Messenger.IsConnected) { EV3Message message = ev3Messenger.ReadMessage(); if (message != null) { if (message.MailboxTitle == "Finished") { if (message.ValueAsLogic) { this.IsEnabled = true; this.Tag = "0"; } } if (message.MailboxTitle == "CardValue1") { val1 = message.ValueAsNumber; } if (message.MailboxTitle == "CardValue2" && val1 != 0) { #region get card value val2 = message.ValueAsNumber; string[] cardColors = new string[2]; float ActualValue = 0; //Color values int valueBlack = 0; int valueBlue = 6; int valueGreen = 11; int valueRed = 16; if (val1 >= valueBlack && val1 < valueBlue) { cardColors[0] = "Black"; } // Black else if (val1 >= valueBlue && val1 < valueGreen) { cardColors[0] = "Blue"; } // Blue else if (val1 >= valueGreen && val1 < valueRed) { cardColors[0] = "Green"; } // Green else if (val1 >= valueRed && val1 <= 100) { cardColors[0] = "Red"; } // Red if (val2 >= valueBlack && val2 < valueBlue) { cardColors[1] = "Black"; } // Black else if (val2 >= valueBlue && val2 < valueGreen) { cardColors[1] = "Blue"; } // Blue else if (val2 >= valueGreen && val2 < valueRed) { cardColors[1] = "Green"; } // Green else if (val2 >= valueRed && val2 <= 100) { cardColors[1] = "Red"; } // Red // Zwart : 0 - 5 // Blauw : 6 - 12 // Groen : 13 - 25 // Rood : 26-100 if (cardColors[0] == "Blue" && cardColors[1] == "Blue") { ActualValue = 11; } else if (cardColors[0] == "Green" && cardColors[1] == "Green") { ActualValue = 5; } else if (cardColors[0] == "Black" && cardColors[1] == "Black") { ActualValue = 8; } else if (cardColors[0] == "Red" && cardColors[1] == "Red") { ActualValue = 10; } else if (cardColors[0] == "Blue" && cardColors[1] == "Green" || cardColors[1] == "Blue" && cardColors[0] == "Green") { ActualValue = 2; } else if (cardColors[0] == "Black" && cardColors[1] == "Blue" || cardColors[1] == "Black" && cardColors[0] == "Blue") { ActualValue = 3; } else if (cardColors[0] == "Blue" && cardColors[1] == "Red" || cardColors[1] == "Blue" && cardColors[0] == "Red") { ActualValue = 4; } else if (cardColors[0] == "Black" && cardColors[1] == "Green" || cardColors[1] == "Black" && cardColors[0] == "Green") { ActualValue = 6; } else if (cardColors[0] == "Green" && cardColors[1] == "Red" || cardColors[1] == "Green" && cardColors[0] == "Red") { ActualValue = 7; } else if (cardColors[0] == "Black" && cardColors[1] == "Red" || cardColors[1] == "Black" && cardColors[0] == "Red") { ActualValue = 9; } //MessageBox.Show(ActualValue.ToString() + "\n 1:" + val1.ToString() + "\n 2:" + val2.ToString()); ev3Messenger.SendMessage("Gelezen", "True"); val1 = 0; val2 = 0; #endregion if (this.Tag.ToString() == "1") { ((Player)lboxPlayers.Items[playerTurn]).Cards.Add(ActualValue); if (playerTurn == lboxPlayers.Items.Count - 1) { playerTurn = 0; } else { playerTurn++; } lboxPlayers.Items.Refresh(); Thread.Sleep(1000); } else { ((Player)lboxPlayers.Items[lboxPlayers.SelectedIndex]).Cards.Add(ActualValue); lboxPlayers.Items.Refresh(); if (((Player)lboxPlayers.Items[lboxPlayers.SelectedIndex]).Dealer == true) { JacksTurn(((Player)lboxPlayers.Items[lboxPlayers.SelectedIndex])); } } //read card in C# ev3Messenger.SendMessage("Gelezen", "True"); if (((Player)lboxPlayers.Items[playerTurn]).Score >= 21) { butHit.IsEnabled = false; } } if (message.MailboxTitle == "CardReady") { } } } }
private void timer1_Tick(object sender, EventArgs e) { if (connectButton.Enabled == false) { EV3Message message = messenger.ReadMessage(); if (message != null) { switch (message.ValueAsText) { case "black": pictureBox1.BackColor = Color.Black; break; case "red": pictureBox1.BackColor = Color.Red; break; case "yellow": pictureBox1.BackColor = Color.Yellow; break; case "white": pictureBox1.BackColor = Color.White; break; default: pictureBox1.BackColor = SystemColors.Control; break; } } EV3Message message2 = messenger.ReadMessage(); if (message != null) { switch (message.ValueAsNumber) { case 25: progressBar1.Value = 25; break; case 50: progressBar1.Value = 50; break; case 75: progressBar1.Value = 75; break; case 100: progressBar1.Value = 100; break; default: progressBar1.Value = 0; break; } } } else if (connectButton.Enabled == true) { progressBar1.Value = 0; pictureBox1.BackColor = SystemColors.Control; } }