public void DisconnectService(BluetoothConnection connection)
        {
            int connectionHandle = connection.ConnectionHandle;

            NativeMethods.BTSTATUS status = NativeMethods.BT_DisconnectService(connectionHandle);
            ValidateStatus(status);
            lookupConnections.Remove(connectionHandle);
            connections.Remove(connection);
            OnConnectionClosed(new BluetoothConnectionEventArgs(connection));
        }
        public BluetoothConnection ConnectService(BluetoothService service)
        {
            ValidateThread();
            int connectionHandle = 0;

            NativeMethods.BTSTATUS status = NativeMethods.BT_ConnectService(service.Device.DeviceInfo, service.ServiceInfo, ref connectionHandle);
            ValidateStatus(status);
            BluetoothConnection connection = new BluetoothConnection(this, service, connectionHandle);

            lookupConnections.Add(connectionHandle, connection);
            connections.Add(connection);

            OnConnectionOpened(new BluetoothConnectionEventArgs(connection));
            return(connection);
        }
        public IDevice Connect(IDeviceInfo deviceInfo)
        {
            BluesoleilDeviceInfo bluetoothDeviceInfo = (BluesoleilDeviceInfo)deviceInfo;

            Thread.Sleep(100);

            BluetoothConnection connection = BluesoleilService.Instance.ConnectService(bluetoothDeviceInfo.Service);

            ReportDevice device = null;

            foreach (KeyValuePair <string, SafeFileHandle> pair in MsHidDeviceProviderHelper.GetWiiDeviceHandles())
            {
                string         devicePath          = pair.Key;
                SafeFileHandle fileHandle          = pair.Value;
                Stream         communicationStream = new MsHidStream(fileHandle);

                // determine the device type
                if (bluetoothDeviceInfo.Name == "Nintendo RVL-WBC-01")
                {
                    device = new ReportBalanceBoard(deviceInfo, communicationStream);
                }
                else if (bluetoothDeviceInfo.Name == "Nintendo RVL-CNT-01")
                {
                    device = new ReportWiimote(deviceInfo, communicationStream);
                }
                else
                {
                    throw new ArgumentException("The specified deviceInfo with name '" + bluetoothDeviceInfo.Name + "' is not supported.", "deviceInfo");
                }

                if (MsHidDeviceProviderHelper.TryConnect(device, communicationStream, devicePath, fileHandle))
                {
                    break;
                }
                device = null;
            }
            if (device == null)
            {
                bluesoleil.DisconnectService(connection);
                throw new DeviceConnectException("The connected bluetooth device was not found in the HID-list.");
            }

            device.Disconnected += new EventHandler(device_Disconnected);
            lookupConnection.Add(bluetoothDeviceInfo.Address, connection);
            OnDeviceConnected(device);
            return(device);
        }
 public BluetoothConnectionEventArgs(BluetoothConnection BluetoothConnection)
 {
     bluetoothConnection = BluetoothConnection;
 }
 public void DisconnectService(BluetoothConnection connection)
 {
     int connectionHandle = connection.ConnectionHandle;
     NativeMethods.BTSTATUS status = NativeMethods.BT_DisconnectService(connectionHandle);
     ValidateStatus(status);
     lookupConnections.Remove(connectionHandle);
     connections.Remove(connection);
     OnConnectionClosed(new BluetoothConnectionEventArgs(connection));
 }
        public BluetoothConnection ConnectService(BluetoothService service)
        {
            ValidateThread();
            int connectionHandle = 0;
            NativeMethods.BTSTATUS status = NativeMethods.BT_ConnectService(service.Device.DeviceInfo, service.ServiceInfo, ref connectionHandle);
            ValidateStatus(status);
            BluetoothConnection connection = new BluetoothConnection(this, service, connectionHandle);

            lookupConnections.Add(connectionHandle, connection);
            connections.Add(connection);

            OnConnectionOpened(new BluetoothConnectionEventArgs(connection));
            return connection;
        }
 public BluetoothConnectionEventArgs(BluetoothConnection BluetoothConnection)
 {
     bluetoothConnection = BluetoothConnection;
 }