Connecting Phidgets With MSN Messenger
(back to: Back to Phidgets.Net)
What you will learn in this tutorial:
|
In this tutorial we will develop an application that uses several Phidget devices to control the Microsoft MSN messenger.
The following functions will be implemented in the application:
- Show the current status of the user with a green and red LED
- Use Phidget RFID tags to control the user status
- Show changes of the status of other users in the Phidget Text LCD

Getting started:
|
Tutorial:
A) Starting with Phidgets
- Start Visual Studio 2003 and create a new project (C# Windows Application, name: for example "MSNPhidgets")
- From the 'Phidget' Toolbar Tab drag the following objects to the form: RFID, InterfaceKit and TextLCD, and also drag the Skins to the form: RFIDSkin, InterfaceKitSkin and TextLCDSkin
- Change the phidget property of the skins: The 'RFID' property to 'rfid1', the 'InterfaceKit' property to 'interfacekit1' and the 'TextLCD' property ro 'textlcd1'
- Run the application and test the components
- If the RFID reader is not activated by default, add an event handler to the 'Attach' event and add the following code to the callback method:
{
this.rfid1.Outputs[3].State = true;
}
B) Connecting to the MSN Messenger: Display changes with Text LCD and LED
- At first, we add a reference to the MSN Messenger API: Click on the Reference listing on the "Solution Explorer" window (usually on the right side of the screen), choose "Add reference...", click on the "COM" tab and search for the entry "Messenger API Type Library". Double-click on the entry and confirm the dialog window.
- Add this to the beginning of the code
using MessengerAPI;
- Add a private member of the type Messenger to the class:
- In the constructor of the form, create a new instance of the Messenger() and add the following event listener and the callback methods of the class (Remember that you can use the Tab key two times, to generate the callback method automatically)
- Now we want to display the status of the users (if it changes) on the Text LC display. Add the following code to the first callback method we have created:
{
MessengerAPI.IMessengerContact contact = (IMessengerContact)pMContact;
//
// If Phidget TextLCD is attached, change the message of the display.
//
if(this.textLCD1.Attached)
{
this.textLCD1.Display = contact.FriendlyName + ": " + mStatus;
}
}
- And when the personal status changes, we want to visualize that with the LEDs: green for online and red for every other status:
{
//
// If the status is ONLINE, then activate the green LED,
// otherwise activate the red LED.
//
if(mMyStatus == MessengerAPI.MISTATUS.MISTATUS_ONLINE)
{
this.interfaceKit1.Outputs[0].State = true;
this.interfaceKit1.Outputs[1].State = false;
}
else
{
this.interfaceKit1.Outputs[0].State = false;
this.interfaceKit1.Outputs[1].State = true;
}
}
- Because we want to initialize the green and red LED when we start the application, we add a event listener to the 'Attach' event of the interfacekit1 (just click to the event in the properties and Visual Studio creates a callback method. Add the following code to the method:
{
if(this.msn.MyStatus == MessengerAPI.MISTATUS.MISTATUS_ONLINE)
{
this.interfaceKit1.Outputs[0].State = true;
this.interfaceKit1.Outputs[1].State = false;
}
else
{
this.interfaceKit1.Outputs[0].State = false;
this.interfaceKit1.Outputs[1].State = true;
}
}
- We also initialize the Text LC display, so add also an event handler to this phidget and add the following code:
{
this.textLCD1.Backlight = true;
this.textLCD1.CursorBlink = false;
this.textLCD1.Display = "MSN Phidget";
}
- We can now test this application to display the changes of the online states
C) Change the displayed messages
- As you may have seen on the Text LC display, the messages about the status changes of the user display some ugly string messages; we change these messages by using a hashtable to translate these strings
- Add this new hashtable member to the class:
- Create a method initOnlineStatesHashtable to the class, and there add the following code to initialize our hashtable:
{
this.onlineStates.Add(MISTATUS.MISTATUS_AWAY, "Away");
this.onlineStates.Add(MISTATUS.MISTATUS_BE_RIGHT_BACK, "Be right back");
this.onlineStates.Add(MISTATUS.MISTATUS_BUSY, "Busy");
this.onlineStates.Add(MISTATUS.MISTATUS_IDLE, "Idle");
this.onlineStates.Add(MISTATUS.MISTATUS_OFFLINE, "Offline");
this.onlineStates.Add(MISTATUS.MISTATUS_ON_THE_PHONE, "On the phone");
this.onlineStates.Add(MISTATUS.MISTATUS_ONLINE, "Online");
this.onlineStates.Add(MISTATUS.MISTATUS_OUT_TO_LUNCH, "Out to lunch");
}
- In the constructor of the form, call this method to initialize the hashtable on startup
- We add now a lookup method, to translate the internal string messages to the displayed text
{
if(this.onlineStates.ContainsKey(mMyStatus))
{
return (string)this.onlineStates[mMyStatus];
}
else
{
return "Unknown";
}
}
- Finally we change the display command in the method msn_OnContactStatusChange that we have created before;
{
this.textLCD1.Display = contact.FriendlyName + ": "
+ this.getStatusText(mStatus);
}
- Now you can test the application with the changed display messages.
D) Using RFID tags to control MSN Messenger
- Now we use the tags of the RFID reader to control our online status in the Microsoft Messenger.
- Add an event listener to the TAG event of the rfid1 object, and add the following code to the callback method:
{
if(e.Tag == "YourTag1")
{
if(!(this.msn.MyStatus == MessengerAPI.MISTATUS.MISTATUS_ONLINE))
{
this.msn.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE;
}
}
else if (e.Tag == "YourTag2")
{
if(!(this.msn.MyStatus == MessengerAPI.MISTATUS.MISTATUS_AWAY))
{
this.msn.MyStatus = MessengerAPI.MISTATUS.MISTATUS_AWAY;
}
}
}
- Note: please replace the statement YourTag1 and YourTag2 with the tag ID numbers of the RFID tags you use.
- In this method, we first check the RFID tag (with e.Tag) and then we check if we have to change the user state of the user (this prevents to much change events that we send to the Messenger, because a lot of similar RFID events are detected if you place a tag on the RFID reader)
- As feedback that the RFID reader is activated, we add another method to the 'Attach' event listener for the RFID reader, and activate the digital LED output in the callback method:
{
this.rfid1.Outputs[3].State = true;
this.rfid1.Outputs[1].State = true;
}
- We also want to deactivate this LED when we end our application, so we create an event handler to the Closing event of the form and add the following code:
{
this.rfid1.Outputs[3].State = false;
this.rfid1.Outputs[1].State = false;
}
- THAT'S ALL. You have finished your MSNPhidget tutorial, and successfully developed an application that uses Phidgets to interact with the MSN Messenger.
Downloads (General):
|
Links:
|