Plug-In/Interface Guide

Introduction

This tutorial will walk you through the process of creating a plug-in for vCrib. We will be using MS Visual Studio 2008 Express Edition and will be coding in C# and/or VB.NET. Of course there is no one standard way to create a plug-in for vCrib, but this tutorial will try to cover the basic concepts needed to get started. We will focus on the connection between your plug-in and vCrib and not so much the functionality.

Create a New Project

Create a new project in VS2008. We will be using a WinForms Application in this tutorial, but a vCrib plug-in can be a console app or even a service.
newProject.jpg

Add References to vCribAPI.dll and MySQL.Data.dll
addRef1.jpg

addRef2.jpg
addRef3.jpg

Skeleton Code

This section contains the basic skeleton code for our plug-in. First, you must declare the vCrib object.

vCribAPI.clsvCrib vc = new vCribAPI.clsvCrib();

Next, you need to create a connection with the vCrib database and set up the process information for your plug-in to tell vCrib about itself.

private void Form1_Load(object sender, EventArgs e)
{
      vc.DB_Connection(); 

      vc.Process_Name = "myVCplugin";
      vc.Process_Version = "v0.0.1";
      vc.Process_ID = vc.Process_Validation(vc.Process_Name, "MYPLUGIN", vc.Process_Version);
      this.Text = vc.Process_Name + " " + vc.Process_Version;
      vc.Process_Send_Startup(vc.Process_Name);
}

Now that we have the basics for setting up your plug-in, we will add the necessary code to add a device to vCrib and update it's status. Here is the form with the new buttons added:
buttons.jpg

Here is the code behind the 'Add Device to vCrib' button:

private void Add_btn_Click(object sender, EventArgs e)
{
         vc.Object_Add("myPluginDevice", "myPluginDeviceType", "00000", "", 0, 100, 100, 0, "");
}

….the ON button:

private void ON_btn_Click(object sender, EventArgs e)
{
        vc.Object_Update_Status_by_Address("00000", "ON", 100, vc.Process_ID);
}

….and the OFF button:

private void OFF_btn_Click(object sender, EventArgs e)
{
        vc.Object_Update_Status_by_Address("00000", "OFF", 100, vc.Process_ID);
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License