Contains members that are specific to the LibUsb-Win32 driver.
Use the T:LibUsbDotNet.UsbDevice class instead to allow your code to work with either LibUsb or WinUsb.
Inheritance: UsbDevice, IUsbDevice
示例#1
0
        /// <summary>
        /// Opens the USB device for communucation.
        /// </summary>
        /// <param name="usbDevice">The newly created UsbDevice.</param>
        /// <returns>True on success.</returns>
        public bool Open(out LibUsbDevice usbDevice)
        {
            bool bSuccess = LibUsbDevice.Open(mDeviceFilename, out usbDevice);

            if (bSuccess)
            {
                usbDevice.mUsbRegistry = this;
            }

            return(bSuccess);
        }
示例#2
0
        /// <summary>
        /// Opens the USB device for communucation.
        /// </summary>
        /// <param name="deviceFilename">The LibUsb device filename to open.</param>
        /// <param name="usbDevice">The newly created UsbDevice.</param>
        /// <returns>True on success.</returns>
        public static bool Open(string deviceFilename, out LibUsbDevice usbDevice)
        {
            usbDevice = null;
            SafeFileHandle sfh = LibUsbDriverIO.OpenDevice(deviceFilename);

            if (!sfh.IsClosed && !sfh.IsInvalid)
            {
                usbDevice = new LibUsbDevice(LibUsbApi, sfh, deviceFilename);
                return(true);
            }
            else
            {
//                UsbDevice.Error(ErrorCode.DeviceNotFound, "The device is no longer attached or failed to open.", typeof(LibUsbDevice));
            }
            return(false);
        }
示例#3
0
        private LibUsbRegistry(SafeFileHandle usbHandle, string deviceFileName, int deviceIndex)
        {
            mDeviceFilename = deviceFileName;
            mDeviceIndex    = deviceIndex;
            GetPropertiesSPDRP(usbHandle);
            string symbolicName;

            if (GetCustomDeviceKeyValue(usbHandle, SYMBOLIC_NAME_KEY, out symbolicName, 512) == ErrorCode.None)
            {
                symbolicName = FixSymbolicName(symbolicName);

                mDeviceProperties.Add(SYMBOLIC_NAME_KEY, symbolicName);
            }

            string regKeyPathnameStr;

            GetObjectName(usbHandle, 0, out regKeyPathnameStr);
            mDeviceProperties.Add("DevicePlugPlayRegistryKey", regKeyPathnameStr);

            // If the SymbolicName key does not exists, use the first HardwareID string.
            if (!mDeviceProperties.ContainsKey(SYMBOLIC_NAME_KEY) || String.IsNullOrEmpty(symbolicName))
            {
                string[] hwIDs = mDeviceProperties[SPDRP.HardwareId.ToString()] as string[];

                if ((hwIDs == null) || hwIDs.Length == 0)
                {
                    LibUsbDevice usbDevice = new LibUsbDevice(UsbDevice.LibUsbApi, usbHandle, deviceFileName);
                    LegacyUsbRegistry.GetPropertiesSPDRP(usbDevice, mDeviceProperties);
                    return;
                }

                if (hwIDs.Length > 0)
                {
                    mDeviceProperties.Add(SYMBOLIC_NAME_KEY, hwIDs[0]);
                }
            }

            string deviceInterfaceGuids;

            if (GetCustomDeviceKeyValue(usbHandle, LIBUSB_INTERFACE_GUIDS, out deviceInterfaceGuids, 512) == ErrorCode.None)
            {
                string[] deviceInterfaceGuidsArray = deviceInterfaceGuids.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);

                mDeviceProperties.Add(LIBUSB_INTERFACE_GUIDS, deviceInterfaceGuidsArray);
            }
        }
        internal UsbConfigInfo(LibUsbDevice usbDevice, LibUsbConfigDescriptor configDescriptor)
        {
            mUsbDevice = usbDevice;

            mUsbConfigDescriptor = new UsbConfigDescriptor(configDescriptor);

            List<LibUsbInterface> monoUSBInterfaces = configDescriptor.InterfaceList;
            foreach (LibUsbInterface usbInterface in monoUSBInterfaces)
            {
                List<LibUsbAltInterfaceDescriptor> monoUSBAltInterfaces = usbInterface.AltInterfaceList;
                foreach (LibUsbAltInterfaceDescriptor monoUSBAltInterface in monoUSBAltInterfaces)
                {
                    UsbInterfaceInfo usbInterfaceInfo = new UsbInterfaceInfo(mUsbDevice, monoUSBAltInterface);
                    mInterfaceList.Add(usbInterfaceInfo);
                }
            }
        }
示例#5
0
        private LibUsbRegistry(SafeFileHandle usbHandle, string deviceFileName, int deviceIndex)
        {
            mDeviceFilename = deviceFileName;
            mDeviceIndex = deviceIndex;
            GetPropertiesSPDRP(usbHandle);
            string symbolicName;

            if (GetCustomDeviceKeyValue(usbHandle, SYMBOLIC_NAME_KEY, out symbolicName, 512) == ErrorCode.None)
            {
                symbolicName = FixSymbolicName(symbolicName);

                mDeviceProperties.Add(SYMBOLIC_NAME_KEY, symbolicName);
            }

            string regKeyPathnameStr;
            GetObjectName(usbHandle, 0, out regKeyPathnameStr);
            mDeviceProperties.Add("DevicePlugPlayRegistryKey", regKeyPathnameStr);

            // If the SymbolicName key does not exists, use the first HardwareID string.
            if (!mDeviceProperties.ContainsKey(SYMBOLIC_NAME_KEY) || String.IsNullOrEmpty(symbolicName))
            {
                string[] hwIDs = mDeviceProperties[SPDRP.HardwareId.ToString()] as string[];

                if ((hwIDs == null) || hwIDs.Length==0)
                {
                    LibUsbDevice usbDevice = new LibUsbDevice(UsbDevice.LibUsbApi, usbHandle, deviceFileName);
                    LegacyUsbRegistry.GetPropertiesSPDRP(usbDevice, mDeviceProperties);
                    return;
                }

                if (hwIDs.Length > 0)
                {
                    mDeviceProperties.Add(SYMBOLIC_NAME_KEY, hwIDs[0]);
                }
            }

            string deviceInterfaceGuids;
            if (GetCustomDeviceKeyValue(usbHandle, LIBUSB_INTERFACE_GUIDS, out deviceInterfaceGuids, 512) == ErrorCode.None)
            {
                string[] deviceInterfaceGuidsArray = deviceInterfaceGuids.Split(new char[] {'\0'}, StringSplitOptions.RemoveEmptyEntries);

                mDeviceProperties.Add(LIBUSB_INTERFACE_GUIDS, deviceInterfaceGuidsArray);
            }
        }
        /// <summary>
        /// Opens the USB device for communucation.
        /// </summary>
        /// <param name="usbDevice">The newly created UsbDevice.</param>
        /// <returns>True on success.</returns>
        public bool Open(out LibUsbDevice usbDevice)
        {
            bool bSuccess = LibUsbDevice.Open(mDeviceFilename, out usbDevice);
            if (bSuccess)
            {
                usbDevice.mUsbRegistry = this;
            }

            return bSuccess;
        }
        private static ErrorCode GetConfigs(LibUsbDevice usbDevice, out List<UsbConfigInfo> configInfoListRtn)
        {
            configInfoListRtn = new List<UsbConfigInfo>();
            UsbError usbError = null;
            List<LibUsbConfigDescriptor> configList = new List<LibUsbConfigDescriptor>();
            int iConfigs = usbDevice.Info.Descriptor.ConfigurationCount;

            for (int iConfig = 0; iConfig < iConfigs; iConfig++)
            {
                LibUsbConfigHandle nextConfigHandle;
                int ret = LibUsbApi.GetConfigDescriptor(usbDevice.mMonoUSBProfile.ProfileHandle, (byte) iConfig, out nextConfigHandle);
                Debug.Print("GetConfigDescriptor:{0}", ret);
                if (ret != 0 || nextConfigHandle.IsInvalid)
                {
                    usbError = UsbError.Error(ErrorCode.MonoApiError,
                                              ret,
                                              String.Format("GetConfigDescriptor Failed at index:{0}", iConfig),
                                              usbDevice);
                    return usbError.ErrorCode;
                }
                try
                {
                    LibUsbConfigDescriptor nextConfig = new LibUsbConfigDescriptor();
                    Marshal.PtrToStructure(nextConfigHandle.DangerousGetHandle(), nextConfig);

                    UsbConfigInfo nextConfigInfo = new UsbConfigInfo(usbDevice, nextConfig);
                    configInfoListRtn.Add(nextConfigInfo);
                }
                catch (Exception ex)
                {
                    UsbError.Error(ErrorCode.InvalidConfig, Marshal.GetLastWin32Error(), ex.ToString(), usbDevice);
                }
                finally
                {
                    if (!nextConfigHandle.IsInvalid)
                        nextConfigHandle.Close();
                }
            }

            return ErrorCode.Success;
        }
示例#8
0
 /// <summary>
 /// Opens the USB device for communucation.
 /// </summary>
 /// <param name="deviceFilename">The LibUsb device filename to open.</param>
 /// <param name="usbDevice">The newly created UsbDevice.</param>
 /// <returns>True on success.</returns>
 public static bool Open(string deviceFilename, out LibUsbDevice usbDevice)
 {
     usbDevice = null;
     SafeFileHandle sfh = LibUsbDriverIO.OpenDevice(deviceFilename);
     if (!sfh.IsClosed && !sfh.IsInvalid)
     {
         usbDevice = new LibUsbDevice(LibUsbApi, sfh, deviceFilename);
         return true;
     }
     else
     {
     //                UsbDevice.Error(ErrorCode.DeviceNotFound, "The device is no longer attached or failed to open.", typeof(LibUsbDevice));
     }
     return false;
 }
示例#9
0
		private void usbDisconnected()
		{
			_usbDevice = null;
			lblStatus.Text = "Not Connected";
		}
示例#10
0
		private void tmrUSBCheck_Tick(object sender, EventArgs e)
		{
			if (_usbDevice == null)
			{
				// (0x16C1, "Nima Alamatsaz", 0x15DC, "AVROscope")
				foreach (LibUsbRegistry reg in LibUsbDevice.AllLibUsbDevices)
					if (reg.Vid == 0x16C1 && reg.Pid == 0x0002 && reg.Device.Info.ManufacturerString == "Nima Alamatsaz" && reg.Device.Info.ProductString == "AVROscope")
					{
						_usbDevice = (LibUsbDevice)reg.Device;
						if (_usbDevice.Open())
							lblStatus.Text = "Connected";
						else
						{
							lblStatus.Text = "Can't Connect";
							_usbDevice = null;
						}
					}
			}
		}