Obtaining Operating Condition Data

Vehicle status data is obtained from the IVIO_Device interface to two types of vehicle devices: polled devices and streaming devices. Polled devices provide relatively static data, such as coolant temperature. Streaming devices provide dynamic data, such as RPM.

    To retrieve data from a polled device

  1. Obtain a reference to the interface for the device with CoCreateInstance.
  2. Retrieve the data by calling the appropriate method calls for the device, such as GetData.
  3. Release the reference to the device interface.

    To set up data retrieval from a streaming device

  1. Write a callback object for the device to invoke.
  2. Obtain a reference to the interface for the device using CoCreateInstance.
  3. Obtain a reference to an instance of the callback object’s IUnknown interface.
  4. Obtain a reference to the callback object’s IVioEventSink interface.
  5. Release the reference to the callback object’s IUnknown interface.
  6. Set the device’s notification routine to be the callback object’s IVioEventSink interface.

    To terminate data retrieval from a streaming device

  1. Set the device’s notification routine to NULL.
  2. Release the reference to the callback object’s IVioEventSink interface.
  3. Release the reference to the device.

The following code example shows how to obtain a polled device interface and how to retrieve data from that device.

IVIO_Device          *pDevice;
VARIANT              vCoolantTemp;
LONG                     lCoolantTemp;

hr = CoCreateInstance(CLSID_VIO_COOLANT_TEMP, NULL,
                      CLSCTX_INPROC_SERVER, IID_VIODEVICE, 
                      (PVOID *) &pDevice);
VariantInit(&vCoolantTemp);
// Read the coolant temperature from the vehicle.
hr = pDevice->GetData(&vCoolantTemp, 2000);
// If you read the coolant temperature successfully, save it.
lCoolantTemp = V_I4(&vCoolantTemp);
// Free the resources of the VARIANT.
VariantClear(&vCoolantTemp);
// Release the reference to the device.
pDevice->Release();

If you need data from a device that provides streaming data, you must not only obtain an interface to the device, but also create a callback object. The following code example shows how to obtain the necessary interface and how to invoke the callback object.

IVIO_Device         *pDevice;
IVIO_EventSink      *pEventSink;

hr = CoCreateInstance(CLSID_VIO_VEHICLE_SPEED, NULL,
                      CLSCTX_INPROC_SERVER, IID_VIODEVICE,
                      (PVOID *) &pDevice);

CVioSpeedCallBack *pCallback = new CVioSpeedCallback;
pCallback->QueryInterface(IID_VIOEVENTSINK, (PVOID *) &pEventSink);
// Release the callback object.
pCallback->Release();
// Start the streaming vehicle speedometer device.
hr = pDevice->SetNotify(NULL, pEventSink, 0);

// Other code

// Before exiting the application, turn off the streaming device.
hr = pDevice->SetNotify(NULL, NULL, 0);
// Release the reference to the event sink object.
pEventSink->Release();
// Release the reference to the device.
pDevice->Release();

The following code example shows how to create a callback object.

class CVioSpeedCallBack : public IVIO_EventSink
{
public:
  CVioSpeedCallback();
  virtual ~CVioSpeedCallback();
// Standard IUnknown methods.
// IVIO_EventSink method.
  STDMETHOD (ReceiveMsg) (LPVARIANT pData, LPARAM lParam);
};
// Note: The callback function returns  on its own thread.
STDMETHODIMP CVioSpeedCallback::ReceiveMsg(LPVARIANT pData, LPARAM
                                           lParam)
  {
  USHORT usVehicleSpeed;
  // Get the speed from the VARIANT.
  usVehicleSpeed = V_UI2(pData);
  return S_OK;
  }