internal Device(UvcDevice device) { handle = device; IntPtr descriptor; var error = NativeMethods.uvc_get_device_descriptor(handle, out descriptor); UvcException.ThrowExceptionForUvcError(error); try { vendorId = (ushort)Marshal.ReadInt16(descriptor); productId = (ushort)Marshal.ReadInt16(descriptor, 2); complianceLevel = (ushort)Marshal.ReadInt16(descriptor, 4); } finally { NativeMethods.uvc_free_device_descriptor(descriptor); } }
internal Device(UvcDevice device) { handle = device; IntPtr descriptor; var error = NativeMethods.uvc_get_device_descriptor(handle, out descriptor); UvcException.ThrowExceptionForUvcError(error); try { vendorId = (ushort)Marshal.ReadInt16(descriptor); productId = (ushort)Marshal.ReadInt16(descriptor, 2); complianceLevel = (ushort)Marshal.ReadInt16(descriptor, 4); serialNumber = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(descriptor, 6)); manufacturer = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(descriptor, 6 + IntPtr.Size)); product = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(descriptor, 6 + IntPtr.Size * 2)); } finally { NativeMethods.uvc_free_device_descriptor(descriptor); } }
public IEnumerable <Device> GetDevices() { IntPtr devices; var error = NativeMethods.uvc_get_device_list(handle, out devices); UvcException.ThrowExceptionForUvcError(error); try { int i = 0; IntPtr devh; while ((devh = Marshal.ReadIntPtr(devices, IntPtr.Size * i++)) != IntPtr.Zero) { var device = new UvcDevice(devh); yield return(new Device(device)); } } finally { NativeMethods.uvc_free_device_list(devices, 1); } }
public IEnumerable <Device> FindDevices(int vendorId = 0, int productId = 0, string serialNumber = null) { IntPtr devices; var error = NativeMethods.uvc_find_devices(handle, out devices, vendorId, productId, serialNumber); UvcException.ThrowExceptionForUvcError(error); try { int i = 0; IntPtr devh; while ((devh = Marshal.ReadIntPtr(devices, IntPtr.Size * i++)) != IntPtr.Zero) { var device = new UvcDevice(devh); yield return(new Device(device)); } } finally { NativeMethods.uvc_free_device_list(devices, 1); } }
internal static extern void uvc_ref_device(UvcDevice dev);
internal static extern UvcError uvc_open(UvcDevice dev, out UvcDeviceHandle devh);
internal static extern UvcError uvc_find_device( UvcContext ctx, out UvcDevice dev, int vid, int pid, string sn);
internal static extern UvcError uvc_get_device_descriptor(UvcDevice dev, out IntPtr desc);