Bootstrapping Your Development Environment:

Here are some things I assume you are developing with:

  • Microsoft Visual Studio 2015
  • C#

Here is the shopping list you will need:

 

Launch Microsoft Visual Studio

Create a .NET 4.6 C# Console Application project - In this example I created a project called TweetMe

After the project has been created rename the default Program.cs to TweetMe.cs

 

Adding The Plantronics and TweetSharp Dependencies

 

Getting TweetSharp

NuGet can be found under the Project menu in Visual Studio. To add TweetSharp to your project, click on the Project menu and select the "NuGet Package Manager" option and go to "Manage NuGet Packages for Sol.  Once the NuGet dialog box shows up search for the TweetSharp libraries and add them to your project by installing it.

Add the Plantronics SDK References

You will need to add the Interop.Plantronics reference to the solution.



Once you have the TweetSharp and Plantronics assemblies referenced, your project's reference list should look like this:

 

Step 1: Initialize Twitter.

The IPlugin interface has three methods that must be implemented Name, Init and Exit, below is a skeleton of what an empty plug-in implementation looks like.

using System;
using System.Runtime.InteropServices;
using TweetSharp;
using Interop.Plantronics;
 
namespace TweetMe
{
    public class TweetMe
    {
        //Twitter integration stuff
        //NOTE: you must get your own keys/tokens in order to make this tweet to your _twitter account!
        //To do this simply register at the following site: https://dev.twitter.com/apps/new
        static String twitterConsumerKey = "yourConsumerKey";
        static String twitterConsumerSecret = "yourConsumerSecret";
        static String twitterAccessToken = "yourAccessToken";
        static String twitterAccessTokenSecret = "yourAccessTokenSecret";
        static String twitterUserHandle = "yourUserHandle";
 
        static TwitterService _twitter;
        
        InitializeTwitter();
    }
 
    //_twitter initialization
    private static void InitializeTwitter()
    {
        //initialize _twitter
        _twitter = new TwitterService(twitterConsumerKey, twitterConsumerSecret);
        _twitter.AuthenticateWith(twitterAccessToken, twitterAccessTokenSecret);
    }
}

Step 2. Add Plantronics Objects

Start to adding the Plantronics objects we will be using to gain access to the headset events.
....
 
namespace TweetMe
{
    public class TweetMe
    {
        private static COMDevice _device;
        static ICOMDeviceListenerEvents_Event _devListener;
        private static ICOMHostCommandExt _command;
 
        //Twitter integration stuff
        //NOTE: you must get your own keys/tokens in order to make this tweet to your _twitter account!
        //To do this simply register at the following site: https://dev.twitter.com/apps/new
        static String twitterConsumerKey = "yourConsumerKey";
        static String twitterConsumerSecret = "yourConsumerSecret";
        static String twitterAccessToken = "yourAccessToken";
        static String twitterAccessTokenSecret = "yourAccessTokenSecret";
        static String twitterUserHandle = "yourUserHandle";
 
        static TwitterService _twitter;
        
        //Get a valid _device
        COMSessionManager mgr = new COMSessionManager();
        COMSession sess;
        mgr.Register("My Session", out sess);
        _device = sess.GetActiveDevice();
 
        //Cast HostCommand and init _command.
        _command = _device.HostCommand as ICOMHostCommandExt;
 
        //Cast HostCommand and DeviceListener and init _command and _devListener.
        _command = _device.HostCommand as ICOMHostCommandExt;
        _devListener = _device.DeviceListener;
 
        _devListener.onHeadsetStateChanged += devListener_HeadsetStateChanged;
 
        InitializeTwitter();
    }
 
    private static void devListener_HeadsetStateChanged(COMDeviceListenerEventArgs args)
    {
        
    }
...

Step 3: Request Proximity

To receive proximity data, you will need to call _command.RequestProximity() after you start listening for headset events.
....
 
namespace TweetMe
{
    public class TweetMe
    {
        private static COMDevice _device;
        static ICOMDeviceListenerEvents_Event _devListener;
        private static ICOMHostCommandExt _command;
 
        //Twitter integration stuff
        //NOTE: you must get your own keys/tokens in order to make this tweet to your _twitter account!
        //To do this simply register at the following site: https://dev.twitter.com/apps/new
        static String twitterConsumerKey = "yourConsumerKey";
        static String twitterConsumerSecret = "yourConsumerSecret";
        static String twitterAccessToken = "yourAccessToken";
        static String twitterAccessTokenSecret = "yourAccessTokenSecret";
        static String twitterUserHandle = "yourUserHandle";
 
        static TwitterService _twitter;
        
        //Get a valid _device
        COMSessionManager mgr = new COMSessionManager();
        COMSession sess;
        mgr.Register("My Session", out sess);
        _device = sess.GetActiveDevice();
 
        //Cast HostCommand and init _command.
        _command = _device.HostCommand as ICOMHostCommandExt;
 
        //Cast HostCommand and DeviceListener and init _command and _devListener.
        _command = _device.HostCommand as ICOMHostCommandExt;
        _devListener = _device.DeviceListener;
 
        _devListener.onHeadsetStateChanged += devListener_HeadsetStateChanged;
 
        InitializeTwitter();
 
        RequestProximity();
    }
  
    private static void RequestProximity()
    {
        try
        {
           if (_command != null)
               _command.RequestProximity();
        }
        catch (COMException ex)
        {
           Console.WriteLine(ex.Message + "\r\nPlease use a _device that supports proximity.");
        }
    }
}

Step 4: Tweet!

Now add the code to tweet your headset events!
  • HeadsetState.Don - Capacitive sensor event that the user is wearing their headset
  • HeadsetState.Doff - Capacitive sensor event the user has take off their headset
  • Proximity.Near - event that the headset is near the host system
  • Proximity.Far - event that the headset is far from the host system (but still in range)
  private static void devListener_HeadsetStateChanged(COMDeviceListenerEventArgs args)
  {
        switch (args.HeadsetStateChange)
        {
             case (DeviceHeadsetStateChange.HeadsetStateChange_Don):
                SendTweet("At " + DateTime.Now.ToString("H:mm:ss") + " my Plantronics headset sensors told me that " + twitterUserHandle + " is wearing me!");
                break;
             case (DeviceHeadsetStateChange.HeadsetStateChange_Doff):
                SendTweet("At " + DateTime.Now.ToString("H:mm:ss") + " my Plantronics headset sensors told me that " + twitterUserHandle + " has taken me off.");
                break;
             case (DeviceHeadsetStateChange.HeadsetStateChange_Far):
                SendTweet("At " + DateTime.Now.ToString("H:mm:ss") + " my Plantronics headset sensors told me that " + twitterUserHandle + " is away from their desk.");
                break;
             case (DeviceHeadsetStateChange.HeadsetStateChange_Near):
                SendTweet("At " + DateTime.Now.ToString("H:mm:ss") + " my Plantronics headset sensors told me that " + twitterUserHandle + " is at their desk.");
                break;
             default:
                SendTweet("At " + DateTime.Now.ToString("H:mm:ss") + " the following Plantronics headset event " + args.HeadsetStateChange + " occured for " + twitterUserHandle);
                break;
        }
  }
 
  //_twitter send tweet and display status
  private static void SendTweet(string text)
  {
       SendTweetOptions options = new SendTweetOptions {Status = text};
       TwitterStatus status = _twitter.SendTweet(options);
       if (status == null)
       {
           Console.WriteLine("Tweet failed, no status returned. (have you added key/token/user etc at top of code?)");
       }
       else
       {
           Console.WriteLine("Created a new tweet, id = " + status.Id);
       }
   }

The Source Code:

Well there you go... I hope this works for you, if you encounter any problems let me know!
Download link: TweetMe.zip

Cheers,
-Cary
 
News Articles Classification: 

Comments


Very cool - I like it. But it really should follow "fluffyflush" and Jari's toaster on twitter.


, the PDC memeber was looking for a Hello World based on the emulator. I pointed him to this blog post, but perhaps there is something we can create that is more specific to people getting up and running using the emulator?  Thanks!


HI,

I got problem on running the code that u posted. Actually I got problems running the sample code which Plantronics provided as well. Coz the sample doesn't have main program in C#, how they can run??? Also, even I create a main program and then go to the init(), then when I do the second step... Trying to get the session manager instance, yet it shows the following error: Failed to load Avaya one-X Communicator Plugin from Plantronics.UC.Avaya.dll. Assembly C:Documents and SettingsjacquelineHDesktop28thAugWindowsFormsApplication1WindowsFormsApplication1inDebugPlantronics.UC.Avaya.dll not found

Can any one help me to fit this problem?? Many THX... Cheers


Hello,

This sample code doesn't have a "main" method as an entry point because this code runs as a Spokes plugin.

Writing your own main method and trying to run the code as a stand-alone application can cause all kinds of particularly nasty things to occur. However, the biggest issue is that the majority of the code won't be able to communicate with the spokes service.

The above article covers in great detail all the steps from setting up your development environment, to writing and finally running the plugin. If you follow all the steps above exactly I think you should be able to see your voyager pro tweeting in no time

Concerning the missing assembly error you're seeing, is it possible that you have Plantronics.UC.Avaya.dll added to the references in your project? If so, it's not necessary to add that assembly to the references.

I hope this helps answer your questions.

-Brandon Haston


If you are creating a standalone app you have possibility to connect to Spokes runtime via a different Spokes API.

This sample uses Spokes iPlugin API, where the project needs to create a DLL that is loaded into Spokes runtime.

Other samples in DevZone Sample Repository use Spokes COM Service API. This allows standalone C++ applications to integrate to Spokes runtime. Since recent launch of Spokes 2.7 SDK it now allows standalone C# applications to integrate to Spokes runtime, as long as those C# applications target .NET Framework 4.0.