Exemple #1
0
        public unsafe virtual bool FinishDataXfer(ref byte[] singleXfer, ref byte[] buffer, ref int len, ref byte[] ov)
        {
            bool rResult;

            uint[] bytes = new uint[1];

            // DWY fix single variable during call by converting it into an 'array of 1'
            //  and fixing it to a pointer.
            fixed(uint *buf0 = bytes)
            {
                fixed(byte *buf = singleXfer)
                {
                    SINGLE_TRANSFER *transfer = (SINGLE_TRANSFER *)buf;

                    rResult = PInvoke.GetOverlappedResult(_hDevice, ov, ref bytes[0], 0);
                    if (rResult == false)
                    {
                        transfer->NtStatus = PInvoke.GetLastError();
                    }
                }
            }

            len = (int)bytes[0];

            fixed(byte *buf = singleXfer)
            {
                SINGLE_TRANSFER *transfer = (SINGLE_TRANSFER *)buf;

                _usbdStatus = transfer->UsbdStatus;
                _ntStatus   = transfer->NtStatus;

                if ((XferMode == XMODE.BUFFERED) && (len > 0))
                {
                    //len -= (int)transfer->BufferOffset; This is not required becuse we pass the actual data buffer length
                    for (int i = 0; i < len; i++)
                    {
                        buffer[i] = buf[transfer->BufferOffset + i];
                    }
                }
            }

            _bytesWritten = (uint)len;

            return(rResult && (_usbdStatus == 0) && (_ntStatus == 0));
        }