Shared Phidgets Simple Example The Interfacekit And Sensors

<< Back to the SharedPhidgets 3 page

What you will learn in this tutorial:

  • how to create a SharedPhidgets InterfaceKit object,
  • how to assign a specific serial number to this InterfaceKit,
  • how to use the InterfaceKit skin and
  • how to control outputs, register for inputs and retrieve sensor values.

Download source:
The zip file contains the program code of all the Shared Phidgets programming examples. The source code of this example can be found in the 'InterfaceKitExample' project.


The Phidget Interfacekit
The Phidget InterfaceKit
  1. Create a new Shared Phidgets appliance with the template in VisualStudio.NET
  2. Create a InterfaceKit object
  3. Create a InterfaceKit skin and connect it to the InterfaceKit object
  4. Create event handlers for inputs and sensors and buttons to control the outputs
  5. Finished! Compile the application.

Step-by-step Instructions

Preparation: Install the Shared Phidgets toolkit on all client machines, run the Connector software, and attach at least one Phidgets InterfaceKit to one of the client computers.

1) Open VisualStudio.NET 2005, click New Project, select a new C# Windows application, enter a name for the project, and confirm the dialog.

2) Doubleclick the 'ApplianceForm.cs' file in the project explorer on the right side of the screen:

The windows form for the appliance control will now be opened:

It is possible to change the appliance name, as well as the default address for the connection to the shared dictionary by changing properties of the main form:

3) Drag a SharedPhidgets InterfaceKit component on your form,

It is possible to change the serial number of the interface kit. If you have only one interface kit connected to your infrastructure, you don't need to add the serial number because the component will then connect to the only hardware device of this type that it will find.

4) Create a skin object for the interface kit:

Change the InterfaceKit property of the InterfaceKitSkin to the object of the created interfacekit, here this is interfacekit1:

Add a sensor skin to the form, and set the 'InterfaceKit' property of this object as well. Furthermore, set the 'Sensor' property to 0.

5) Create 3 new buttons on your form, and change their Text property to "Output 1", "Output 2" and "Output 3".
Your form should now look like this:

Create a new eventhandler for the InputChange and SensorChange events of the Interfacekit object (interfacekit1):
just select the events in the list of events and press Enter (or Doubleclick there), and a new callback method will be created:

Now, just insert the following code line in the callback method for the InputChange: it will write the input and its status to the console.

private void interfaceKit1_InputChange(object sender, GroupLab.SharedPhidgets.BitStateChangeEventArgs e)
  System.Console.WriteLine("Status of input " + e.Index + ": " + e.State);

And insert the following code line in the callback method for the SensorChange: it will show the current sensor value in the system console.

private void interfaceKit1_SensorChange(object sender, GroupLab.SharedPhidgets.IndexSensorChangeEventArgs e)
  System.Console.WriteLine("Value of sensor " + e.Index + ": " + e.Value)

Then add callback handlers to the Click event for each of the buttons on your form. Simply doubleclick the buttons on your form, and VisualStudio.NET will create the event handlers.

Finally, add the following code lines to the eventhandler you created before:

private void button1_Click(object sender, System.EventArgs e)
  this.interfaceKit1.Outputs[0].State = !this.interfaceKit1.Outputs[0].State;

private void button2_Click(object sender, System.EventArgs e)
  this.interfaceKit1.Outputs[1].State = !this.interfaceKit1.Outputs[1].State;

private void button3_Click(object sender, System.EventArgs e)
  this.interfaceKit1.Outputs[2].State = !this.interfaceKit1.Outputs[2].State;

6) Compile the application:

The following window will appear, where you can see the Skin for the InterfaceKit, the sensor skin with the graph plot of the first analog sensor's values, and the three buttons to toggle the state of the three outputs.

That's it,

you can now modify this application and enhance the functionality. You can connect a variety of different sensors to the sensor inputs, connect buttons to the binary inputs and LEDs to the outputs.