Example #1
0
        /// <summary>
        /// Enable or disable mote switch
        /// </summary>
        /// <remarks>
        /// This sends messages to the mote instructing it to send or not send switch input
        /// </remarks>
        private void EnableDisableMoteSwitch_Click(object sender, EventArgs e)
        {
            if (!_serialStarted || _serialComm == null)
            {
                return;
            }
            EnableDisableMoteSwitch.Enabled = false;
            // If mote switch is enabled then disable (send "0") and change control
            Random random    = new Random();
            int    numToSend = random.Next(0, 9);

            if (_moteSwitchEnabled)
            {
                _moteSwitchEnabled = false;
                _serialComm.Write("fffffff" + numToSend);
                Console.WriteLine("Sent to mote: " + numToSend + "\n");
                MethodInvoker m1 = () =>
                {
                    // Append the received data to the textbox

                    FromMote.AppendText("Sent to mote: " + numToSend + "\n");
                };
                if (FromMote.InvokeRequired)
                {
                    FromMote.Invoke(m1);
                }
                else
                {
                    m1();
                }
                EnableDisableMoteSwitch.Text = "Click to Send Random Number";

                EnableDisableMoteSwitch.BackColor = Color.LightCoral;
            }
            // if mote switch is disabled then enable (send "1") and change control
            else
            {
                _moteSwitchEnabled = true;
                _serialComm.Write("fffffff" + numToSend);
                Console.WriteLine("Sent to mote: " + numToSend + "\n");
                MethodInvoker m1 = () =>
                {
                    // Append the received data to the textbox

                    FromMote.AppendText("Sent to mote: " + numToSend);
                };
                if (FromMote.InvokeRequired)
                {
                    FromMote.Invoke(m1);
                }
                else
                {
                    m1();
                }
                EnableDisableMoteSwitch.Text      = "Click to Send Random Number";
                EnableDisableMoteSwitch.BackColor = Color.YellowGreen;
            }
            EnableDisableMoteSwitch.Enabled = true;
        }
Example #2
0
        /// <summary>
        /// A call-back method that's called by SerialComm whenever serial data has been received from the mote
        /// </summary>
        /// <param name="input">The data received</param>
        ///

        private void ProcessInput(string input)
        {
            // We have to use a method invoker to avoid cross-thread issues
            //Console.WriteLine(f_n);
            if (f_n == 7)
            {
                f_n = 0;

                String tempString = "From mote got: " + input + "  \n";
                Console.WriteLine(tempString);
                MethodInvoker m1 = () =>
                {
                    // Append the received data to the textbox
                    //Console.Write("inside lambda");
                    FromMote.AppendText(tempString);
                };
                if (FromMote.InvokeRequired)
                {
                    FromMote.Invoke(m1);
                }
                else
                {
                    m1();
                }
            }
            else if (input.Equals("f"))
            {
                f_n++;
            }
            else
            {
                f_n = 0;
            }
            if (true)
            {
                //Console.Write("decent input " + input +" with length  "+ input.Length+"\n");
                Console.Write(input);
            }
            return;

            MethodInvoker m = () =>
            {
                // Append the received data to the textbox

                FromMote.AppendText(input);
            };

            //if (input.Length < 2)
            //    return;
            if (FromMote.InvokeRequired)
            {
                FromMote.Invoke(m);
            }
            else
            {
                m();
            }
        }
Example #3
0
 /// <summary>
 /// Clear the messages received from the mote
 /// </summary>
 private void ClearFromMote_Click(object sender, EventArgs e)
 {
     FromMote.Clear();
 }
        /// <summary>
        /// A call-back method that's called by SerialComm whenever serial data has been received from the mote
        /// </summary>
        /// <param name="input">The data received</param>
        ///

        private void ProcessInput(string input)
        {
            // We have to use a method invoker to avoid cross-thread issues
            //Console.WriteLine(f_n);
            Console.Write(input);
            //if (f_n == 7 && flag==1)
            if (f_n == 7)
            {
                f_n  = 0;
                flag = 2;

                String tempString = " From mote got: " + input + " \n";
                Console.WriteLine(tempString);
                MethodInvoker m1 = () =>
                {
                    // Append the received data to the textbox
                    //Console.Write("inside lambda");
                    FromMote.AppendText(tempString);
                };
                if (FromMote.InvokeRequired)
                {
                    FromMote.Invoke(m1);
                }
                else
                {
                    m1();
                }
                //int num = int.Parse(input);
                //int numToReturn=0;

                int num = -1;
                try
                {
                    num = int.Parse(input);
                }
                catch (Exception ex)
                {
                    num = -1;
                }
                Console.WriteLine("num is " + num);
                int numToReturn = 9 - num;
                //if (mockServer.Contains(input)){
                //    numToReturn = (int)mockServer[num];}
                String tempStringReturn = " Sent Back " + numToReturn + "\n";
                Console.WriteLine(tempStringReturn);
                MethodInvoker m2 = () =>
                {
                    // Append the received data to the textbox
                    //Console.Write("inside lambda");
                    FromMote.AppendText(tempStringReturn);
                };
                if (FromMote.InvokeRequired)
                {
                    FromMote.Invoke(m2);
                }
                else
                {
                    m2();
                }
                if (num >= 0 && num <= 9)
                {
                    _serialComm.Write("fffffff" + numToReturn);
                }
            }
            else if (input.Equals("f"))
            {
                f_n++;
            }
            else
            {
                f_n = 0;
                return;
            }
            return;

            if (true)
            {
                //Console.Write("decent input " + input +" with length  "+ input.Length+"\n");
                //Console.Write(input);
            }
            MethodInvoker m = () => {
                // Append the received data to the textbox

                FromMote.AppendText(input);
            };

            //if (input.Length < 2)
            //    return;
            if (FromMote.InvokeRequired)
            {
                FromMote.Invoke(m);
            }
            else
            {
                m();
            }
        }