Esempio n. 1
0
        private Object SyncControl(DeviceControlCode deviceControlCode,
                                   Object inBuffer, Object outBuffer)
        {
            Int32 bytesReturned;

            return(SyncControl(deviceControlCode, inBuffer, outBuffer, out bytesReturned));
        }
Esempio n. 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)));
     }
 }
Esempio n. 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));
     }
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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)));
     }
 }
Esempio n. 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));
        }
Esempio n. 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));
 }
Esempio n. 9
0
 protected TResult GetObject <TResult>(DeviceControlCode deviceControlCode, Object inBuffer) where TResult : new()
 {
     return(DeviceIO.GetObject <TResult>(m_device, deviceControlCode, inBuffer));
 }
Esempio n. 10
0
 protected TResult GetObject <TResult>(DeviceControlCode deviceControlCode) where TResult : new()
 {
     return(DeviceIO.GetObject <TResult>(m_device, deviceControlCode, null));
 }
Esempio n. 11
0
 protected IAsyncResult BeginControl(DeviceControlCode deviceControlCode,
                                     Object inBuffer, AsyncCallback asyncCallback, Object state)
 {
     return(DeviceIO.BeginControl(m_device, deviceControlCode, inBuffer, asyncCallback, state));
 }
Esempio n. 12
0
 protected void Control(DeviceControlCode deviceControlCode, Object inBuffer)
 {
     DeviceIO.Control(m_device, deviceControlCode, inBuffer);
 }
Esempio n. 13
0
 protected void Control(DeviceControlCode deviceControlCode)
 {
     DeviceIO.Control(m_device, deviceControlCode);
 }
Esempio n. 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));
 }
Esempio n. 15
0
 protected TElement[] GetArray <TElement>(DeviceControlCode deviceControlCode, Object inBuffer, Int32 maxElements) where TElement : struct
 {
     return(DeviceIO.GetArray <TElement>(m_device, deviceControlCode, inBuffer, maxElements));
 }
Esempio n. 16
0
 public TResult GetObject <TResult>(DeviceControlCode deviceControlCode) where TResult : new()
 {
     return(GetObject <TResult>(deviceControlCode, null));
 }
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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);
 }