Developer Center   

 

Walkthrough - Writing An Examplar Device Plugin (Code Listing 1)

Code Listing 1:

using System;
using System.Collections.Generic;
using System.Text;

using MakeAffinity.Plugin;

namespace MyExemplarPlugin
{
  public class MyManager: MakeAffinity.Plugin.Manager.Manager
  {
    public override void Shutdown()
    {
      //During development: display a message so we know what's going on
      ReportErrorMessage(this, "Shutdown: ExampleManager1");

      //shutdown all the devices in MAFFDevices
      foreach (MakeAffinity.Plugin.Devices.Device dev in MAFFDevices)
      {
        dev.Shutdown();
      }

      //clear all MAFFDevices
      MAFFDevices.Clear();
    }

    public override void Initialise()
    {
      //During development: display a message so we know what's going on
      ReportErrorMessage(this, "MyManager.Initialise Invoked");

      //create an instance of MyRelay
      MakeAffinity.Plugin.Devices.Device myPlugin = new MyRelay();

      //initialise the instance of MyRelay so it is in a ready state
      myPlugin.Initialise();

      //add the instance to MyManager's MAFFDevices collection 
      //so the client can use it
      MAFFDevices.Add(myPlugin as MakeAffinity.Plugin.Devices.Device);
    }
  }

  public class MyRelay : MakeAffinity.Plugin.Devices.Relay
  {
    public override bool GetState(int index)
    {
      // write a message to the client's status screen
      ReportErrorMessage(this, "MyRelay.GetState: index=" + index);

      // return an example value
      return true;
    }

    public override int OutputCount
    {
      get 
      {
        // write a message to the client's status screen
        ReportErrorMessage(this, "MyRelay.OutputCount Invoked");

        // return an example value
        return 4;
      }
    }

    public override void SetState(int index, bool value)
    {
      // write a message to the client's status screen
      ReportErrorMessage(this, "MyRelay.SetState: index=" + index + " value=" + value);
    }

    public override void Initialise()
    {
      // write a message to the client's status screen
      ReportErrorMessage(this, "MyRelay.Initialise Invoked"); 
    }

    public override void Shutdown()
    {
      // write a message to the client's status screen
      ReportErrorMessage(this, "MyRelay.Shutdown Invoked");
    }

    public override void MakeSafeAll()
    {
      // write a message to the client's status screen
      ReportErrorMessage(this, "MyRelay.MakeSafeAll Invoked");
    }

    public override string BrandName
    {
      get { return "MyExemplarRelayBrand"; }
    }

    public override string ModelName
    {
      get { return "MyExemplarRelayModel"; }
    }

    public override int SerialNumber
    {
      get { return 99999; }
    }
  }
}

 
 




MakeAffinity © 2009     About     Developers     Jobs     Company Info     Business Solutions     Partners     Terms     Help     |     mon.itor.us