private void MainForm_Load(object sender, EventArgs e) { this.bluetooth = new BluetoothDevice(new HC06(this.portName)); this.SearchForPorts(); if (this.cmbBoudRate.Items.Count > 0) { this.cmbBoudRate.Text = (string)this.cmbBoudRate.Items[3]; } //store the each retrieved available prot names into the MenuItems... IEnumerable list = Enum.GetValues(typeof(BluetoothTypes)); foreach (BluetoothTypes item in list) { this.typeToolStripMenuItem.DropDown.Items.Add(item.ToString()); } foreach (ToolStripMenuItem item in this.typeToolStripMenuItem.DropDown.Items) { item.Click += mItType_Click; item.Enabled = true; item.Checked = false; } this.SetType(); }
private void mItType_Click(object sender, EventArgs e) { ToolStripMenuItem item = (ToolStripMenuItem)sender; this.bluetoothType = (BluetoothTypes)Enum.Parse(typeof(BluetoothTypes), item.Text); this.lblType.Text = this.bluetoothType.ToString(); this.DisconnectFromDevice(); if (this.bluetoothType == BluetoothTypes.HC06) { this.bluetooth = new BluetoothDevice(new HC06(this.portName)); } else if (this.bluetoothType == BluetoothTypes.HC05) { this.bluetooth = new BluetoothDevice(new HC05(this.portName)); } else if (this.bluetoothType == BluetoothTypes.RN21) { this.bluetooth = new BluetoothDevice(new RN21(this.portName)); } this.bluetooth.SetRecieveEvent(this.bluetooth_RecievedMessage); this.bluetooth.SetMessageEvent(this.bluetooth_SentMessage); item.Checked = this.bluetooth.IsConnected; this.SetConnectivity(); this.SetType(); }
private void ConnectToDevice() { try { if (this.bluetoothType == BluetoothTypes.HC05) { this.bluetooth = new BluetoothDevice(new HC05(this.portName)); } else if (this.bluetoothType == BluetoothTypes.HC06) { this.bluetooth = new BluetoothDevice(new HC06(this.portName)); } else if (this.bluetoothType == BluetoothTypes.RN21) { this.bluetooth = new BluetoothDevice(new RN21(this.portName)); } this.bluetooth.SetRecieveEvent(this.bluetooth_RecievedMessage); this.bluetooth.SetMessageEvent(this.bluetooth_SentMessage); this.bluetooth.Connect(); } catch (Exception exception) { //this.AddLogRow(exception.ToString()); } }