/// <summary> /// Constructor. /// </summary> /// <param name="commportNumber">The number of the commport the bike is connected to.</param> public Bike(string commportNumber) { bikeCommunication = new BikeCommunication(this); if (bikeCommunication.ConnectToCom(commportNumber)) { usingComm = true; status = "Connected to " + commportNumber; } else //When there is nothing connected to the commport; { simulator = new Simulator(); status = "Simulator"; } }
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(); }