public PSVR(bool EnableSensor) { if (CurrentOS.IsWindows) { var ndev = UsbDevice.AllDevices.Where(d => d.Vid == 0x54C && d.Pid == 0x09AF && d.SymbolicName.ToLower().Contains("mi_05")).FirstOrDefault(); if (ndev == null) { throw new InvalidOperationException("No Control device found"); } if (!ndev.Open(out controlDevice)) { throw new InvalidOperationException("Device in use"); } ndev = UsbDevice.AllDevices.Where(d => d.Vid == 0x54C && d.Pid == 0x09AF && d.SymbolicName.ToLower().Contains("mi_04")).FirstOrDefault(); if (ndev == null) { controlDevice.Close(); throw new InvalidOperationException("No Sensor device found"); } if (EnableSensor) { if (!ndev.Open(out sensorDevice)) { controlDevice.Close(); throw new InvalidOperationException("Device in use"); } } writer = controlDevice.OpenEndpointWriter(LibUsbDotNet.Main.WriteEndpointID.Ep04); cmdReader = controlDevice.OpenEndpointReader(LibUsbDotNet.Main.ReadEndpointID.Ep04); cmdReader.DataReceived += CmdReader_DataReceived; cmdReader.DataReceivedEnabled = true; if (EnableSensor) { reader = sensorDevice.OpenEndpointReader(LibUsbDotNet.Main.ReadEndpointID.Ep03, 64); reader.DataReceived += Reader_DataReceived; reader.DataReceivedEnabled = true; } aliveTimer = new Timer(is_alive); aliveTimer.Change(2000, 2000); } else { var found = UsbDevice.AllDevices.Where(d => d.Vid == 0x54C && d.Pid == 0x09AF).FirstOrDefault(); controlDevice = found.Device; var dev = (MonoUsbDevice)controlDevice; var handle = new MonoUsbDeviceHandle(dev.Profile.ProfileHandle); MonoUsbApi.DetachKernelDriver(handle, 5); if (EnableSensor) { MonoUsbApi.DetachKernelDriver(handle, 4); } if (!dev.ClaimInterface(5)) { controlDevice.Close(); throw new InvalidOperationException("Device in use"); } if (EnableSensor) { if (!dev.ClaimInterface(4)) { controlDevice.Close(); throw new InvalidOperationException("Device in use"); } } writer = dev.OpenEndpointWriter(LibUsbDotNet.Main.WriteEndpointID.Ep04); if (EnableSensor) { reader = dev.OpenEndpointReader(LibUsbDotNet.Main.ReadEndpointID.Ep03, 64); reader.DataReceived += Reader_DataReceived; reader.DataReceivedEnabled = true; } } }