public IDevice Connect(IDeviceInfo deviceInfo) { MsHidDeviceInfo hidDeviceInfo = deviceInfo as MsHidDeviceInfo; if (hidDeviceInfo == null) { throw new ArgumentException("The specified DeviceInfo does not belong to this DeviceProvider.", "deviceInfo"); } ReportWiimote wiimote; if (!TryConnect(hidDeviceInfo, out wiimote)) { UseSetOutputReport = !UseSetOutputReport; if (!TryConnect(hidDeviceInfo, out wiimote)) { throw new DeviceConnectException("Both methods of connecting timed out."); } } wiimote.Disconnected += device_Disconnected; ConnectedDevices.Add(wiimote); MsHidDeviceProviderHelper.SetDevicePathConnected(hidDeviceInfo.DevicePath, true); OnDeviceConnected(new DeviceEventArgs(wiimote)); return(wiimote); }
void device_Disconnected(object sender, EventArgs e) { ReportWiimote wiimote = (ReportWiimote)sender; MsHidDeviceInfo deviceInfo = (MsHidDeviceInfo)wiimote.DeviceInfo; wiimote.Disconnected -= device_Disconnected; ConnectedDevices.Remove(wiimote); MsHidDeviceProviderHelper.SetDevicePathConnected(deviceInfo.DevicePath, false); OnDeviceDisconnected(new DeviceEventArgs(wiimote)); }