Exemplo n.º 1
0
        unsafe WindowsOverlappedAsyncResult BeginDeviceIoControl(int code, Byte[] inbuffer, Byte[] outbuffer, int outoffset, int outsize, AsyncCallback callback, Object state)
        {
            WindowsOverlappedAsyncResult ar = new WindowsOverlappedAsyncResult(callback, state);

            try
            {
                fixed(Byte *inptr = inbuffer, outptr = outbuffer)
                {
                    int     ret;
                    Boolean success = Kernel32.DeviceIoControl(DeviceHandle, code, inptr, inbuffer.Length, outptr + outoffset, outsize, out ret, ar.PackOverlapped(new Object[] { inbuffer, outbuffer }));

                    ar.SyncResult(success, ret);
                }
                return(ar);
            } catch {
                ar.ErrorCleanup();
                throw;
            }
        }
Exemplo n.º 2
0
        public override unsafe IAsyncResult BeginControlTransfer(UsbControlRequestType requestType, byte request, short value, short index, byte[] buffer, int offset, int length, AsyncCallback callback, Object state)
        {
            SafeWinUsbInterfaceHandle    ih = PrepareControlTransfer(requestType, index, ref buffer, offset, length);
            WindowsOverlappedAsyncResult ar = new WindowsOverlappedAsyncResult(callback, state);

            try
            {
                fixed(Byte *b = buffer)
                {
                    Boolean success = WinUsb_ControlTransfer(ih,
                                                             new UsbSetupPacket((byte)requestType, request, value, index, (short)length),
                                                             (IntPtr)(b + offset), length, out length, (IntPtr)ar.PackOverlapped(buffer));

                    ar.SyncResult(success, length);
                    return(ar);
                }
            } catch {
                ar.ErrorCleanup();
                throw;
            }
        }