Ejemplo n.º 1
0
        private void ConnectToDevice(object obj)
        {
            InTheHand.Net.BluetoothAddress tempDev = null;
            if (mobjBt == null)
            {
                MessageBox.Show("本机未找到蓝牙设备");
                return;
            }

            tempDev = UserSelectDev();
            if (tempDev == null)
            {
                return;
            }

            mobjBt.ConnectToDevice(tempDev);
            System.Threading.Thread.Sleep(3000);
            DateTime timeTo = DateTime.Now.AddSeconds(15);

            while (mobjBt.ConnectionStatue != clsBlueTooth.en_ConStatue.EN_SUCCEED && timeTo > DateTime.Now)
            {
                Application.DoEvents();
                System.Threading.Thread.Sleep(1000);
            }

            if (mobjBt.ConnectionStatue != clsBlueTooth.en_ConStatue.EN_SUCCEED)
            {
                MessageBox.Show("连接蓝牙设备失败!!!");
                return;
            }

            this.Close();
            return;
        }
Ejemplo n.º 2
0
        void AddKnownAddress(InTheHand.Net.BluetoothAddress value)
        {
            var text = value.ToString("C");

            if (!_knownAddresses.Contains(text))
            {
                _knownAddresses.Add(text);
            }
        }
Ejemplo n.º 3
0
        private static string GetRadioRegKey(InTheHand.Net.BluetoothAddress radioAddress)
        {
            Guid   btguid   = NativeMethods.GUID_DEVCLASS_BLUETOOTH;
            IntPtr hDevInfo = NativeMethods.SetupDiGetClassDevs(ref btguid, null, IntPtr.Zero, NativeMethods.DIGCF.PRESENT | NativeMethods.DIGCF.PROFILE);

            if (IntPtr.Zero.Equals(hDevInfo))
            {
                throw new Win32Exception();
            }

            try {
                NativeMethods.SP_DEVINFO_DATA data = new NativeMethods.SP_DEVINFO_DATA();
                // On 32bit platforms, all SetupApi structures are 1-Byte packed.
                // On 64bit platforms the SetupApi structures are 8-byte packed.
                // i.e. for 32 bit SP_DEVINFO_DATA.cbSize=28, for 64Bit SP_DEVINFO_DATA.cbSize=(28+4)=32.
                data.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(data);
                uint idx = 0;

                while (NativeMethods.SetupDiEnumDeviceInfo(hDevInfo, idx++, ref data))
                {
                    // grab the instance id
                    string instanceId = DevInstanceId(hDevInfo, data);
                    //Debug.WriteLine("WindowsBluetoothRadio.GetRadioRegKey item: " + instanceId);

                    //the last part of the instanceId will be the unique bluetooth address of the radio
                    int lastSlashIndex = instanceId.LastIndexOf("\\");
                    BluetoothAddress address;
                    InTheHand.Net.BluetoothAddress.TryParse(instanceId.Substring(lastSlashIndex + 1, instanceId.Length - lastSlashIndex - 1), out address);
                    //InTheHand.Net.BluetoothAddress address = InTheHand.Net.BluetoothAddress.Parse(instanceId.Substring(lastSlashIndex + 1, instanceId.Length - lastSlashIndex - 1));

                    if (address != null && radioAddress == address)
                    {
                        return(instanceId);
                    }
                }
            } finally {
                // make sure we clean up after ourselves!
                NativeMethods.SetupDiDestroyDeviceInfoList(hDevInfo);
            }
            // hmmm, we didn't find any BT radios?
            Debug.WriteLine("!! WindowsBluetoothRadio.GetRadioRegKey, radio NOT found!");
            return(null);
        }
Ejemplo n.º 4
0
 void AddKnownAddress(InTheHand.Net.BluetoothAddress value)
 {
 }
Ejemplo n.º 5
0
 bool IBluetoothSecurity.RevokePin(InTheHand.Net.BluetoothAddress device)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 //----
 bool IBluetoothSecurity.SetPin(InTheHand.Net.BluetoothAddress device, string pin)
 {
     throw new NotImplementedException();
 }