Sunday, August 16, 2009

Creating Xml Configuration Files For Pos .Net Plug and Play Support

This post is about how to create an xml file that enables Plug and Play for Pos .Net devices that don’t natively support it. For details on the Plug and Play system see my previous post.

I’m not going to cover the actual format of the xml file you need to create as it’s well documented in the SDK help.

What I will help with is how to locate the values you need to embed in the file.

Locating Hardware Ids

There are two ways to locate hardware ids for plug and play devices, either using Device Manager or Pos .Net logging (which is often easier).

Using Device Manager

The first is using Device Manager in Windows to locate the values. The easiest way to open Device Manager is to right click My Computer and choose Manage.


Then in the management console that appears, click on Device Manager.


Now for the hard part… you need to locate your device in the tree on the right. Often devices will appear either under Human Interface Devices or Universal Serial Bus Controllers. It sometimes helps to expand these nodes and then disconnect and reconnect the device to see if you can spot the entry being added.

If not, right click on each one and choose properties to see if the device has any values that identify it as the one you want.


Once you’ve found the device you’re interested in open it’s property window and go to the details tab. In the Property drop down list select Hardware Ids.


These are the values you need for your from and to hardware id attributes. See the Tricks and Traps section of this post for common gotcha’s.

Using Pos .Net Logging

This is sometimes easier than using device manager because you don’t have to hunt for the right device in a list.

First, you must enable Pos .Net Logging.

Once you’ve enabled it you need to run a program that will create an instance of the PosExplorer class. You can write your own, use one of the SDK samples, use your real application or a third party utility.

Once you have a suitable application running, connect your device. Wait a few seconds, then open the log file with notepad or another text file editor. The log file will be created in your windows temporary file folder (specified by the %TEMP% environment variable), unless you have changed the location. Again, unless you’ve changed the default settings, the log file will be called PosFor.Net(today's date and time).txt.

Go to the end of the file and then search or scroll upwards looking for the text

Searching for SO's with the following hardware id's:

The two lines immediately following this will contain the hardware id’s for the device you just connected. Here’s a portion of a sample log file;

[7/22/2009 3:28:53 PM     10  INFO     PhysicalDeviceInfo.WndProc]  Received DBT_DEVICEARRIVAL message
[7/22/2009 3:28:53 PM     10  INFO     PhysicalDeviceInfo.WndProc]  DevicePath is: \\?\USB#VID_04B8&PID_0202#J5UF019152#{5DD901C0-BCF4-11D1-9738-008029E6A5B3}
[7/22/2009 3:28:53 PM     14  INFO     PhysicalDeviceInfo.ProcessPnPEvent]  Starting processing PnP events.
[7/22/2009 3:28:53 PM     14  INFO     PhysicalDeviceInfo.ProcessPnPEvent]  Dequeued PnP Event - updating device list.  Total devices: 74
[7/22/2009 3:28:53 PM     14  INFO     PhysicalDevice]  Created PhysicalDevice for DevicePath: \\?\USB#VID_04B8&PID_0202#J5UF019152#{5DD901C0-BCF4-11D1-9738-008029E6A5B3}
[7/22/2009 3:28:53 PM     14  INFO     PhysicalDeviceInfo.ProcessPnPEvent]  Added new device to device list: USB\VID_04B8&PID_0202\J5UF019152(\\?\USB#VID_04B8&PID_0202#J5UF019152#{5DD901C0-BCF4-11D1-9738-008029E6A5B3})
[7/22/2009 3:28:53 PM     14  INFO     PhysicalDeviceInfo.ProcessPnPEvent]  Finished updating device list.  Total devices: 75
[7/22/2009 3:28:53 PM     14  INFO     PhysicalDeviceInfo.ProcessPnPEvent]  Firing DeviceAdded event
[7/22/2009 3:28:53 PM     14  INFO     Explorer]  Entering OnDeviceAddedEventHandler()
[7/22/2009 3:28:53 PM     14  INFO     Explorer]  Entering GetDevicesByHardwareIds(). Searching for SO's with the following hardware id's:
[7/22/2009 3:28:53 PM     14  INFO     Explorer]     Id: USB\VID_04B8&PID_0202&REV_0100
[7/22/2009 3:28:53 PM     14  INFO     Explorer]     Id: USB\VID_04B8&PID_0202
[7/22/2009 3:28:53 PM     14  INFO     Explorer]  Found a match: TM-T88IV Type: PosPrinter From: USB\VID_04B8&PID_0202&REV_0100 To: USB\VID_04B8&PID_0202&REV_0999
[7/22/2009 3:28:53 PM     14  INFO     Explorer]  Leaving GetDevicesByHardwareIds()
[7/22/2009 3:28:53 PM     14  INFO     Explorer]  1 matching service objects found.
[7/22/2009 3:28:53 PM     14  INFO     Explorer]  Firing a DeviceAddedEvent for service object name=TM-T88IV, type=PosPrinter

Locating Service Object Names

Hopefully you can locate your service object names in the documentation or readme files provided with your service objects.

Failing that you can use the Service Object Manager published by Sean Liming or you can write your own code.

To use the Service Object Manager, download it and run it, then click the Get Service Objects button which will load the list of installed service objects in the displayed list box.


To write your own code, you just need to create an instance of PosExplorer, call GetDevices() and then enumerate the returned collection looking at the ServiceObjectName property of each item;

PosExplorer posExplorer = new PosExplorer();
DeviceCollection devices = posExplorer.GetDevices();
foreach (DeviceInfo deviceInfo in devices)

Tricks and Traps

Common traps to avoid are;

When putting any value into the xml file that contains an & (commonly used in hardware id values) or other character that is illegal in xml, ensure you encode it properly. For example, & becomes &

When putting in your from and to hardware id’s, ensure you get the them the correct way around, that is the ‘fromid’ needs to be ‘less than’ the ‘toid’ as far as the computer is concerned. Device manager often shows them in reverse order. A good rule of thumb is the longer hardware id should be the ‘to’ id.

Installing and Using Your Xml File

To install a file, once you have one, you need to place it in the Pos .Net Control Configurations directory, which is usually;

C:\Program Files\Common Files\microsoft shared\Point Of Service\Control Configurations

But the only way to get the exact file location is to read the registry key;


Your configuration file will be read each time the PosExplorer class is instantiated, so if you edit or replace it with a newer one, you will need restart your application or at least cause it to re-create the PosExplorer object before the new content will be used.

Technorati Tags: ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Windows Live Tags: Configuration,Files,Plug,Play,Support,devices,system,Hardware,Device,Manager,Manage,management,tree,Often,Human,Interface,Universal,Serial,Tricks,instance,PosExplorer,Wait,notepad,text,folder,TEMP,environment,location,portion,INFO,PhysicalDeviceInfo,WndProc,DBT_DEVICEARRIVAL,message,DevicePath,ProcessPnPEvent,events,Event,PhysicalDevice,Explorer,OnDeviceAddedEventHandler,GetDevicesByHardwareIds,Found,Type,PosPrinter,From,objects,DeviceAddedEvent,Service,Object,documentation,Sean,code,GetDevices,collection,ServiceObjectName,DeviceCollection,DeviceInfo,Console,WriteLine,ReadLine,Common,example,needs,File,Control,Configurations,directory,Program,Point,HKEY_LOCAL_MACHINE,SOFTWARE,ControlConfigs,Controllers,easier

WordPress Tags: Configuration,Files,Plug,Play,Support,devices,system,Hardware,Device,Manager,Manage,management,tree,Often,Human,Interface,Universal,Serial,Tricks,instance,PosExplorer,Wait,notepad,text,folder,TEMP,environment,location,portion,INFO,PhysicalDeviceInfo,WndProc,DBT_DEVICEARRIVAL,message,DevicePath,ProcessPnPEvent,events,Event,PhysicalDevice,Explorer,OnDeviceAddedEventHandler,GetDevicesByHardwareIds,Found,Type,PosPrinter,From,objects,DeviceAddedEvent,Service,Object,documentation,Sean,code,GetDevices,collection,ServiceObjectName,DeviceCollection,DeviceInfo,Console,WriteLine,ReadLine,Common,example,needs,File,Control,Configurations,directory,Program,Point,HKEY_LOCAL_MACHINE,SOFTWARE,ControlConfigs,Controllers,easier

Blogger Labels: Configuration,Files,Plug,Play,Support,devices,system,Hardware,Device,Manager,Manage,management,tree,Often,Human,Interface,Universal,Serial,Tricks,instance,PosExplorer,Wait,notepad,text,folder,TEMP,environment,location,portion,INFO,PhysicalDeviceInfo,WndProc,DBT_DEVICEARRIVAL,message,DevicePath,ProcessPnPEvent,events,Event,PhysicalDevice,Explorer,OnDeviceAddedEventHandler,GetDevicesByHardwareIds,Found,Type,PosPrinter,From,objects,DeviceAddedEvent,Service,Object,documentation,Sean,code,GetDevices,collection,ServiceObjectName,DeviceCollection,DeviceInfo,Console,WriteLine,ReadLine,Common,example,needs,File,Control,Configurations,directory,Program,Point,HKEY_LOCAL_MACHINE,SOFTWARE,ControlConfigs,Controllers,easier

1 comment:

  1. There is also a method to PosExplorer, Refresh(), that will make it re-load the configuration.