// update all TextBox values
        public void updateValues()
        {
            if (current_reactor != null)
            {
                // TEMPERATURE
                filter = null;
                string data = current_reactor.getSensors()[0].getData();
                // check and apply any temperature filters
                if (CRadioButton.Checked)
                {
                    if (TempCheckBox.Checked)
                    {
                        filter = new CelsiusFilter(data);
                        filter = new IntegerFilter(filter);
                    }
                    else
                    {
                        filter = new CelsiusFilter(data);
                    }
                    data = filter.getData();
                }
                else if (TempCheckBox.Checked)
                {
                    filter = new IntegerFilter(data);
                    data   = filter.getData();
                }
                int    first        = data.IndexOf('?');
                int    last         = data.LastIndexOf('?');
                string current_temp = data.Substring(0, first);
                string max_temp     = data.Substring(first + 1, last - first - 1);
                string unit_temp    = data.Substring(last + 1, data.Length - last - 1);

                // RADIATION
                filter = null;
                data   = current_reactor.getSensors()[1].getData();
                // check and apply any temperature filters
                if (RadRadioButton.Checked)
                {
                    if (RadCheckBox.Checked)
                    {
                        filter = new RadFilter(data);
                        filter = new IntegerFilter(filter);
                    }
                    else
                    {
                        filter = new RadFilter(data);
                    }
                    data = filter.getData();
                }
                else if (RadCheckBox.Checked)
                {
                    filter = new IntegerFilter(data);
                    data   = filter.getData();
                }
                first = data.IndexOf('?');
                last  = data.LastIndexOf('?');
                string current_radi = data.Substring(0, first);
                string max_radi     = data.Substring(first + 1, last - first - 1);
                string unit_radi    = data.Substring(last + 1, data.Length - last - 1);

                // PRESSURE
                filter = null;
                data   = current_reactor.getSensors()[2].getData();
                // check and apply any temperature filters
                if (KpaRadioButton.Checked)
                {
                    if (PresCheckBox.Checked)
                    {
                        filter = new KpaFilter(data);
                        filter = new IntegerFilter(filter);
                    }
                    else
                    {
                        filter = new KpaFilter(data);
                    }
                    data = filter.getData();
                }
                else if (PresCheckBox.Checked)
                {
                    filter = new IntegerFilter(data);
                    data   = filter.getData();
                }
                first = data.IndexOf('?');
                last  = data.LastIndexOf('?');
                string current_pres = data.Substring(0, first);
                string max_pres     = data.Substring(first + 1, last - first - 1);
                string unit_pres    = data.Substring(last + 1, data.Length - last - 1);

                try {
                    TempTextBox.Invoke(new Action(() => TempTextBox.Text           = current_temp));
                    MaxTempTextBox.Invoke(new Action(() => MaxTempTextBox.Text     = max_temp));
                    TempUnitsTextBox.Invoke(new Action(() => TempUnitsTextBox.Text = unit_temp));
                    RadTextBox.Invoke(new Action(() => RadTextBox.Text             = current_radi));
                    MaxRadTextBox.Invoke(new Action(() => MaxRadTextBox.Text       = max_radi));
                    RadUnitsTextBox.Invoke(new Action(() => RadUnitsTextBox.Text   = unit_radi));
                    PresTextBox.Invoke(new Action(() => PresTextBox.Text           = current_pres));
                    MaxPresTextBox.Invoke(new Action(() => MaxPresTextBox.Text     = max_pres));
                    PresUnitsTextBox.Invoke(new Action(() => PresUnitsTextBox.Text = unit_pres));
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Exemplo n.º 2
0
        public void UpdateGUI()
        {
            while (true)
            {
                //Adds the new client to the GUI listbox list if there are less clients in the gui list box than there are in the connectedclient list.
                if (listBox1.Items.Count < clientManager.Clients.Count)
                {
                    foreach (ConnectedClients client in clientManager.Clients)                           //iterate through is client in the list
                    {
                        if (listBox1.FindStringExact(client.clientID.ToString()) == -1)                  //if there is any client in the connectedclient list that isn't on the list then add it.
                        {
                            listBox1.Invoke((MethodInvoker)(() => listBox1.Items.Add(client.clientID))); //Add client to the list of available clients.
                        }
                    }
                }


                //Removes a specific client from the GUI listbox if there are more clients in the GUI listbox than there are in the connectedclient list
                if (listBox1.Items.Count > clientManager.Clients.Count)
                {
                    for (int xx = 0; xx < listBox1.Items.Count; xx++)                                                                          //iterate through every client in the GUI listbox
                    {
                        if (!clientManager.Clients.Exists(connectedClient => connectedClient.clientID == Convert.ToInt32(listBox1.Items[xx]))) //If client id on the GUI list does not belong to any clients in the connected client list remove it from the list.
                        {
                            listBox1.Invoke((MethodInvoker)(() => listBox1.Items.RemoveAt(xx)));                                               //Remove the client from the available client list.
                            xx--;                                                                                                              //push the counter back once so that all items on the list are compared against the connected clients list. The list is rearranged after removal of an item.
                        }
                    }
                }

                //If any of the values that were received from the buggy differ from the old readings displayed then update the readings.
                if ((float.Parse(TempTextBox.Text) != EnvData.ftemperature) || (Int32.Parse(HumTextBox.Text) != EnvData.humidity) || (Int32.Parse(LIntTextBox.Text) != EnvData.lIntensity))
                {
                    TempTextBox.Invoke((MethodInvoker)(() => TempTextBox.Text = EnvData.ftemperature.ToString()));
                    HumTextBox.Invoke((MethodInvoker)(() => HumTextBox.Text = EnvData.humidity.ToString()));
                    LIntTextBox.Invoke((MethodInvoker)(() => LIntTextBox.Text = EnvData.lIntensity.ToString()));
                }



                if (!ConnectionManager.ConnectionLost)
                {
                    connectToServerBtn.Invoke((MethodInvoker)(() => connectToServerBtn.Enabled = false));
                }

                //If connection with the server has been lost at any point then enable the server connect button to allow the controller client to reconnect.
                //Also update the messaged to notify the user what happened witht he server connection.
                if ((ConnectionManager.ConnectionLost) && (connectToServerBtn.IsHandleCreated))
                {
                    //Enable and Disable appropriate units
                    connectToServerBtn.Invoke((MethodInvoker)(() => connectToServerBtn.Enabled = true));
                    buggyConnectBtn.Invoke((MethodInvoker)(() => buggyConnectBtn.Enabled = false));
                    buggyDisconnectBtn.Invoke((MethodInvoker)(() => buggyDisconnectBtn.Enabled = false));
                    textBoxBuggyConnectStatus.Invoke((MethodInvoker)(() => textBoxBuggyConnectStatus.Enabled = false));
                    comboBoxIntMode.Invoke((MethodInvoker)(() => comboBoxIntMode.Enabled = false));
                    comboBoxConfig.Invoke((MethodInvoker)(() => comboBoxConfig.Enabled = false));
                    ManualControlFocusBtn.Invoke((MethodInvoker)(() => ManualControlFocusBtn.Enabled = false));
                    textBoxConfigStatus.Invoke((MethodInvoker)(() => textBoxConfigStatus.Enabled = false));
                    textBoxCurrConfig.Invoke((MethodInvoker)(() => textBoxCurrConfig.Enabled = false));
                    textBoxConfigStatus.Invoke((MethodInvoker)(() => textBoxConfigStatus.Enabled = false));
                    buttonConfigUpdate.Invoke((MethodInvoker)(() => buttonConfigUpdate.Enabled = false));
                    comboBoxNewConfig.Invoke((MethodInvoker)(() => comboBoxNewConfig.Enabled = false));
                    TempTextBox.Invoke((MethodInvoker)(() => TempTextBox.Enabled = false));
                    HumTextBox.Invoke((MethodInvoker)(() => HumTextBox.Enabled = false));
                    LIntTextBox.Invoke((MethodInvoker)(() => LIntTextBox.Enabled = false));
                    buttonReqData.Invoke((MethodInvoker)(() => buttonReqData.Enabled = false));

                    listBox1.Invoke((MethodInvoker)(() => listBox1.Items.Clear()));

                    //clear the connected client list on disconnection
                    statusTB.Invoke((MethodInvoker)(() => statusTB.Text = "Disconnected"));

                    Thread.CurrentThread.Abort();
                }

                if (ConnectionManager.BuggyConnectionResult)
                {
                    if (!ConnectionManager.buggyConnected)
                    {
                        buggyConnectBtn.Invoke((MethodInvoker)(() => buggyConnectBtn.Enabled = true));
                        buggyDisconnectBtn.Invoke((MethodInvoker)(() => buggyDisconnectBtn.Enabled = false));
                        textBoxBuggyConnectStatus.Invoke((MethodInvoker)(() => textBoxBuggyConnectStatus.Enabled = false));
                        comboBoxIntMode.Invoke((MethodInvoker)(() => comboBoxIntMode.Enabled = false));
                        comboBoxConfig.Invoke((MethodInvoker)(() => comboBoxConfig.Enabled = false));
                        ManualControlFocusBtn.Invoke((MethodInvoker)(() => ManualControlFocusBtn.Enabled = false));
                        textBoxConfigStatus.Invoke((MethodInvoker)(() => textBoxConfigStatus.Enabled = false));
                        textBoxCurrConfig.Invoke((MethodInvoker)(() => textBoxCurrConfig.Enabled = false));
                        textBoxConfigStatus.Invoke((MethodInvoker)(() => textBoxConfigStatus.Enabled = false));
                        buttonConfigUpdate.Invoke((MethodInvoker)(() => buttonConfigUpdate.Enabled = false));
                        comboBoxNewConfig.Invoke((MethodInvoker)(() => comboBoxNewConfig.Enabled = false));
                        TempTextBox.Invoke((MethodInvoker)(() => TempTextBox.Enabled = false));
                        HumTextBox.Invoke((MethodInvoker)(() => HumTextBox.Enabled = false));
                        LIntTextBox.Invoke((MethodInvoker)(() => LIntTextBox.Enabled = false));
                        buttonReqData.Invoke((MethodInvoker)(() => buttonReqData.Enabled = false));

                        textBoxBuggyConnectStatus.Invoke((MethodInvoker)(() => textBoxBuggyConnectStatus.Text = "Disconnected"));
                    }
                    ConnectionManager.BuggyConnectionResult = false;
                }

                //Update the current configuration parameter value in the textbox
                textBoxCurrConfig.Invoke((MethodInvoker)(() => textBoxCurrConfig.Text = BuggyConfigurationData.currConfigParam.ToString()));

                //If the buggy has been configured, display "OK" message in the configuration status textbox
                if (MessageHandler.configStatusUpdate)
                {
                    if (BuggyConfigurationData.configUpdateStatus == 1)
                    {
                        textBoxConfigStatus.Invoke((MethodInvoker)(() => textBoxConfigStatus.Text = "OK"));
                    }
                    MessageHandler.configStatusUpdate = false;
                }
            }
        }