Beispiel #1
0
        private Object SyncControl(DeviceControlCode deviceControlCode,
                                   Object inBuffer, Object outBuffer)
        {
            Int32 bytesReturned;

            return(SyncControl(deviceControlCode, inBuffer, outBuffer, out bytesReturned));
        }
Beispiel #2
0
 public TResult GetObject <TResult>(DeviceControlCode deviceControlCode, Object inBuffer) where TResult : new()
 {
     if (!m_openedAsync)
     {
         return((TResult)SyncControl(deviceControlCode, inBuffer, new TResult()));
     }
     else
     {
         return(EndGetObject <TResult>(BeginGetObject <TResult>(deviceControlCode, inBuffer, null, null)));
     }
 }
Beispiel #3
0
 /// <summary>Sends a control code to the device driver synchronously along with an input buffer.</summary>
 /// <param name="deviceControlCode">The control code to send to the driver.</param>
 /// <param name="inBuffer">The input buffer to send to the driver.</param>
 public void Control(DeviceControlCode deviceControlCode, Object inBuffer)
 {
     if (!m_openedAsync)
     {
         SyncControl(deviceControlCode, inBuffer, null);
     }
     else
     {
         EndControl(BeginControl(deviceControlCode, inBuffer, null, null));
     }
 }
Beispiel #4
0
        private DeviceAsyncResult <T> AsyncControl <T>(DeviceControlCode deviceControlCode,
                                                       Object inBuffer, T outBuffer, AsyncCallback asyncCallback, Object state)
        {
            SafePinnedObject      inDeviceBuffer  = SafePinnedObject.FromObject(inBuffer);
            SafePinnedObject      outDeviceBuffer = SafePinnedObject.FromObject(outBuffer);
            DeviceAsyncResult <T> asyncResult     = new DeviceAsyncResult <T>(inDeviceBuffer, outDeviceBuffer, asyncCallback, state);

            unsafe {
                Int32 bytesReturned;
                NativeControl(deviceControlCode, inDeviceBuffer, outDeviceBuffer,
                              out bytesReturned, asyncResult.GetNativeOverlapped());
            }
            return(asyncResult);
        }
Beispiel #5
0
        private Object SyncControl(DeviceControlCode deviceControlCode,
                                   Object inBuffer, Object outBuffer, out Int32 bytesReturned)
        {
            using (SafePinnedObject inDeviceBuffer = SafePinnedObject.FromObject(inBuffer))
                using (SafePinnedObject outDeviceBuffer = SafePinnedObject.FromObject(outBuffer)) {
                    unsafe {
                        NativeControl(deviceControlCode, inDeviceBuffer, outDeviceBuffer,
                                      out bytesReturned, null);
                    }
                }

            // When passed, the argument for outBuffer got boxed so we return a reference
            // to the object that contains the data returned from DeviceIoControl.
            return(outBuffer);
        }
Beispiel #6
0
 public TElement[] GetArray <TElement>(DeviceControlCode deviceControlCode,
                                       Object inBuffer, Int32 maxElements) where TElement : struct
 {
     if (!m_openedAsync)
     {
         Int32      bytesReturned;
         TElement[] outBuffer = (TElement[])SyncControl(deviceControlCode,
                                                        inBuffer, new TElement[maxElements], out bytesReturned);
         Array.Resize <TElement>(ref outBuffer, bytesReturned / Marshal.SizeOf(typeof(TElement)));
         return(outBuffer);
     }
     else
     {
         return(EndGetArray <TElement>(BeginGetArray <TElement>(deviceControlCode, inBuffer, maxElements, null, null)));
     }
 }
Beispiel #7
0
        private unsafe void NativeControl(DeviceControlCode deviceControlCode,
                                          SafePinnedObject inBuffer, SafePinnedObject outBuffer,
                                          out Int32 bytesReturned, NativeOverlapped *nativeOverlapped)
        {
            Boolean ok = NativeMethods.DeviceIoControl(m_device, deviceControlCode.Code,
                                                       inBuffer, inBuffer.Size, outBuffer, outBuffer.Size, out bytesReturned, nativeOverlapped);

            if (ok)
            {
                return;
            }

            Int32       error            = Marshal.GetLastWin32Error();
            const Int32 c_ErrorIOPending = 997;

            if (error == c_ErrorIOPending)
            {
                return;
            }
            throw new InvalidOperationException(
                      String.Format(CultureInfo.CurrentCulture, "Control failed (code={0})", error));
        }
Beispiel #8
0
 protected IAsyncResult BeginGetObject <TResult>(DeviceControlCode deviceControlCode, Object inBuffer,
                                                 AsyncCallback asyncCallback, Object state) where TResult : new()
 {
     return(DeviceIO.BeginGetObject <TResult>(m_device, deviceControlCode, inBuffer, asyncCallback, state));
 }
Beispiel #9
0
 protected TResult GetObject <TResult>(DeviceControlCode deviceControlCode, Object inBuffer) where TResult : new()
 {
     return(DeviceIO.GetObject <TResult>(m_device, deviceControlCode, inBuffer));
 }
Beispiel #10
0
 protected TResult GetObject <TResult>(DeviceControlCode deviceControlCode) where TResult : new()
 {
     return(DeviceIO.GetObject <TResult>(m_device, deviceControlCode, null));
 }
Beispiel #11
0
 protected IAsyncResult BeginControl(DeviceControlCode deviceControlCode,
                                     Object inBuffer, AsyncCallback asyncCallback, Object state)
 {
     return(DeviceIO.BeginControl(m_device, deviceControlCode, inBuffer, asyncCallback, state));
 }
Beispiel #12
0
 protected void Control(DeviceControlCode deviceControlCode, Object inBuffer)
 {
     DeviceIO.Control(m_device, deviceControlCode, inBuffer);
 }
Beispiel #13
0
 protected void Control(DeviceControlCode deviceControlCode)
 {
     DeviceIO.Control(m_device, deviceControlCode);
 }
Beispiel #14
0
 /// <summary>Sends a control code to the device driver asynchronously along with an input buffer.</summary>
 /// <param name="deviceControlCode">The control code to send to the driver.</param>
 /// <param name="inBuffer">The input buffer to send to the driver.</param>
 /// <param name="asyncCallback">The method to be called when the asynchronous operation completes.</param>
 /// <param name="state">A user-provided object that distinguishes this particular asynchronous operation from other operations.</param>
 /// <returns>An IAsyncResult that references the asynchronous operation.</returns>
 public IAsyncResult BeginControl(DeviceControlCode deviceControlCode,
                                  Object inBuffer, AsyncCallback asyncCallback, Object state)
 {
     return(AsyncControl <Object>(deviceControlCode, inBuffer, null, asyncCallback, state));
 }
Beispiel #15
0
 protected TElement[] GetArray <TElement>(DeviceControlCode deviceControlCode, Object inBuffer, Int32 maxElements) where TElement : struct
 {
     return(DeviceIO.GetArray <TElement>(m_device, deviceControlCode, inBuffer, maxElements));
 }
Beispiel #16
0
 public TResult GetObject <TResult>(DeviceControlCode deviceControlCode) where TResult : new()
 {
     return(GetObject <TResult>(deviceControlCode, null));
 }
Beispiel #17
0
 public IAsyncResult BeginGetArray <TElement>(DeviceControlCode deviceControlCode,
                                              Object inBuffer, Int32 maxElements, AsyncCallback asyncCallback, Object state) where TElement : struct
 {
     return(AsyncControl(deviceControlCode, inBuffer, new TElement[maxElements], asyncCallback, state));
 }
Beispiel #18
0
 public IAsyncResult BeginGetObject <TResult>(DeviceControlCode deviceControlCode,
                                              Object inBuffer, AsyncCallback asyncCallback, Object state) where TResult : new()
 {
     return(AsyncControl(deviceControlCode, inBuffer, new TResult(), asyncCallback, state));
 }
Beispiel #19
0
 protected IAsyncResult BeginGetArray <TElement>(DeviceControlCode deviceControlCode, Object inBuffer,
                                                 Int32 maxElements, AsyncCallback asyncCallback, Object state) where TElement : struct
 {
     return(DeviceIO.BeginGetArray <TElement>(m_device, deviceControlCode, inBuffer, maxElements, asyncCallback, state));
 }
Beispiel #20
0
 /// <summary>Sends a control code to the device driver synchronously.</summary>
 /// <param name="deviceControlCode">The control code to send to the driver.</param>
 public void Control(DeviceControlCode deviceControlCode)
 {
     Control(deviceControlCode, null);
 }