Hi both
Using the ClassOfDevice value is not as simple as comparing it for equality against a single enum member. The Flags Attribute on the enum should be a hint that that's the case. :-)
One really also needs to have read the Bluetooth documentation on this value, its quite involved, see the "Assigned Numbers" link in the help page. In summary the value contains four separate parts: Service classes, Major Device class, Minor Device class and a fixed Format Type. So one will nearly always need to use a set of bit masks to pick out the required piece. I suggest something like:
MaskServiceClasses = 0xffe000,
MaskMajorDeviceClass = 0x001f00,
MaskMinorDeviceClass = 0x0000fc,
MaskDeviceClass = MaskMajorDeviceClass | MaskMinorDeviceClass,
MaskFormatType = 0x000003,
and for completeness
FormatType1=0x0, //last two bits (00), for "format #1"; the one described in this enum
Note then, that: the Service Classes field is a bit mask; Major Device Class is a numerical value; the format of Minor Device class is different for each Major Device class, and can be a numerical or a flags value, or even have a number of sub fields. For instance the Peripherals minor device class has two part a Keyboard / Pointing Device pair of flags and a "sub-field" numerical value, again further masking is probably necessary there.
Anyway, if wanting to check the value of the Major Device class, one could do something like the following (untested) code.
class Abcdef
{
const ClassOfDevice MaskMajorDeviceClass = (ClassOfDevice)0x001f00;
... MyMethod(...)
{
//mask out the middle five bits
switch(value & MaskMajorDeviceClass)
{
//use the enum members that have their last byte blank
case ClassOfDevice.Computer: //0x100
...
case ClassOfDevice.Phone: //0x200
case ClassOfDevice.AccessPointAvailable: //0x300
}//switch
As you probably guessed converting the enum value to a string (with ToString) and then grep-ing bits of the string from it is not nice. :-,(
Or to check whether a device advertises a particular service use, for example:
if(0 != (value & ClassOfDevice.ObexService))
Alan
Alan J. McFarlane
http://www.alanjmcf.me.uk/
Please follow-up in the newsgroup for the benefit of all.
Have I helped? Consider visiting my Amazon wishlist, see my homepage.