/// <summary> /// Initialized the GUI /// Attempts to open COM 9 by default /// </summary> /// <param name="frmChoose">The parent chooser form</param> public frmTeslaGui(frmChoose frmChoose) { InitializeComponent(); this.chooserForm = frmChoose; updateGUI = new UpdateGUI(this.UpdateGUIFunction); //add the serial port selection to the menu string[] serialPorts = System.IO.Ports.SerialPort.GetPortNames(); foreach (string portName in serialPorts) { COMPortToolStripMenuItem.DropDownItems.Add(portName, null, (object sender, EventArgs e) => { serialPort.PortName = portName; UncheckAllComs(); ((ToolStripMenuItem)sender).Checked = true; }); if (portName == "COM9") { ((ToolStripMenuItem)COMPortToolStripMenuItem.DropDownItems[COMPortToolStripMenuItem.DropDownItems.Count - 1]).Checked = true; } } //set up serial port serialPort = new System.IO.Ports.SerialPort(); if (serialPorts.Contains("COM9")) { serialPort.PortName = "COM9"; } serialPort.BaudRate = 57600; serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort_DataReceived); //Initialize classes antComm = new ANTCommunication(ref serialPort, this); spBuffer = new BufferedReader(this); tempConv = new TempVal(); //Initialize timers flashTimer = new System.Timers.Timer(50); flashTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTimer_Elapsed); simTimer = new System.Timers.Timer(500); simTimer.Elapsed += new System.Timers.ElapsedEventHandler(simTimer_Elapsed); pastTemps = new Queue<double>(150); //Clear labels lblError.Text = ""; lblLastMessage.Text = ""; //Set up last received lastRecieved = new Dictionary<DataDecoder.SensorType, int>(3); lastRecieved.Add(DataDecoder.SensorType.Temperature, 100); lastRecieved.Add(DataDecoder.SensorType.Accelerometer, 100); lastRecieved.Add(DataDecoder.SensorType.Button, 100); }
/// <summary> /// Initialized the debug form /// </summary> /// <param name="parent">The parent chooser form</param> public frmDisplay(frmChoose parent) { InitializeComponent(); chooserForm = parent; updateLabel = new UpdateLabel(this.UpdateLabelFunction); displayText = new DisplayText(this.UpdateDisplayTextFunction); spBuffer = new BufferedReader(this); string[] serialPorts = System.IO.Ports.SerialPort.GetPortNames(); cmbPort.Items.AddRange(serialPorts); cmbPort.SelectedIndex = 0; cmbBaudRate.SelectedIndex = 1; serialPort.PortName = cmbPort.Text; }