Requirements

The requirements for using this set of classes are the following:
  • Visual Studio 2008
  • A set of plugwise Plugs and the USB stick
  • Source software has to be installed and configured.

Installation

The installation of the plugwise library is reasonably simple. The first step is to check out the latest version in SVN. I recommend using Tortoise SVN as a client. After you;ve done that you are almost ready to go. Open the project in Visual Studio 2008 and Build/Release. This leaves a DLL in the Bin directory of the project.

Be aware
This library is a not even beta so errors can happen.

Hello Plugwise

This is the first step in creating your own application with the library. Please follow the steps below carefully:
  • Create a new project in Visual Studio;
In Visual Studio (VS) click the "File" -> "New Project" button and create a Console application.
  • Add the library as a reference to your new project;
Locate the DLL you created in the installation steps and add that as a reference to your project.
  • Locate the MAC address of the plug you want to control;
  • The mac addresses are saved in the database that the source software is using. This is usually stored in "Documents And Settings\<user>\Local Settings\Application Data\Plugwise\Source\DB" directory. Open the PlugwiseData.mdb file that is found there with Acces.
  • Open the 'Module' table and locatie the device you want to control. For this example I recommend choosing a device that can be switched 'On' and 'Off' without any problems.
  • Locate the MAC address that is stored in the MACAddress field. For this example i will use '000D6F000037B49E'.
  • Locate the serial port the plugwise plug is using. This can be found by using the device manager in windows and look at the serial ports that are listed there. In the further example I will use "Com5".
  • Writing the code
Below is a small example program that switches the selected device on. This is just a basic example thats shows how simple it is to switch a device on.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PlugwiseLib;

namespace InstallTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //create a PlugwiseControl object which will be used to communicate with the plugs
            plugwiseControl control = new plugwiseControl("Com5");

            try
            {
                //Open the connection
                control.Open();
                //Switch the plug on
                control.Action("000D6F000037B49E", PlugwiseLib.BLL.BC.PlugwiseActions.On);

            }
            catch (Exception e)
            {
                //Do something with the Exception if it occures
            }
            finally
            {
                 //close the serial port
                 control.Close();
            }

        }
    }
}


Last edited Dec 28, 2009 at 11:42 PM by guldan, version 2

Comments

Jerry123123123 Sep 22, 2014 at 7:13 AM 
Excellent, I wish I found this years ago... thanks! Turning devices on and off works perfectly!
Could you give me an example on how to get the status of a device, and how to get power usage (wattage) of a device? I don't understand everything in your library yet...

krivc May 7, 2011 at 4:54 PM 
Hi, I am getting System.UnAuthorizedAccessException if i want to run your example or any other program which uses plugwiselib. Any idea why? I am using Windows 7 and Visual Studio 2010.

i_karl Jan 1, 2010 at 9:37 PM 
I just want to say - Great job!
I tried On and Off function work perfect.

Thanks for publish that source.....