private void button2_Click(object sender, EventArgs e) { CommForm commChooser = new CommForm(); DialogResult dialogResult = commChooser.ShowDialog(); if (dialogResult == DialogResult.OK) { commPortLetter = commChooser.getCommport; commPort = new SerialPort(commPortLetter, 9600, Parity.None, 8, StopBits.One); try { commPort.Open(); usingCommport = true; } catch (Exception ex) { usingCommport = false; } if (usingCommport) { Thread readThread = new Thread(new ThreadStart(new SerialRead(commPort, this).ReadSerial)); readThread.Start(); connectLabel.Text = "Connected to: " + commPortLetter; commPort.WriteLine("ID"); commPort.WriteLine("VE"); } else { connectLabel.Text = "Connected to: Simulator"; simulator = new Simulator(); modelLabel.Text = simulator.ReceiveCommand("ID"); versionLabel.Text = simulator.ReceiveCommand("VE"); } } commChooser.Dispose(); }
private void button1_Click(object sender, EventArgs e) { if (commPort.IsOpen) { commPort.WriteLine("rs"); } if (!usingCommport && simulator != null) { consoleOutput.Text = simulator.ReceiveCommand("RS"); } pwrTxtBox.Text = ""; timeTxtBox.Text = ""; distanceTxtBox.Text = ""; }
private void button2_Click(object sender, EventArgs e) { CommForm commChooser = new CommForm(); DialogResult dialogResult = commChooser.ShowDialog(); if(dialogResult == DialogResult.OK) { commPortLetter = commChooser.getCommport; commPort = new SerialPort(commPortLetter, 9600, Parity.None, 8, StopBits.One); try { commPort.Open(); usingCommport = true; } catch(Exception ex) { usingCommport = false; } if(usingCommport) { Thread readThread = new Thread(new ThreadStart(new SerialRead(commPort, this).ReadSerial)); readThread.Start(); connectLabel.Text = "Connected to: " + commPortLetter; commPort.WriteLine("ID"); commPort.WriteLine("VE"); } else { connectLabel.Text = "Connected to: Simulator"; simulator = new Simulator(); modelLabel.Text = simulator.ReceiveCommand("ID"); versionLabel.Text = simulator.ReceiveCommand("VE"); } } commChooser.Dispose(); }