private string log; //The string used to store the log data on public Form1() { InitializeComponent(); //Sets up dummy data SetupData(); //Sets up list view SetupListView(listView1); //Populate the Combobox with SerialPorts on the System comboBox_available_serialPorts.Items.AddRange(SerialPort.GetPortNames()); //Setup serialCom serialCom = new SerialCom(serialPort1); // Displaying System Information string SystemInformation;//Used for Storing System Information //Log the system information SystemInformation = " Machine Name = " + System.Environment.MachineName; // Get the Machine Name SystemInformation = SystemInformation + Environment.NewLine + " OS Version = " + System.Environment.OSVersion; // Get the OS version SystemInformation = SystemInformation + Environment.NewLine + " Processor Cores = " + Environment.ProcessorCount + Environment.NewLine; // Get the Number of Processors on the System TextBox_System_Log.AppendText(SystemInformation); //Display into the Log Text Box }
/// <summary> /// Event for when the baud rate is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComboBox_baudRate_SelectionChangeCommitted(object sender, EventArgs e) { // Store the Selected Baud rate log = "Baudrate of " + comboBox_baudRate.SelectedItem.ToString() + " Selected" + Environment.NewLine; // Display the Selected COM port in the Log Text Box TextBox_System_Log.AppendText(log); //Sets the baudrate of serialPort1 serialPort1.BaudRate = Convert.ToInt32(comboBox_baudRate.SelectedItem.ToString()); }
/// <summary> /// Event for when the COM is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComboBox_available_serialPorts_SelectionChangeCommitted(object sender, EventArgs e) { // Store the Selected COM port log = comboBox_available_serialPorts.SelectedItem.ToString() + " Selected" + Environment.NewLine; // Display the Selected COM port in the Log Text Box TextBox_System_Log.AppendText(log); //Sets the portName serialPort1.PortName = comboBox_available_serialPorts.SelectedItem.ToString(); }
/// <summary> /// Event for when the delete button is presssed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteButton_Click(object sender, EventArgs e) { //Foreach selected item in listview1: Delete foreach (ListViewItem selected in listView1.SelectedItems) { //Write it to log log = availableApparats[selected.Index].Name + " removed." + Environment.NewLine; TextBox_System_Log.AppendText(log); //Remove it availableApparats.RemoveAt(selected.Index); selected.Remove(); } }
/// <summary> /// Event to add the new apparat /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, EventArgs e) { //Create new apparat Apparat apparatToAdd = new Apparat(); //Set name to the text of apparatNameTextbox apparatToAdd.Name = (!string.IsNullOrEmpty(apparatNameTextbox.Text) ? apparatNameTextbox.Text : "Unknown"); //Set functionality of the apparat foreach (object indexChecked in functionalityCheckBox.CheckedIndices) { apparatToAdd.Functionality |= (Func)((int)indexChecked + 1); } //Set Port to the port chosen apparatToAdd.Port = portComboBox.SelectedIndex; //If the port chosen already exist if (availableApparats.Exists(x => x.Port == portComboBox.SelectedIndex)) { //Replace the apparat int index = availableApparats.FindIndex(x => x.Port == portComboBox.SelectedIndex); availableApparats[index] = apparatToAdd; } else { //Else add new apparat availableApparats.Add(apparatToAdd); } //update listview UpdateListView(listView1); //Write to log log = apparatToAdd.Name + " on port " + apparatToAdd.Port.ToString() + " added to list" + Environment.NewLine; TextBox_System_Log.AppendText(log); //change page to apparat menu ChangePage(ApplicationPage.ApparatMenu); }