Adding Plug and Play Support (POS for .NET v1.12 SDK Documentation)

2/27/2008

POS for .NET includes support for Plug and Play devices. By adding Plug and Play support to your Service Objects, applications can become more simple, reliable, and efficient. Service Objects should support it whenever possible.

Implementing Plug and Play support at the Service Object level is very simple. Once you know the hardware ID of your device, simply add a single attribute to your class, HardwareIdAttribute. The HardwareId attribute is used by PosExplorer to intelligently filter out Service Objects from the list of available devices depending on the state of the device. If the Service Object has a HardwareId attribute that refers to an installed Plug and Play device, but that device is not connected, the Service Object will be excluded from the PosExplorer device list. This list is returned when applications call GetDevices.

Service Objects may also have more than one HardwareId attribute, in which case PosExplorer associates a union of all specified devices with the Service Object. It is possible to override the HardwareId attributes or add to the list of associated hardware on the Service Object without rebuilding the Service Object assembly. For information about overriding or adding the HardwareId attribute, see Plug and Play XML Configuration.

Only the application is responsible for catching DeviceAddedEvent and DeviceRemovedEvent events and updating its status as appropriate based on the updated device list returned from PosExplorer. The Service Object does not need to detect these events.

To add a HardwareId attribute to your Service Object class

  1. Determine the range of hardware IDs for the device or devices that your Service Object supports.

  2. Add a HardwareId attribute before your class definition using the lowest hardware ID used by your device and the highest. Multiple HardwareId attributes may be used to identify multiple ranges of hardware IDs.

Example

The following sample adds a HardwareId attribute to the basic template shown in the previous section.

using System; 

using Microsoft.PointOfService;
using Microsoft.PointOfService.BaseServiceObjects;

namespace SOTemplate
{

    [HardwareId("HID\\Vid_05e0&Pid_038a",
                "HID\\Vid_05e0&Pid_038a")]

    [ServiceObject(
                DeviceType.Msr,
                "ServiceObjectTemplate",
                "Bare bones Service Object class",
                1,
                9)]
    public class MyServiceObject : MsrBase
    {
        public MyServiceObject()
        {
        }
    }
}

See Also

Tasks

Creating a Basic Service Object Code Template
Creating a Service Object Sample

Concepts

Attributes for Identifying Service Objects and Assigning Hardware
Plug and Play XML Configuration

Other Resources

Service Object Samples: Getting Started
POS for .NET Service Object Architecture