Greetings!

The Plantronics SDK feature for receiving proximity events when headset is Near or Far from PC can still be used with the new line of products based on BT600 dongle (Voyager Focus UC, Voyager 5200 UC).

**Full sample code for this article located here**: /system/files/FocusProximityExample.zip
(You must be logged in to download the file).

You can register for Proximity with these devices using the latest SDK version 3.8.51454.38364, located here: http://developer.plantronics.com/windows

You need to register for DeviceListener HeadsetStateChanged events, like this:
 
m_deviceListenerEvents.onHeadsetStateChanged += m_deviceListenerEvents_onHeadsetStateChanged;

Then you register to receive proximity:
 
m_hostCommandExt.EnableProximity(true); // enable proximity reporting for device
m_hostCommandExt.RequestProximity();    // request to receive asyncrounous near/far proximity event to HeadsetStateChanged event handler.

When you handle the HeadsetStateChanged events you can see if you are near or far:
(Note, there are a couple of edge cases for the older legacy wireless products where you need to re-register for proximity on InRange and ProximityDisabled, these do not apply to BT600).
        private static void m_deviceListenerEvents_onHeadsetStateChanged(COMDeviceListenerEventArgs args)
        {
            switch (args.HeadsetStateChange)
            {
                case DeviceHeadsetStateChange.HeadsetStateChange_Near:
                    Console.WriteLine(">>Headset NEAR (via deviceListener event)");
                    break;
                case DeviceHeadsetStateChange.HeadsetStateChange_Far:
                    Console.WriteLine(">>Headset FAR (via deviceListener event)");
                    // this is NOT working. for now use workaround in m_deviceComEvents_onDataReceived below.
                    break;
                case DeviceHeadsetStateChange.HeadsetStateChange_ProximityDisabled:
                    // Immediately re-enable proximity
                    RegisterForProximity(true);
                    break;
                case DeviceHeadsetStateChange.HeadsetStateChange_InRange:
                    // Immediately re-enable proximity
                    RegisterForProximity(true);
                    break;
            }
        }
Finally, there is a known issue with the current SDK version that we need to workaround to get the "Far" event. (the "Far" event is not currently reported via DeviceListener, expected to be implemented in later SDK release 3.9).

For the workaround register to receive "raw" headset data events:
 
            m_deviceComEvents = m_activeDevice as ICOMDeviceEvents_Event;
            m_deviceComEvents.onDataReceived += m_deviceComEvents_onDataReceived;

Then when you receive raw data event, use the code below to work out when the device is "Far":
 
        private static string byteArrayToString(byte[] p)
        {
            StringBuilder b = new StringBuilder();
            foreach (byte x in p)
                b.Append(x.ToString("X2"));
            return b.ToString();
        }

        private static void m_deviceComEvents_onDataReceived(ref object report)
        {
            byte[] reportbuf = (byte[])report;
            string datareporthex = byteArrayToString(reportbuf);

            // use raw device data to implement proximity Far event
            string command = datareporthex.Substring(18, 4);
            switch (command)
            {
                case "0806":
                    string nearfar = datareporthex.Substring(26, 2);
                    if (nearfar == "00")    // this workaround is required with 3.8 for now as Far is not done in Spokes SDK (will be in 3.9)
                    {
                        Console.WriteLine(">>Headset FAR (via raw device data event)");
                    }
                    break;
            }
        }

Here is a picture of the code in action:


That's it! Have fun with proximity laugh
Lewis.

**Full sample code for this article located here**: /system/files/FocusProximityExample.zip
News Articles Classification: