private void PollTimer_Elapsed(object state) { lock (PollTimerLock) { mDeviceListPollTimer.Change(-1, -1); MonoUsbDevice.RefreshProfileList(); mDeviceListPollTimer.Change(PollingInterval, PollingInterval); } }
private void PollTimer_Elapsed(object sender, ElapsedEventArgs e) { lock (PollTimerLock) { mDeviceListPollTimer.Stop(); MonoUsbDevice.RefreshProfileList(); mDeviceListPollTimer.Start(); } }
public override void OpenDevice() { log.Info("QDLUsb trying to find device"); UsbDevice.UsbErrorEvent += new EventHandler <UsbError>(UsbErrorEvent); UsbRegistry regDev = null; if (Environment.OSVersion.Platform == PlatformID.Win32NT) { regDev = UsbDevice.AllWinUsbDevices.Find((reg) => reg.Vid == VID && reg.Pid == PID); } else { regDev = UsbDevice.AllDevices.Find((reg) => reg.Vid == VID && reg.Pid == PID); } if (regDev == null) { log.Error("No QDLUSB Devices found"); throw new QDLDeviceNotFoundException("Unable to find device"); } if (!regDev.Open(out device) || device == null) { log.Error("No QDLUSB Devices found"); throw new QDLDeviceNotFoundException("Unable to open device"); } if (UsbDevice.IsLinux) { log.Debug("Running on linux, detaching kernel driver"); MonoUsbDevice monodev = device as MonoUsbDevice; if (!monodev.DetachKernelDriver()) { log.Error("Failed to detach kernel driver"); throw new Exception("Failed to detach kernel driver"); } } IUsbDevice wholeUsbDevice = device as IUsbDevice; if (wholeUsbDevice != null) { wholeUsbDevice.SetConfiguration(1); wholeUsbDevice.ClaimInterface(0); } reader = device.OpenEndpointReader(ReadEndpointID.Ep01); writer = device.OpenEndpointWriter(WriteEndpointID.Ep01, EndpointType.Bulk); if (reader == null || writer == null) { device.Close(); device = null; UsbDevice.Exit(); log.Error("Failed to open endpoints"); throw new Exception("Unable to open endpoints"); } log.Info("Found QDLUSB device"); }
private void StartDeviceListPolling() { lock (PollTimerLock) { if (mDeviceListPollTimer != null) { return; } MonoUsbDevice.RefreshProfileList(); MonoUsbDevice.ProfileList.AddRemoveEvent += OnAddRemoveEvent; mDeviceListPollTimer = new Timer(PollTimer_Elapsed, null, PollingInterval, PollingInterval); } }
private void syncWith(MonoUsbProfileList newList) { SetDiscovered(false); newList.SetDiscovered(true); int iNewProfiles = newList.mList.Count; for (int iNewProfile = 0; iNewProfile < iNewProfiles; iNewProfile++) { MonoUsbProfile newProfile = newList.mList[iNewProfile]; int iFoundOldIndex; if ((iFoundOldIndex = mList.IndexOf(newProfile)) == -1) { //Console.WriteLine("DeviceDiscovery: Added: {0}", newProfile.ProfileHandle.DangerousGetHandle()); newProfile.mDiscovered = true; //Super hackish way to add serial MonoUsbDevice dev = new MonoUsbDevice(ref newProfile); newProfile.mSerial = dev.Info.SerialString; mList.Add(newProfile); FireAddRemove(newProfile, AddRemoveType.Added); } else { //Console.WriteLine("DeviceDiscovery: Unchanged: Orig:{0} New:{1}", mList[iFoundOldIndex].ProfileHandle.DangerousGetHandle(), newProfile.ProfileHandle.DangerousGetHandle()); mList[iFoundOldIndex].mDiscovered = true; newProfile.mDiscovered = false; } } newList.mList.RemoveAll(FindDiscoveredFn); newList.Close(); foreach (MonoUsbProfile deviceProfile in mList) { if (!deviceProfile.mDiscovered) { // Close Unplugged device profiles. //Console.WriteLine("DeviceDiscovery: Removed: {0}", deviceProfile.ProfileHandle.DangerousGetHandle()); FireAddRemove(deviceProfile, AddRemoveType.Removed); deviceProfile.Close(); } } // Remove Unplugged device profiles. mList.RemoveAll(FindUnDiscoveredFn); }
public UsbConfigInfo ToUsbConfigInfo(MonoUsbDevice usbDevice) { List <UsbInterfaceInfo> usbInterfaceInfos = new List <UsbInterfaceInfo>(); foreach (MonoUsbInterface usbInterface in InterfaceList) { List <MonoUsbAltInterfaceDescriptor> monoUSBAltInterfaces = usbInterface.AltInterfaceList; foreach (MonoUsbAltInterfaceDescriptor monoUSBAltInterface in monoUSBAltInterfaces) { UsbInterfaceInfo usbInterfaceInfo = monoUSBAltInterface.ToUsbInterfaceInfo(usbDevice); usbInterfaceInfos.Add(usbInterfaceInfo); } } return(new UsbConfigInfo(usbDevice, this, usbInterfaceInfos)); }
internal UsbConfigInfo(MonoUsbDevice usbDevice, MonoUsbConfigDescriptor configDescriptor) { mUsbDevice = usbDevice; mUsbConfigDescriptor = new UsbConfigDescriptor(configDescriptor); List <MonoUsbInterface> monoUSBInterfaces = configDescriptor.InterfaceList; foreach (MonoUsbInterface usbInterface in monoUSBInterfaces) { List <MonoUsbAltInterfaceDescriptor> monoUSBAltInterfaces = usbInterface.AltInterfaceList; foreach (MonoUsbAltInterfaceDescriptor monoUSBAltInterface in monoUSBAltInterfaces) { UsbInterfaceInfo usbInterfaceInfo = new UsbInterfaceInfo(mUsbDevice, monoUSBAltInterface); mInterfaceList.Add(usbInterfaceInfo); } } }
private static bool FillWindowsMonoUsbDeviceRegistry(UsbRegistry usbRegistry, MonoUsbDevice usbDevice) { MonoLibUsb.MonoUsbApi.internal_windows_device_priv priv = MonoLibUsb.MonoUsbApi.GetWindowsPriv(usbDevice.Profile.ProfileHandle); string path; for (int i = 0; i < 32; i++) { if (priv.usb_interfaces[i].path == IntPtr.Zero) { break; } path = Marshal.PtrToStringAnsi(priv.usb_interfaces[i].path); //Debug.Print("Intf:{0} Path:{1}",i,path); } path = Marshal.PtrToStringAnsi(priv.path); bool bFound = false; //System.Diagnostics.Debug.WriteLine(sb.ToString()); path = path.ToString().ToLower().Replace("#", "\\"); foreach (MasterItem masterItem in mMasterSetupApiDeviceList) { if (path.Contains(masterItem[DEVICE_ID_KEY].ToString().ToLower())) { usbRegistry.mDeviceProperties = masterItem; bFound = true; break; } } return(bFound); }