Compartir a través de


Agregar compatibilidad con eventos de sondeo

Para configurar correctamente el controlador WIA para notificar eventos de sondeo, haga lo siguiente:

  1. Establezca Capabilities=0x33 en el archivo INF del dispositivo. (Consulte Archivos INF para dispositivos WIA para obtener más información).

  2. Informe STI_GENCAP_NOTIFICATIONS y STI_USD_GENCAP_NATIVE_PUSHSUPPORT en el método IStiUSD::GetCapabilities .

  3. Informe de todos los eventos admitidos en el método IWiaMiniDrv::d rvGetCapabilities .

  4. Responda a las llamadas al método IStiUSD::GetStatus . El servicio WIA llama a este método en un intervalo preestablecido que se puede configurar en el archivo INF. La configuración predeterminada es un intervalo de 1 segundo.

  5. Informe de la respuesta de información de eventos adecuada en el método IStiUSD::GetNotificationData .

El servicio WIA llama al método IStiUSD::GetStatus para dos operaciones principales:

  1. Comprobar el estado en línea del dispositivo.

  2. Sondear eventos de dispositivo, como un evento de botón de inserción.

Para determinar la solicitud de operación, compruebe el miembro StatusMask de la estructura STI_DEVICE_STATUS . El miembro StatusMask puede ser una de las siguientes solicitudes:

STI_DEVSTATUS_ONLINE_STATE
Esta solicitud de operación comprueba si el dispositivo está en línea y debe rellenarse estableciendo el miembro dwOnlinesState de la estructura STI_DEVICE_STATUS.

STI_DEVSTATUS_EVENTS_STATE
Esta solicitud de operación comprueba si hay eventos de dispositivo. Debe rellenarse estableciendo el miembro dwEventHandlingState de la estructura STI_DEVICE_STATUS. El valor que se debe usar es STI_EVENTHANDLING_PENDING. (El dispositivo tiene un evento pendiente y está esperando notificarlo al servicio WIA).

Cuando se establece STI_EVENTHANDLING_PENDING, se señala al servicio WIA que se ha producido un evento en el controlador WIA. El servicio WIA llama al método IStiUSD::GetNotificationData para obtener más información sobre el evento.

Se llama al método IStiUSD::GetNotificationData para eventos sondeados y eventos de interrupción. Se encuentra en este método que debe rellenar la información de eventos adecuada para volver al servicio WIA.

Nota Borre siempre la marca STI_EVENTHANDLING_PENDING en el miembro dwEventHandlingState para asegurarse de que se establece correctamente cuando se produce un evento de dispositivo. Este controlador WIA debe establecer la variable de miembro de clase m_guidLastEvent en el GUID de evento adecuado cuando se detecta un evento. El m_guidLastEvent se comprueba más adelante cuando el servicio WIA llama al método IStiUSD::GetNotificationData . La variable miembro m_guidLastEvent se define en la clase CWIADevice (en el siguiente fragmento de código), que se usa para almacenar en caché el último evento señalado. Una vez que el servicio WIA ha solicitado esta variable miembro, siempre se establece en GUID_NULL.

En el ejemplo siguiente se muestra una implementación del método IStiUSD::GetStatus .

STDMETHODIMP CWIADevice::GetStatus(PSTI_DEVICE_STATUS pDevStatus)
{
  //
  // If the caller did not pass in the correct parameters,
  // then fail the call with E_INVALIDARG.
  //

  if(!pDevStatus)
  {
      return E_INVALIDARG;
  }

  HRESULT hr = S_OK;

  //
  // If we are asked, verify state of an event handler 
  //(front panel buttons, user controlled attachments, etc.).
  //
  // If your device requires polling, then this is where you would
  // specify the event result.
  // However, It is not recommended to have polled events.
  // Interrupt events are better for performance, and reliability.
  // See the SetNotificationsHandle method for how to
  // implement interrupt events.
  //

  //
  // clear the dwEventHandlingState field first to make sure we are really setting
  // a pending event.
  //

  pDevStatus->dwEventHandlingState &= ~STI_EVENTHANDLING_PENDING;
  if (pDevStatus->StatusMask & STI_DEVSTATUS_EVENTS_STATE) {

    //
    // set the polled event result here, for the GetNotificationData()
    // method to read and report.
    // (m_guidLastEvent will be read in GetNotificationData)
    //

    LONG lEventResult = 0;
    PollMyDeviceForEvents(&lEventResult)

    if(lEventResult == DEVICE_SCAN_BUTTON_PRESSED) {

        //
        // polled event result was one we know about
        //

        m_guidLastEvent = WIA_EVENT_SCAN_IMAGE;
    } else {

        //
        // nothing happened, so continue
        //

        m_guidLastEvent = GUID_NULL;
    }

    if (m_guidLastEvent != GUID_NULL) {

        //
        // if the event GUID is NOT GUID_NULL, set the
        // STI_EVENTHANDLING_PENDING flag letting the WIA service
        // know that we have an event ready. This will tell the WIA
        // service to call GetNotificationData() for the event
        // specific information.
        //

        pDevStatus->dwEventHandlingState |= STI_EVENTHANDLING_PENDING;
    }
  }
  return S_OK;
}