Beispiel #1
0
        /// <summary>
        /// Gets a descriptor from the device. See <see cref="DescriptorType"/> for more information.
        /// </summary>
        /// <param name="descriptorType">The descriptor type ID to retrieve; this is usually one of the <see cref="DescriptorType"/> enumerations.</param>
        /// <param name="index">Descriptor index.</param>
        /// <param name="langId">Descriptor language id.</param>
        /// <param name="buffer">Memory to store the returned descriptor in.</param>
        /// <param name="bufferLength">Length of the buffer parameter in bytes.</param>
        /// <param name="transferLength">The number of bytes transferred to buffer upon success.</param>
        /// <returns>True on success.</returns>
        public override bool GetDescriptor(byte descriptorType, byte index, short langId, IntPtr buffer, int bufferLength, out int transferLength)
        {
            transferLength = 0;
            bool bSuccess = false;
            bool wasOpen  = IsOpen;

            if (!wasOpen)
            {
                Open();
            }
            if (!IsOpen)
            {
                return(false);
            }

            int ret = MonoUsbApi.GetDescriptor((MonoUsbDeviceHandle)mUsbHandle, descriptorType, index, buffer, (ushort)bufferLength);

            if (ret < 0)
            {
                UsbError.Error(ErrorCode.MonoApiError, ret, "GetDescriptor Failed", this);
            }
            else
            {
                bSuccess       = true;
                transferLength = ret;
            }

            if (!wasOpen && IsOpen)
            {
                Close();
            }

            return(bSuccess);
        }