Simple Example The Interfacekit And Sensors

<< Back to the SharedPhidgets 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 this example.


The Phidget Interfacekit
The Phidget InterfaceKit
  1. Create a new Windows C# application in VisualStudio.NET
  2. Use the ConnectionManager for connecting to the server
  3. Create a InterfaceKit object
  4. Create a InterfaceKit skin and connect it to the InterfaceKit object
  5. Create event handlers for inputs and sensors and buttons to control the outputs
  6. Finished! Compile the application.

Step-by-step in detail

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

2) Now we click on the SharedPhidgets toolbox on the left side of the VisualStudio window, select the ConnectionManager object and click on your Windows form.

Then change the SharedDictionaryURL property of the Connection Manager to the address of the server:

3) Drag a SharedPhidgets InterfaceKit component on your form, on the FilterSerialNumber property in the Properties explorer of Visual Studio...

...and specify the serial number of the InterfaceKit. If you have only one InterfaceKit connected to your infrastructure (that means: only one InterfaceKit connected to one of the SharedPhidgets Connectors that are connected with the server), you don't need to add the serial number because the component will then connect to the only component of its type it founds.

4) Create a skin object for the InterfaceKit (InterfaceKitSkin object): Just click on the entry in the toolbox and click-and-hold to create the control on your Windows form.

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

5) Create a new TextBox object on your form, and select the Multiline property to true and the ScrollBars property to Vertical. Furthermore, set the value of the Text property to an empty string.

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 display the input and its state in the textbox.

private void interfaceKit1_InputChange(object sender, GroupLab.SharedPhidgets.BitStateChangeEventArgs e)
  this.textBox1.Text =
    "Status of input " + e.Index + ": " + e.State +
    System.Environment.NewLine +

And insert the following code line in the callback method for the SensorChange: it will display the sensor and its current value in the textbox.

private void interfaceKit1_SensorChange(object sender, GroupLab.SharedPhidgets.IndexSensorChangeEventArgs e)
  this.textBox1.Text =
    "Value of sensor " + e.Index + ": " + e.Value +
    System.Environment.NewLine +

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 your application:

The following window will appear, where you can see the Skin for the InterfaceKit, the textbox with the events in a list and the three buttons to toggle the state of the three first 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.