Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using PC gateway

Follow these steps to use PC gateway to connect to a device:

  1. Create an instance of IDeviceBridge.
  2. Create a signal and register for device changes (such as connect or disconnect).
  3. Get a list of connected devices.

    A signal will not be received for devices that are already connected to the gateway. If no devices are connected, wait for the signal.

  4. Get an opener for the device.

    The following code example shows how to implement the first four steps:

    #define ERR_BAIL(f) { nErr=(f); if (AEE_SUCCESS != nErr) goto bail; }
    
    Int getOpener(MyObj* me, IQI** ppiOpener)
    {
       int   nErr   = AEE_EFAILED;
       int   needed = 0;
    
       ISignalQ*      piSignalQ   = 0;
       ISignalCtl*    piSigChange = 0;
       IDeviceBridge* piDevBr = 0;
    
       // Create an instance of IDeviceBridge
       ERR_BAIL(IEnv_CreateInstance(me->piEnv, AEECLSID_USBDeviceBridge,
                (void**) &piDevBr));
    
       // Create a signal to be used for OnChange
       ERR_BAIL(IEnv_CreateInstance(me->piEnv, AEECLSID_SignalQ,
                (void**)&piSignalQ));
       ERR_BAIL(ISignalQ_CreateSignal(piSignalQ, 0, (void*)1, (ISignal**)0,
                &piSigChange));
    
       // Register the signal
       ERR_BAIL(IDeviceBridge_OnChange(piDevBr, (ISignal*) piSigChange));
       ISignalCtl_Enable(piSigChange);
    
       //Get currently connected devices
       ERR_BAIL(IDeviceBridge_GetDevices(piDevBr, deviceIDs,
                sizeof(deviceIDs)/sizeof(int), &needed));
    
       // If no devices are currently connected, wait for the
       // signal (OnChange signal)
       if (!needed) {
          SignalData ud;
    
          ISignalQ_Pop(piSignalQ, &ud);
          switch((uint32)ud.pv) {
             case 1:
                ERR_BAIL(IDeviceBridge_GetDevices(piDevBr, deviceIDs,
                         sizeof(deviceIDs)/sizeof(int), &needed));
                break;
    
             default:
                nErr = AEE_EFAILED;
                goto bail;
          }
       }
    
       if (!needed) {
          nErr = AEE_EFAILED;
          goto bail;
       }
    
       // Get an Opener for the first device
       nErr = IDeviceBridge_GetOpener(piDevBr, deviceIDs[0], ppiOpener);
       
    bail:
       IQI_RELEASEIF(piSigChange);
       IQI_RELEASEIF(piSignalQ);
       IQI_RELEASEIF(piDevBr);
       return nErr;
    }
  5. Use the opener obtained from IDeviceBridge_GetOpener() to create a remote instance of a service from the device, as follows:
    Creating a remote instance of a service from the device
    int useOpener(IQI* piOpener, IQI** ppiRemoteService)
    {
       IRemoteOpener* piro = NULL;
       IRemoteRef*    pirr = NULL;
    
       int nErr;
    
       ERR_BAIL(IQI_QueryInterface(piOpener, AEEIID_IRemoteOpener,
                (void**)&piro));
       ERR_BAIL(IRemoteOpener_Open(piro, ,
                , &pirr));
       ERR_BAIL(IRemoteRef_GetInterface(pirr, ,
                ppiRemoteService));
    
    bail:
       IQI_RELEASEIF(piro);
       IQI_RELEASEIF(pirr);
     }