// 顯示Local端藍芽設備的資訊, 以及把Local端的藍芽設備設置成可被發現(RadioMode.Discoverable) public void DisplayBluetoothRadio() { if (IsDebugMode) { UpdateBTDeviceDetails("Display Bluetooth Details"); } if (mBluetoothRadio == null) { mBluetoothRadio = BluetoothRadio.PrimaryRadio; } if (mBluetoothRadio == null) { UpdateBTDeviceDetails("There's no BT radio hardware or unsupported software stack. Stop."); UpdateFindDeviceResult("Fail. There's no BT device"); labelResult.ForeColor = Color.Red; checkTestStatus("There's no BT device"); return; } Cursor.Current = Cursors.WaitCursor; // 設定Current屬性會變更目前顯示的游標 #region BluetoothRadio Information // Warning: LocalAddress is null if the radio is powered-off. labelBtLocalAddress.Text = String.Format("{0:C}", mBluetoothRadio.LocalAddress); if (IsDebugMode) { UpdateBTDeviceDetails("Name: " + mBluetoothRadio.Name + String.Format("\r\nLocal Address: {0:C}", mBluetoothRadio.LocalAddress)); UpdateBTDeviceDetails("Radio Mode: " + mBluetoothRadio.Mode.ToString()); } Console.WriteLine("HardwareStatus: " + mBluetoothRadio.HardwareStatus); Console.WriteLine("HciRevision: " + mBluetoothRadio.HciRevision); Console.WriteLine("HciVersion: " + mBluetoothRadio.HciVersion); Console.WriteLine("LmpVersion: " + mBluetoothRadio.LmpVersion); Console.WriteLine("LocalAddress: " + mBluetoothRadio.LocalAddress); Console.WriteLine("Manufacturer: " + mBluetoothRadio.Manufacturer); Console.WriteLine("Remote:" + mBluetoothRadio.Remote); Console.WriteLine("SoftwareManufacturer: " + mBluetoothRadio.SoftwareManufacturer); Console.WriteLine("StackFactory: " + mBluetoothRadio.StackFactory); #endregion // Enable discoverable mode // Bluetooth is turned on. The local device is listed, when a peer device searches for available devices within range. The peer device can pair with the local device. mBluetoothRadio.Mode = RadioMode.Discoverable; // Winmate kenkun modify on 2014/08/11 // RadioMode.Connectable // Bluetooth is turned on. The local device can initiate a connection with a peer device but the local device is not discoverable by peer devices that are within range. // mBluetoothRadio.Mode = RadioMode.Connectable; if (IsDebugMode) { UpdateBTDeviceDetails("Now Radio Mode : " + mBluetoothRadio.Mode.ToString()); } }
public MainForm() { InitializeComponent(); try { this.pictureBox1.Image = new Bitmap(@"\n2f.bmp"); this.BTON.Image = new Bitmap(@"\btON.bmp"); } catch { } lblBluetooth.Text = "Bluetooth is ON - Searching..."; BluetoothRadio br = BluetoothRadio.PrimaryRadio; br.Mode = RadioMode.Discoverable; if (br == null) { MessageBox.Show("Bluetooth radio is being used. Restart device for quick fix"); Application.Exit(); } if (br.LocalAddress.ToString() == AsynchronousClient.BTAddress.ToString()) { // BOB is the server so he needs to have the server listener running OtherName = "Alice"; //MessageBox.Show("I am BOB"); // set alices address AsynchronousClient.BTAddress = new BluetoothAddress(new byte[] { 175, 223, 244, 227, 23, 0, 0, 0 }); AsynchronousClient AClient = new AsynchronousClient(this); ThreadClient = new Thread(new ThreadStart(AClient.StartSending)); ThreadClient.Start(); // start the Asynchronous server AsynchronousServer AServer = new AsynchronousServer(this); } else { OtherName = "Bob"; //MessageBox.Show("I am ALICE"); AsynchronousClient AClient = new AsynchronousClient(this); ThreadClient = new Thread(new ThreadStart(AClient.StartSending)); ThreadClient.Start(); // start the Asynchronous server AsynchronousServer AServer = new AsynchronousServer(this); } }
private void Form1_Load(object sender, System.EventArgs e) { //turn on bt radio BluetoothRadio radio = BluetoothRadio.PrimaryRadio; if (radio != null && radio.Mode == RadioMode.PowerOff) { BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable; } bc = new BluetoothClient(); }
public static BluetoothAddress GetBTMacAddress() { BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio; if (myRadio == null) { return(null); } return(myRadio.LocalAddress); }
private BluetoothAddress GetLocalEndpointAddress() { // https://stackoverflow.com/questions/23431071/c-sharp-bluetooth-mac-address-of-our-adapter BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio; if (myRadio == null) { return(null); } return(myRadio.LocalAddress); }
private void ButtonInfo_Click(object sender, RoutedEventArgs e) { if (ListBoxAdapters.SelectedIndex != -1) { int index = ListBoxAdapters.SelectedIndex; Console.WriteLine(bt._btAdapters[index].Name); BluetoothRadio temp = bt._btAdapters[index]; MessageBox.Show( "Device Name " + temp.Name + "\n" + "MAC ADRESS: " + temp.LocalAddress + "\n"); } }
Thread listenThread, sendThread; //发送/接收线程 public Form1() { InitializeComponent(); radio = BluetoothRadio.PrimaryRadio; //获取当前PC的蓝牙适配器 CheckForIllegalCrossThreadCalls = false; //不检查跨线程调用 if (radio == null) //检查该电脑蓝牙是否可用 { MessageBox.Show("这个电脑蓝牙不可用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } recDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); labelRecDir.Text = recDir; }
// -------------------------------------------------------------------------- // STATIC METHODS // -------------------------------------------------------------------------- // Retourne l'adresse MAC du périphérique Bluetooth local public static BluetoothAddress GetLocalBTMacAddress() { BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio; if (myRadio == null) { Console.WriteLine("Pas de matériel Bluetooth, ou logiciel Bluetooth non supporté."); return(null); } return(myRadio.LocalAddress); }
private void ButtonInfo_Click(object sender, EventArgs e) { if (ListBoxAdapters.SelectedIndex != -1) { int index = ListBoxAdapters.SelectedIndex; Console.WriteLine(tabRadios[index].Name); BluetoothRadio temp = tabRadios[index]; MessageBox.Show( "Nazwa adaptera: " + temp.Name + "\n" + "Adres MAC: " + temp.LocalAddress + "\n"); } }
static void Main(string[] args) { BluetoothRadio brad = new BluetoothRadio(); if (brad.BluetoothRadioMode == BluetoothRadioMode.Off) { brad.BluetoothRadioMode = BluetoothRadioMode.On; } else { brad.BluetoothRadioMode = BluetoothRadioMode.Off; } }
//Método para verificar se o adaptador bluetooth está disponível private bool isBluetoothAdapterEnabled() { BluetoothRadio v_RadioInstace = BluetoothRadio.PrimaryRadio; if (v_RadioInstace == null) { return(false); } else { return(true); } }
private void deviceInfo_Click(object sender, EventArgs e) { Console.WriteLine("info clicked"); if (listBox1.SelectedIndex != -1) { int index = listBox1.SelectedIndex; Console.WriteLine(bt._btAdapters[index].Name); BluetoothRadio temp = bt._btAdapters[index]; MessageBox.Show( "Device Name " + temp.Name + "\n" + "MAC ADRESS: " + temp.LocalAddress + "\n"); } }
/// <summary> /// 搜索蓝牙 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { BluetoothRadio BuleRadio = BluetoothRadio.PrimaryRadio; BuleRadio.Mode = RadioMode.Connectable; BluetoothDeviceInfo[] Devices = blueClient.DiscoverDevices(); listBox1.Items.Clear(); deviceAddress.Clear(); foreach (BluetoothDeviceInfo device in Devices) { listBox1.Items.Add(device.DeviceName); deviceAddress[device.DeviceName] = device.DeviceAddress; } }
private BluetoothClient GetRadio() { BluetoothRadio btradio = BluetoothRadio.PrimaryRadio; if (btradio == null) { return(null); } BluetoothEndPoint endPoint = new BluetoothEndPoint(btradio.LocalAddress, serviceGuid); BluetoothClient thisRadio = new BluetoothClient(endPoint); return(thisRadio); }
public Form1() { InitializeComponent(); btr = new BluetoothRadio(); //first use intermec IBT_On() btr.BluetoothRadioMode = BluetoothRadioMode.On; listPairedDevices(); BluetoothAddress btAddr = new BluetoothAddress("00000006660309e8"); ddump("btAddress: " + btAddr.ToString()); BluetoothMessages btmsg = new BluetoothMessages(); }
private bool checkBluetooth() { radio = BluetoothRadio.PrimaryRadio; if (radio == null) { return(false); } if (radio.Mode == RadioMode.PowerOff) { return(false); } radio.Mode = RadioMode.Discoverable; return(true); }
// Inicializa el servidor Bluetooth public void initBluetooth() { exit = false; BluetoothRadio br = BluetoothRadio.PrimaryRadio; // Radio Bluetooth de tipo Primario br.Mode = RadioMode.Discoverable; // Radio Bluetooth visible a los clientes btListener = new BluetoothListener(service); btListener.Start(); Thread th = new Thread(new ThreadStart(this.runBluetooth)); th.Start(); }
public void Fill(BluetoothRadio bl_radio) { this.Machine_name = bl_radio.Name; this.Class_of_device = bl_radio.ClassOfDevice.Device.ToString(); this.Manufacturer = bl_radio.Manufacturer.ToString(); this.MAC_address = bl_radio.LocalAddress.ToString(); this.Hardware_status = bl_radio.HardwareStatus.ToString(); this.Mode = bl_radio.Mode.ToString(); this.Software_manufacturer = bl_radio.SoftwareManufacturer.ToString(); this.Version_fingerprint = bl_radio.HciVersion.ToString() + "/" + bl_radio.HciRevision.ToString() + "/" + bl_radio.LmpVersion.ToString() + "/" + bl_radio.LmpSubversion.ToString(); }
public void Main(string[] args) { BluetoothRadio bluetoothRadio = BluetoothRadio.PrimaryRadio; if (bluetoothRadio == null) { MessageBox.Show("沒有找到本機藍牙設備!"); } else { Bluetooth p = new Bluetooth(); p.localAdapterInfo(bluetoothRadio); p.openDoor(); } }
private void btnQueryBluetooth_Click(object sender, EventArgs e) { btnQueryBluetooth.Enabled = false; radio = BluetoothRadio.PrimaryRadio; //获取当前PC的蓝牙适配器 if (radio == null) //检查该电脑蓝牙是否可用 { MessageBox.Show("Bluetooth is not available for this device!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information); btnQueryBluetooth.Enabled = true; return; } else { blueClient = new BluetoothClient(); SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog(); dialog.ShowRemembered = true; //显示已经记住的蓝牙设备 dialog.ShowAuthenticated = true; //显示认证过的蓝牙设备 dialog.ShowUnknown = true; //显示位置蓝牙设备 if (dialog.ShowDialog() == DialogResult.OK) { sendAddress = dialog.SelectedDevice.DeviceAddress;//获取选择的远程蓝牙地址 } if (sendAddress == null) { MessageBox.Show("Did not select the Bluetooth device!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information); btnQueryBluetooth.Enabled = true; return; } else { string pin = "1234";//默认的蓝牙pin值 if (Connect(sendAddress, pin)) { MessageBox.Show("Connect Bluetooth successfully"); btnPrint.Enabled = true; btnPrintTestPage.Enabled = true; btnLogout.Enabled = true; btnOneDimensionalCode.Enabled = true; btnPrintQRCode.Enabled = true; } else { btnQueryBluetooth.Enabled = true; MessageBox.Show("Failed to connect to Bluetooth"); } } } }
/// <summary> /// Finds all LPMS-B sensors visible to Bluetooth adapters of this computer. /// </summary> /// <param name="deviceSearchTimeout"> /// Timeout for searching available devices for a single Bluetooth adapter. /// Recommended values aree 5 to 10 seconds. /// </param> /// <remarks> /// Method execution may take a significant time due to Bluetooth discovery operations. /// </remarks> /// <returns>Addresses of the sensors.</returns> public static BluetoothAddress[] Enumerate(TimeSpan deviceSearchTimeout) { var radios = BluetoothRadio.FindAll(); var result = radios.SelectMany(radio => radio.FindDevices(deviceSearchTimeout)). Where(device => device.Name.StartsWith("LPMS")). Select(device => device.Address). ToArray(); foreach (var radio in radios) { radio.Dispose(); } return(result); }
private static BluetoothAddress GetLocalAdapterAddress() { BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio; if (myRadio == null) { throw new InvalidStateException("No bt hardware / unsupported stack?"); } var localAddress = myRadio.LocalAddress; if (localAddress == null) { throw new InvalidStateException("BT adapter is off"); } return(localAddress); }
static void Main(string[] args) { BluetoothRadio bluetoothRadio = BluetoothRadio.PrimaryRadio; if (bluetoothRadio == null) { Console.WriteLine("没有找到本机蓝牙设备!"); Console.ReadLine(); } else { Program p = new Program(); p.localAdapterInfo(bluetoothRadio); p.openDoor(); } }
/** * * 顯示本地藍牙的信息 * * **/ public void localAdapterInfo(BluetoothRadio bluetoothRadio) { MessageBox.Show("ClassOfDevice: " + bluetoothRadio.ClassOfDevice); MessageBox.Show("HardwareStatus: " + bluetoothRadio.HardwareStatus); MessageBox.Show("HciRevision: " + bluetoothRadio.HciRevision); MessageBox.Show("HciVersion: " + bluetoothRadio.HciVersion); MessageBox.Show("LmpSubversion: " + bluetoothRadio.LmpSubversion); MessageBox.Show("LmpVersion: " + bluetoothRadio.LmpVersion); MessageBox.Show("LocalAddress: " + bluetoothRadio.LocalAddress); MessageBox.Show("Manufacturer: " + bluetoothRadio.Manufacturer); MessageBox.Show("Mode: " + bluetoothRadio.Mode); MessageBox.Show("Name: " + bluetoothRadio.Name); MessageBox.Show("Remote:" + bluetoothRadio.Remote); MessageBox.Show("SoftwareManufacturer: " + bluetoothRadio.SoftwareManufacturer); MessageBox.Show("StackFactory: " + bluetoothRadio.StackFactory); }
private void InitBluetooth() { try { _bluetooth = new BluetoothClient(); radio = BluetoothRadio.PrimaryRadio; discoverableName.Text = radio.Name; radio.Mode = RadioMode.Connectable; var serviceClass = BluetoothService.SerialPort; GetAllDevices(); } catch (Exception ex) { Debug.WriteLine(ex); } }
public List <CBluetooth> Search() { List <CBluetooth> bluetoothList = new List <CBluetooth>(); //搜索到的蓝牙的集合 BluetoothClient client = new BluetoothClient(); BluetoothRadio radio = BluetoothRadio.PrimaryRadio; //获取蓝牙适配器 radio.Mode = RadioMode.Connectable; BluetoothDeviceInfo[] devices = client.DiscoverDevices(); //搜索蓝牙 10秒钟 foreach (var item in devices) { bluetoothList.Add(new CBluetooth { blueName = item.DeviceName, blueAddress = item.DeviceAddress, blueClassOfDevice = item.ClassOfDevice, IsBlueAuth = item.Authenticated, IsBlueRemembered = item.Remembered, blueLastSeen = item.LastSeen, blueLastUsed = item.LastUsed }); //把搜索到的蓝牙添加到集合中 } return(bluetoothList); }
/** * * 显示本地蓝牙的信息 * * **/ private void localAdapterInfo(BluetoothRadio bluetoothRadio) { Console.WriteLine("ClassOfDevice: " + bluetoothRadio.ClassOfDevice); Console.WriteLine("HardwareStatus: " + bluetoothRadio.HardwareStatus); Console.WriteLine("HciRevision: " + bluetoothRadio.HciRevision); Console.WriteLine("HciVersion: " + bluetoothRadio.HciVersion); Console.WriteLine("LmpSubversion: " + bluetoothRadio.LmpSubversion); Console.WriteLine("LmpVersion: " + bluetoothRadio.LmpVersion); Console.WriteLine("LocalAddress: " + bluetoothRadio.LocalAddress); Console.WriteLine("Manufacturer: " + bluetoothRadio.Manufacturer); Console.WriteLine("Mode: " + bluetoothRadio.Mode); Console.WriteLine("Name: " + bluetoothRadio.Name); Console.WriteLine("Remote:" + bluetoothRadio.Remote); Console.WriteLine("SoftwareManufacturer: " + bluetoothRadio.SoftwareManufacturer); Console.WriteLine("StackFactory: " + bluetoothRadio.StackFactory); Console.ReadLine(); }
private void LaunchRadio() { BluetoothRadio radio = BluetoothRadio.PrimaryRadio; if (radio == null) { // TODO: No radio found we need to report an error in the logs _state = BTStates.start_radio; return; } else if (radio.Mode == RadioMode.PowerOff) { BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable; } _client = new BluetoothClient(); _state = BTStates.find_connected_devices; }
public void DiscoverDevices() { BluetoothRadio radio = BluetoothRadio.PrimaryRadio; //獲取藍芽介面卡 radio.Mode = RadioMode.Connectable; Console.WriteLine("搜尋藍芽裝置中...."); BluetoothDeviceInfo[] devices = client.DiscoverDevices();//搜尋藍芽 10秒鐘 Console.WriteLine("找到裝置數量:" + devices.Count().ToString()); ; foreach (var item in devices) { lanYaList.Add(new Bluetooth { blueName = item.DeviceName, blueAddress = item.DeviceAddress, blueClassOfDevice = item.ClassOfDevice, IsBlueAuth = item.Authenticated, IsBlueRemembered = item.Remembered, blueLastSeen = item.LastSeen, blueLastUsed = item.LastUsed }); //把搜尋到的藍芽新增到集合中 } lanYaList.ForEach(Lanya => { Console.WriteLine("裝置名稱: " + Lanya.blueName + " " + "裝置MAC: " + Lanya.blueAddress.ToString()); }); }
private void LaunchRadio() { BluetoothRadio radio = BluetoothRadio.PrimaryRadio; if (radio == null) { LogMessage("No radio present, cannot launch Bluetooth client."); _state = BTStates.start_radio; return; } else if (radio.Mode == RadioMode.PowerOff) { BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable; } _client = new BluetoothClient(); _state = BTStates.find_connected_devices; }