Beispiel #1
0
        //start button
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button b   = sender as Button;
            string tag = b.Tag.ToString();

            switch (tag)
            {
            case "runall": {
                InputDeviceID window = new InputDeviceID();
                window.ShowDialog();
                string id = window.DeviceID;
                bool   r  = ProjectUtility.IsSmartHomeDeviceID(id);
                if (!r)
                {
                    return;
                }

                Thread t = new Thread(new ThreadStart(() => {
                        _RunAll(id);
                    }));
                t.IsBackground = true;
                t.Start();
                break;
            }

            default: break;
            }
        }
Beispiel #2
0
        //start button
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button b   = sender as Button;
            string tag = b.Tag.ToString();

            switch (tag)
            {
            case "add": {
                InputDeviceID window = new InputDeviceID();
                window.ShowDialog();
                string id = window.DeviceID;
                if (id != "" && listDevice.Contains(id) == false)
                {
                    var c = new ucUserFinal();
                    c.UserSetBindingData((testinfo.TotalDevice + 1).ToString(), id, int.Parse(myGlobal.mySetting.TimeOut));
                    this.stackpanel_content.Children.Add(c);
                    testinfo.TotalDevice++;
                    listDevice.Add(id);
                }
                break;
            }

            case "clear": {
                this.stackpanel_content.Children.Clear();
                testinfo.TotalDevice  = 0;
                testinfo.PassedDevice = 0;
                testinfo.FailedDevice = 0;
                listDevice.Clear();
                break;
            }

            case "start": {
                if (listDevice.Count > 0)
                {
                    try {
                        device.PortName = myGlobal.mySetting.SerialPortName;
                        device.DataBits = int.Parse(myGlobal.mySetting.SerialDataBits);
                        device.BaudRate = int.Parse(myGlobal.mySetting.SerialBaudRate);
                        device.Parity   = Parity.None;
                        device.StopBits = StopBits.One;
                        device.Open();
                    }
                    catch { }

                    if (!device.IsOpen == true)
                    {
                        MessageBox.Show("Can't connect to usb dongle.\r\nPlease check again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        break;
                    }

                    this.listResp.Clear();
                    this.testinfo.LogUART = "";
                    device.DataReceived  += new SerialDataReceivedEventHandler(DataReceivedHandler);
                    start_thread();
                    Thread.Sleep(100);
                    check_thread();

                    foreach (ucUserFinal c in this.stackpanel_content.Children)
                    {
                        c.StartThread();
                    }

                    btn_start.Opacity    = 0.5;
                    btn_stop.Opacity     = 1;
                    btn_start.IsEnabled  = false;
                    btn_stop.IsEnabled   = true;
                    btn_add.IsEnabled    = false;
                    btn_remove.IsEnabled = false;
                }

                break;
            }

            case "stop": {
                if (listDevice.Count > 0)
                {
                    foreach (ucUserFinal c in this.stackpanel_content.Children)
                    {
                        if (c.myTesting.TotalResult.ToLower().Equals("waiting..."))
                        {
                            c.myTesting.TotalResult = "Failed";
                        }
                        c.StopThread();
                    }
                    btn_start.Opacity    = 1;
                    btn_stop.Opacity     = 0.5;
                    btn_start.IsEnabled  = true;
                    btn_stop.IsEnabled   = false;
                    btn_add.IsEnabled    = true;
                    btn_remove.IsEnabled = true;

                    //close device
                    if (device != null && device.IsOpen == true)
                    {
                        device.Close();
                    }
                }
                break;
            }

            default: break;
            }
        }