Beispiel #1
0
        private bool TryConnect(MsHidDeviceInfo hidDeviceInfo, out ReportWiimote wiimote)
        {
            Stream hidStream;

            if (UseSetOutputReport)
            {
                hidStream = new MsHidSetOutputReportStream(hidDeviceInfo.DevicePath);
            }
            else
            {
                hidStream = new MsHidStream(hidDeviceInfo.DevicePath);
            }

            try
            {
                wiimote = new ReportWiimote(hidDeviceInfo, hidStream);
                wiimote.Initialize();
            }
            catch (TimeoutException)
            {
                hidStream.Dispose();
                wiimote = null;
                return(false);
            }
            catch (Exception)
            {
                hidStream.Dispose();
                throw;
            }
            return(true);
        }
        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;
        }
        private bool TryConnect(MsHidDeviceInfo hidDeviceInfo, out ReportWiimote wiimote)
        {
            Stream hidStream;
            if (UseSetOutputReport)
                hidStream = new MsHidSetOutputReportStream(hidDeviceInfo.DevicePath);
            else
                hidStream = new MsHidStream(hidDeviceInfo.DevicePath);

            try
            {
                wiimote = new ReportWiimote(hidDeviceInfo, hidStream);
                wiimote.Initialize();
            }
            catch (TimeoutException)
            {
                hidStream.Dispose();
                wiimote = null;
                return false;
            }
            catch (Exception)
            {
                hidStream.Dispose();
                throw;
            }
            return true;
        }