/***********************************************************************************************
* Sproeval_MainForm.cs
*
* Developed by     : SafeNet, Inc
*
* Copyright (C) 2009 SafeNet, Inc. All rights reserved.
*
* Description      : Sentinel SuperPro Evaluation Program using C#.NET language.
*
* Purpose          : To demostrate the Sentinel SuperPro API for C#.NET language
*                    running under Windows.
*
***********************************************************************************************/
//Include name space
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;


namespace Sproeval
{
   /// <summary>
   /// To demostrate the SentinelSuperPro API for C#(C-Sharp) languages running under Windows.
   /// This is source file for main form . 
   /// </summary>
   public class MainForm : System.Windows.Forms.Form
   {
      // Different resource control declaration here
      private System.Windows.Forms.PictureBox pictureBox1;
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.GroupBox groupBox1;
      private System.Windows.Forms.GroupBox groupBox2;
      private System.Windows.Forms.Label label3;
      private System.Windows.Forms.Label label4;
      private System.Windows.Forms.Label label5;
      private System.Windows.Forms.Label label6;
      private System.Windows.Forms.Label label7;
      private System.Windows.Forms.Label label8;
      private System.Windows.Forms.Label label9;
      private System.Windows.Forms.GroupBox groupBox3;
      private System.Windows.Forms.GroupBox groupBox4;
      private System.Windows.Forms.Button SetProtocol;
      private System.Windows.Forms.Button FormatPkt;
      private System.Windows.Forms.Button InitializeBtn;
      private System.Windows.Forms.Button SetContactSrvBtn;
      private System.Windows.Forms.Button FindFirstBtn;
      private System.Windows.Forms.Button FindNextBtn;
      private System.Windows.Forms.Button HeartBeat;
      private System.Windows.Forms.Button ReadBtn;
      private System.Windows.Forms.Button WriteBtn;
      private System.Windows.Forms.Button OverwriteBtn;
      private System.Windows.Forms.Button ActivateBtn;
      private System.Windows.Forms.Button DecrementBtn;
      private System.Windows.Forms.Button GetHardLmt;
      private System.Windows.Forms.Button StatusBtn;
      private System.Windows.Forms.Button GetSubLicBtn;
      private System.Windows.Forms.Button ReleaseLicBtn;
      private System.Windows.Forms.TextBox CellNumber;
      private System.Windows.Forms.TextBox AccessCode;
      private System.Windows.Forms.TextBox Input;
      private System.Windows.Forms.TextBox Output;
      private System.Windows.Forms.ComboBox ComboBoxProtocolFlag;
      private System.Windows.Forms.Button ViewBtn;
      private System.Windows.Forms.Button PasswordBtn;
      private System.Windows.Forms.Button ExitBtn;

      //Global variable for key passwords
      public static bool Key_WritePW;
      public static bool Key_OWritePW;
      public static ushort WritePW;
      public static ushort OverWritePW1;
      public static ushort OverWritePW2;
      //Global variables for activate passwords
      public static ushort ActivatePwrd1, ActivatePwrd2;
      //Const size for validation
      public const ushort VALIDDATA_LENGTH = 4;
      public const ushort CELLADDRESS_LENGTH = 2;
      public const ushort MINIMUM_QUERYDATA_LENGTH = 8;

      public const int SSP_64_CELL_LIMIT = 64;
      public const int SSP_128_CELL_LIMIT = 128;
      public const int SSP_256_CELL_LIMIT = 256;
      public const int ROWS_16 = 16;
      public const int ROWS_32 = 32;
      public const int ROWS_64 = 64;

      public const ushort MIN_ACCESSCODE_RANGE = 0;
      public const ushort MAX_ACCESSCODE_RANGE = 7;
      //For byte to string manipulation.
      private System.Text.ASCIIEncoding AE = new System.Text.ASCIIEncoding();
      private System.Windows.Forms.ListBox StatusLine;
      private System.Windows.Forms.ComboBox ServerName;
      private System.Windows.Forms.GroupBox groupBox5;
      private System.Windows.Forms.ListBox ViewList;
      private System.Windows.Forms.Button KeyTypeBtn;
      private System.ComponentModel.Container components = null;
      private System.Windows.Forms.Button button1;
      private System.Windows.Forms.Button button2;
      private System.Windows.Forms.Button button3;
      private System.Windows.Forms.Button button4;
      private System.Windows.Forms.Button button5;
      private System.Windows.Forms.Button button6;
      private System.Windows.Forms.Button button7;
      private System.Windows.Forms.CheckBox MainSharing;
      private System.Windows.Forms.CheckBox SubLicSharing;
      private System.Windows.Forms.Label label10;
      private System.Windows.Forms.Button CleanUpBtn;
      private System.Windows.Forms.Button CheckTerminalServiceBtn;
      private System.Windows.Forms.CheckBox TerminalClientCheck;
      private System.Windows.Forms.Label label11;
      private System.Windows.Forms.Button SetDeveloperCodeBtn;
      private System.Windows.Forms.CheckBox DisableDeviceSharing;
      private Button SetConfigFileBtn;

      public static Superpro oSuperPro;
      public MainForm()
      {
         InitializeComponent();
      }

      //Destroy Form resource at time of closing the form.
      protected override void Dispose(bool disposing)
      {
         if (disposing)
         {
            if (components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose(disposing);
      }

      #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
          this.ViewBtn = new System.Windows.Forms.Button();
          this.groupBox1 = new System.Windows.Forms.GroupBox();
          this.SetConfigFileBtn = new System.Windows.Forms.Button();
          this.CleanUpBtn = new System.Windows.Forms.Button();
          this.ReleaseLicBtn = new System.Windows.Forms.Button();
          this.button7 = new System.Windows.Forms.Button();
          this.GetSubLicBtn = new System.Windows.Forms.Button();
          this.KeyTypeBtn = new System.Windows.Forms.Button();
          this.button6 = new System.Windows.Forms.Button();
          this.StatusBtn = new System.Windows.Forms.Button();
          this.GetHardLmt = new System.Windows.Forms.Button();
          this.button5 = new System.Windows.Forms.Button();
          this.DecrementBtn = new System.Windows.Forms.Button();
          this.ActivateBtn = new System.Windows.Forms.Button();
          this.button4 = new System.Windows.Forms.Button();
          this.OverwriteBtn = new System.Windows.Forms.Button();
          this.WriteBtn = new System.Windows.Forms.Button();
          this.button3 = new System.Windows.Forms.Button();
          this.ReadBtn = new System.Windows.Forms.Button();
          this.HeartBeat = new System.Windows.Forms.Button();
          this.button2 = new System.Windows.Forms.Button();
          this.FindNextBtn = new System.Windows.Forms.Button();
          this.FindFirstBtn = new System.Windows.Forms.Button();
          this.SetDeveloperCodeBtn = new System.Windows.Forms.Button();
          this.CheckTerminalServiceBtn = new System.Windows.Forms.Button();
          this.button1 = new System.Windows.Forms.Button();
          this.SetContactSrvBtn = new System.Windows.Forms.Button();
          this.SetProtocol = new System.Windows.Forms.Button();
          this.InitializeBtn = new System.Windows.Forms.Button();
          this.FormatPkt = new System.Windows.Forms.Button();
          this.Output = new System.Windows.Forms.TextBox();
          this.groupBox3 = new System.Windows.Forms.GroupBox();
          this.PasswordBtn = new System.Windows.Forms.Button();
          this.groupBox4 = new System.Windows.Forms.GroupBox();
          this.ExitBtn = new System.Windows.Forms.Button();
          this.groupBox5 = new System.Windows.Forms.GroupBox();
          this.ViewList = new System.Windows.Forms.ListBox();
          this.ComboBoxProtocolFlag = new System.Windows.Forms.ComboBox();
          this.AccessCode = new System.Windows.Forms.TextBox();
          this.label5 = new System.Windows.Forms.Label();
          this.Input = new System.Windows.Forms.TextBox();
          this.label3 = new System.Windows.Forms.Label();
          this.groupBox2 = new System.Windows.Forms.GroupBox();
          this.DisableDeviceSharing = new System.Windows.Forms.CheckBox();
          this.label10 = new System.Windows.Forms.Label();
          this.SubLicSharing = new System.Windows.Forms.CheckBox();
          this.MainSharing = new System.Windows.Forms.CheckBox();
          this.ServerName = new System.Windows.Forms.ComboBox();
          this.label9 = new System.Windows.Forms.Label();
          this.label8 = new System.Windows.Forms.Label();
          this.label7 = new System.Windows.Forms.Label();
          this.label6 = new System.Windows.Forms.Label();
          this.label4 = new System.Windows.Forms.Label();
          this.CellNumber = new System.Windows.Forms.TextBox();
          this.StatusLine = new System.Windows.Forms.ListBox();
          this.TerminalClientCheck = new System.Windows.Forms.CheckBox();
          this.label11 = new System.Windows.Forms.Label();
          this.pictureBox1 = new System.Windows.Forms.PictureBox();
          this.label1 = new System.Windows.Forms.Label();
          this.label2 = new System.Windows.Forms.Label();
          this.groupBox1.SuspendLayout();
          this.groupBox3.SuspendLayout();
          this.groupBox4.SuspendLayout();
          this.groupBox5.SuspendLayout();
          this.groupBox2.SuspendLayout();
          this.SuspendLayout();
          // 
          // ViewBtn
          // 
          this.ViewBtn.Location = new System.Drawing.Point(10, 28);
          this.ViewBtn.Name = "ViewBtn";
          this.ViewBtn.Size = new System.Drawing.Size(141, 28);
          this.ViewBtn.TabIndex = 0;
          this.ViewBtn.Text = "KeyView";
          this.ViewBtn.Click += new System.EventHandler(this.ViewBtn_Click);
          // 
          // groupBox1
          // 
          this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                  this.SetConfigFileBtn,
                                                                                  this.CleanUpBtn,
                                                                                  this.ReleaseLicBtn,
                                                                                  this.button7,
                                                                                  this.GetSubLicBtn,
                                                                                  this.KeyTypeBtn,
                                                                                  this.button6,
                                                                                  this.StatusBtn,
                                                                                  this.GetHardLmt,
                                                                                  this.button5,
                                                                                  this.DecrementBtn,
                                                                                  this.ActivateBtn,
                                                                                  this.button4,
                                                                                  this.OverwriteBtn,
                                                                                  this.WriteBtn,
                                                                                  this.button3,
                                                                                  this.ReadBtn,
                                                                                  this.HeartBeat,
                                                                                  this.button2,
                                                                                  this.FindNextBtn,
                                                                                  this.FindFirstBtn,
                                                                                  this.SetDeveloperCodeBtn,
                                                                                  this.CheckTerminalServiceBtn,
                                                                                  this.button1,
                                                                                  this.SetContactSrvBtn,
                                                                                  this.SetProtocol,
                                                                                  this.InitializeBtn,
                                                                                  this.FormatPkt});
          this.groupBox1.Location = new System.Drawing.Point(10, 378);
          this.groupBox1.Name = "groupBox1";
          this.groupBox1.Size = new System.Drawing.Size(448, 313);
          this.groupBox1.TabIndex = 0;
          this.groupBox1.TabStop = false;
          this.groupBox1.Text = "SuperPro APIs";
          // 
          // SetConfigFileBtn
          // 
          this.SetConfigFileBtn.Location = new System.Drawing.Point(154, 17);
          this.SetConfigFileBtn.Name = "SetConfigFileBtn";
          this.SetConfigFileBtn.Size = new System.Drawing.Size(140, 28);
          this.SetConfigFileBtn.TabIndex = 1;
          this.SetConfigFileBtn.Text = "SetConfigFile";
          this.SetConfigFileBtn.Click += new System.EventHandler(this.SetConfigFileBtn_Click);
          // 
          // CleanUpBtn
          // 
          this.CleanUpBtn.Location = new System.Drawing.Point(10, 276);
          this.CleanUpBtn.Name = "CleanUpBtn";
          this.CleanUpBtn.Size = new System.Drawing.Size(141, 28);
          this.CleanUpBtn.TabIndex = 27;
          this.CleanUpBtn.Text = "Cleanup";
          this.CleanUpBtn.Click += new System.EventHandler(this.ClearUpBtn_Click);
          // 
          // ReleaseLicBtn
          // 
          this.ReleaseLicBtn.Location = new System.Drawing.Point(297, 247);
          this.ReleaseLicBtn.Name = "ReleaseLicBtn";
          this.ReleaseLicBtn.Size = new System.Drawing.Size(141, 29);
          this.ReleaseLicBtn.TabIndex = 26;
          this.ReleaseLicBtn.Text = "ReleaseLicense";
          this.ReleaseLicBtn.Click += new System.EventHandler(this.ReleaseLicBtn_Click);
          // 
          // button7
          // 
          this.button7.Location = new System.Drawing.Point(154, 247);
          this.button7.Name = "button7";
          this.button7.Size = new System.Drawing.Size(140, 29);
          this.button7.TabIndex = 25;
          this.button7.Text = "EnumServer";
          this.button7.Click += new System.EventHandler(this.EnumServer_Click);
          // 
          // GetSubLicBtn
          // 
          this.GetSubLicBtn.Location = new System.Drawing.Point(10, 247);
          this.GetSubLicBtn.Name = "GetSubLicBtn";
          this.GetSubLicBtn.Size = new System.Drawing.Size(141, 29);
          this.GetSubLicBtn.TabIndex = 24;
          this.GetSubLicBtn.Text = "GetSubLicense";
          this.GetSubLicBtn.Click += new System.EventHandler(this.GetSubLicBtn_Click);
          // 
          // KeyTypeBtn
          // 
          this.KeyTypeBtn.Location = new System.Drawing.Point(297, 219);
          this.KeyTypeBtn.Name = "KeyTypeBtn";
          this.KeyTypeBtn.Size = new System.Drawing.Size(141, 28);
          this.KeyTypeBtn.TabIndex = 23;
          this.KeyTypeBtn.Text = "GetKeyType";
          this.KeyTypeBtn.Click += new System.EventHandler(this.KeyTypeBtn_Click);
          // 
          // button6
          // 
          this.button6.Location = new System.Drawing.Point(154, 219);
          this.button6.Name = "button6";
          this.button6.Size = new System.Drawing.Size(140, 28);
          this.button6.TabIndex = 22;
          this.button6.Text = "GetKeyInfoEx";
          this.button6.Click += new System.EventHandler(this.KeyInfo_Click);
          // 
          // StatusBtn
          // 
          this.StatusBtn.Location = new System.Drawing.Point(10, 219);
          this.StatusBtn.Name = "StatusBtn";
          this.StatusBtn.Size = new System.Drawing.Size(141, 28);
          this.StatusBtn.TabIndex = 21;
          this.StatusBtn.Text = "GetFullStatus";
          this.StatusBtn.Click += new System.EventHandler(this.StatusBtn_Click);
          // 
          // GetHardLmt
          // 
          this.GetHardLmt.Location = new System.Drawing.Point(297, 190);
          this.GetHardLmt.Name = "GetHardLmt";
          this.GetHardLmt.Size = new System.Drawing.Size(141, 29);
          this.GetHardLmt.TabIndex = 20;
          this.GetHardLmt.Text = "GetHardLimit";
          this.GetHardLmt.Click += new System.EventHandler(this.GetHardLmt_Click);
          // 
          // button5
          // 
          this.button5.Location = new System.Drawing.Point(154, 190);
          this.button5.Name = "button5";
          this.button5.Size = new System.Drawing.Size(140, 29);
          this.button5.TabIndex = 19;
          this.button5.Text = "GetVersion";
          this.button5.Click += new System.EventHandler(this.VersionBtn_Click);
          // 
          // DecrementBtn
          // 
          this.DecrementBtn.Location = new System.Drawing.Point(10, 190);
          this.DecrementBtn.Name = "DecrementBtn";
          this.DecrementBtn.Size = new System.Drawing.Size(141, 29);
          this.DecrementBtn.TabIndex = 18;
          this.DecrementBtn.Text = "Decrement";
          this.DecrementBtn.Click += new System.EventHandler(this.DecrementBtn_Click);
          // 
          // ActivateBtn
          // 
          this.ActivateBtn.Location = new System.Drawing.Point(297, 161);
          this.ActivateBtn.Name = "ActivateBtn";
          this.ActivateBtn.Size = new System.Drawing.Size(141, 29);
          this.ActivateBtn.TabIndex = 17;
          this.ActivateBtn.Text = "Activate";
          this.ActivateBtn.Click += new System.EventHandler(this.ActivateBtn_Click);
          // 
          // button4
          // 
          this.button4.Location = new System.Drawing.Point(154, 161);
          this.button4.Name = "button4";
          this.button4.Size = new System.Drawing.Size(140, 29);
          this.button4.TabIndex = 16;
          this.button4.Text = "Query";
          this.button4.Click += new System.EventHandler(this.QueryBtn_Click);
          // 
          // OverwriteBtn
          // 
          this.OverwriteBtn.Location = new System.Drawing.Point(10, 161);
          this.OverwriteBtn.Name = "OverwriteBtn";
          this.OverwriteBtn.Size = new System.Drawing.Size(141, 29);
          this.OverwriteBtn.TabIndex = 15;
          this.OverwriteBtn.Text = "Overwrite";
          this.OverwriteBtn.Click += new System.EventHandler(this.OverwriteBtn_Click);
          // 
          // WriteBtn
          // 
          this.WriteBtn.Location = new System.Drawing.Point(297, 132);
          this.WriteBtn.Name = "WriteBtn";
          this.WriteBtn.Size = new System.Drawing.Size(141, 29);
          this.WriteBtn.TabIndex = 14;
          this.WriteBtn.Text = "Write";
          this.WriteBtn.Click += new System.EventHandler(this.WriteBtn_Click);
          // 
          // button3
          // 
          this.button3.Location = new System.Drawing.Point(154, 132);
          this.button3.Name = "button3";
          this.button3.Size = new System.Drawing.Size(140, 29);
          this.button3.TabIndex = 13;
          this.button3.Text = "ExtendedRead";
          this.button3.Click += new System.EventHandler(this.XReadBtn_Click);
          // 
          // ReadBtn
          // 
          this.ReadBtn.Location = new System.Drawing.Point(10, 132);
          this.ReadBtn.Name = "ReadBtn";
          this.ReadBtn.Size = new System.Drawing.Size(141, 29);
          this.ReadBtn.TabIndex = 12;
          this.ReadBtn.Text = "Read";
          this.ReadBtn.Click += new System.EventHandler(this.ReadBtn_Click);
          // 
          // HeartBeat
          // 
          this.HeartBeat.Location = new System.Drawing.Point(297, 103);
          this.HeartBeat.Name = "HeartBeat";
          this.HeartBeat.Size = new System.Drawing.Size(141, 29);
          this.HeartBeat.TabIndex = 11;
          this.HeartBeat.Text = "SetHeartBeat";
          this.HeartBeat.Click += new System.EventHandler(this.HeartBeat_Click);
          // 
          // button2
          // 
          this.button2.Location = new System.Drawing.Point(154, 103);
          this.button2.Name = "button2";
          this.button2.Size = new System.Drawing.Size(140, 29);
          this.button2.TabIndex = 10;
          this.button2.Text = "GetContactServer";
          this.button2.Click += new System.EventHandler(this.GetContactSrv_Click);
          // 
          // FindNextBtn
          // 
          this.FindNextBtn.Location = new System.Drawing.Point(10, 103);
          this.FindNextBtn.Name = "FindNextBtn";
          this.FindNextBtn.Size = new System.Drawing.Size(141, 29);
          this.FindNextBtn.TabIndex = 9;
          this.FindNextBtn.Text = "FindNextUnit";
          this.FindNextBtn.Click += new System.EventHandler(this.FindNextBtn_Click);
          // 
          // FindFirstBtn
          // 
          this.FindFirstBtn.Location = new System.Drawing.Point(297, 74);
          this.FindFirstBtn.Name = "FindFirstBtn";
          this.FindFirstBtn.Size = new System.Drawing.Size(141, 29);
          this.FindFirstBtn.TabIndex = 8;
          this.FindFirstBtn.Text = "FindFirstUnit";
          this.FindFirstBtn.Click += new System.EventHandler(this.FindFirstBtn_Click);
          // 
          // SetDeveloperCodeBtn
          // 
          this.SetDeveloperCodeBtn.Location = new System.Drawing.Point(154, 74);
          this.SetDeveloperCodeBtn.Name = "SetDeveloperCodeBtn";
          this.SetDeveloperCodeBtn.Size = new System.Drawing.Size(140, 29);
          this.SetDeveloperCodeBtn.TabIndex = 7;
          this.SetDeveloperCodeBtn.Text = "SetDeveloperCode";
          this.SetDeveloperCodeBtn.Click += new System.EventHandler(this.SetDeveloperCodeBtn_Click);
          // 
          // CheckTerminalServiceBtn
          // 
          this.CheckTerminalServiceBtn.Location = new System.Drawing.Point(10, 74);
          this.CheckTerminalServiceBtn.Name = "CheckTerminalServiceBtn";
          this.CheckTerminalServiceBtn.Size = new System.Drawing.Size(141, 29);
          this.CheckTerminalServiceBtn.TabIndex = 6;
          this.CheckTerminalServiceBtn.Text = "CheckTerminal";
          this.CheckTerminalServiceBtn.Click += new System.EventHandler(this.CheckTerminalServiceBtn_Click);
          // 
          // button1
          // 
          this.button1.Location = new System.Drawing.Point(297, 45);
          this.button1.Name = "button1";
          this.button1.Size = new System.Drawing.Size(141, 29);
          this.button1.TabIndex = 5;
          this.button1.Text = "SetSharedLicense";
          this.button1.Click += new System.EventHandler(this.SetSharedLicenseBtn_Click);
          // 
          // SetContactSrvBtn
          // 
          this.SetContactSrvBtn.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
          this.SetContactSrvBtn.Location = new System.Drawing.Point(154, 45);
          this.SetContactSrvBtn.Name = "SetContactSrvBtn";
          this.SetContactSrvBtn.Size = new System.Drawing.Size(140, 29);
          this.SetContactSrvBtn.TabIndex = 4;
          this.SetContactSrvBtn.Text = "SetContactServer";
          this.SetContactSrvBtn.Click += new System.EventHandler(this.SetContactSrvBtn_Click);
          // 
          // SetProtocol
          // 
          this.SetProtocol.Location = new System.Drawing.Point(10, 45);
          this.SetProtocol.Name = "SetProtocol";
          this.SetProtocol.Size = new System.Drawing.Size(141, 29);
          this.SetProtocol.TabIndex = 3;
          this.SetProtocol.Text = "SetProtocol";
          this.SetProtocol.Click += new System.EventHandler(this.SetProtocol_Click);
          // 
          // InitializeBtn
          // 
          this.InitializeBtn.Location = new System.Drawing.Point(297, 17);
          this.InitializeBtn.Name = "InitializeBtn";
          this.InitializeBtn.Size = new System.Drawing.Size(141, 28);
          this.InitializeBtn.TabIndex = 2;
          this.InitializeBtn.Text = "Initialize";
          this.InitializeBtn.Click += new System.EventHandler(this.InitializeBtn_Click);
          // 
          // FormatPkt
          // 
          this.FormatPkt.Location = new System.Drawing.Point(10, 17);
          this.FormatPkt.Name = "FormatPkt";
          this.FormatPkt.Size = new System.Drawing.Size(141, 28);
          this.FormatPkt.TabIndex = 0;
          this.FormatPkt.Text = "FormatPacket";
          this.FormatPkt.Click += new System.EventHandler(this.FormatPkt_Click);
          // 
          // Output
          // 
          this.Output.Location = new System.Drawing.Point(76, 86);
          this.Output.Name = "Output";
          this.Output.ReadOnly = true;
          this.Output.Size = new System.Drawing.Size(244, 21);
          this.Output.TabIndex = 9;
          this.Output.Text = "";
          // 
          // groupBox3
          // 
          this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                  this.PasswordBtn,
                                                                                  this.ViewBtn});
          this.groupBox3.Location = new System.Drawing.Point(809, 378);
          this.groupBox3.Name = "groupBox3";
          this.groupBox3.Size = new System.Drawing.Size(161, 105);
          this.groupBox3.TabIndex = 2;
          this.groupBox3.TabStop = false;
          this.groupBox3.Text = "Miscellaneous";
          // 
          // PasswordBtn
          // 
          this.PasswordBtn.Location = new System.Drawing.Point(10, 58);
          this.PasswordBtn.Name = "PasswordBtn";
          this.PasswordBtn.Size = new System.Drawing.Size(141, 29);
          this.PasswordBtn.TabIndex = 1;
          this.PasswordBtn.Text = "Passwords";
          this.PasswordBtn.Click += new System.EventHandler(this.PasswordBtn_Click);
          // 
          // groupBox4
          // 
          this.groupBox4.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                  this.ExitBtn});
          this.groupBox4.Location = new System.Drawing.Point(809, 614);
          this.groupBox4.Name = "groupBox4";
          this.groupBox4.Size = new System.Drawing.Size(161, 66);
          this.groupBox4.TabIndex = 3;
          this.groupBox4.TabStop = false;
          // 
          // ExitBtn
          // 
          this.ExitBtn.Location = new System.Drawing.Point(10, 22);
          this.ExitBtn.Name = "ExitBtn";
          this.ExitBtn.Size = new System.Drawing.Size(141, 29);
          this.ExitBtn.TabIndex = 0;
          this.ExitBtn.Text = "E&xit";
          this.ExitBtn.Click += new System.EventHandler(this.ExitBtn_Click);
          // 
          // groupBox5
          // 
          this.groupBox5.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                  this.ViewList});
          this.groupBox5.Location = new System.Drawing.Point(31, 46);
          this.groupBox5.Name = "groupBox5";
          this.groupBox5.Size = new System.Drawing.Size(942, 323);
          this.groupBox5.TabIndex = 9;
          this.groupBox5.TabStop = false;
          this.groupBox5.Text = "KeyView";
          // 
          // ViewList
          // 
          this.ViewList.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.ViewList.ImeMode = System.Windows.Forms.ImeMode.On;
          this.ViewList.ItemHeight = 14;
          this.ViewList.Location = new System.Drawing.Point(10, 19);
          this.ViewList.Name = "ViewList";
          this.ViewList.Size = new System.Drawing.Size(922, 256);
          this.ViewList.TabIndex = 0;
          this.ViewList.SelectedIndexChanged += new System.EventHandler(this.ViewList_SelectedIndexChanged);
          // 
          // ComboBoxProtocolFlag
          // 
          this.ComboBoxProtocolFlag.AllowDrop = true;
          this.ComboBoxProtocolFlag.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
          this.ComboBoxProtocolFlag.DropDownWidth = 191;
          this.ComboBoxProtocolFlag.Items.AddRange(new object[] {
                                                                    "NSPRO_TCP_PROTOCOL "});
          this.ComboBoxProtocolFlag.Location = new System.Drawing.Point(76, 163);
          this.ComboBoxProtocolFlag.MaxDropDownItems = 4;
          this.ComboBoxProtocolFlag.Name = "ComboBoxProtocolFlag";
          this.ComboBoxProtocolFlag.Size = new System.Drawing.Size(244, 20);
          this.ComboBoxProtocolFlag.TabIndex = 3;
          // 
          // AccessCode
          // 
          this.AccessCode.Location = new System.Drawing.Point(268, 20);
          this.AccessCode.MaxLength = 1;
          this.AccessCode.Name = "AccessCode";
          this.AccessCode.Size = new System.Drawing.Size(52, 21);
          this.AccessCode.TabIndex = 1;
          this.AccessCode.Text = "";
          // 
          // label5
          // 
          this.label5.Location = new System.Drawing.Point(9, 59);
          this.label5.Name = "label5";
          this.label5.Size = new System.Drawing.Size(45, 17);
          this.label5.TabIndex = 4;
          this.label5.Text = "Input";
          // 
          // Input
          // 
          this.Input.AcceptsReturn = true;
          this.Input.Location = new System.Drawing.Point(76, 54);
          this.Input.MaxLength = 2048;
          this.Input.Name = "Input";
          this.Input.Size = new System.Drawing.Size(244, 21);
          this.Input.TabIndex = 2;
          this.Input.Text = "";
          // 
          // label3
          // 
          this.label3.Location = new System.Drawing.Point(9, 26);
          this.label3.Name = "label3";
          this.label3.Size = new System.Drawing.Size(57, 17);
          this.label3.TabIndex = 0;
          this.label3.Text = "Cell No.";
          // 
          // groupBox2
          // 
          this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                  this.DisableDeviceSharing,
                                                                                  this.label10,
                                                                                  this.SubLicSharing,
                                                                                  this.MainSharing,
                                                                                  this.ServerName,
                                                                                  this.label9,
                                                                                  this.ComboBoxProtocolFlag,
                                                                                  this.label8,
                                                                                  this.label7,
                                                                                  this.Output,
                                                                                  this.label6,
                                                                                  this.Input,
                                                                                  this.label5,
                                                                                  this.AccessCode,
                                                                                  this.label4,
                                                                                  this.CellNumber,
                                                                                  this.label3,
                                                                                  this.StatusLine,
                                                                                  this.TerminalClientCheck,
                                                                                  this.label11});
          this.groupBox2.Location = new System.Drawing.Point(468, 378);
          this.groupBox2.Name = "groupBox2";
          this.groupBox2.Size = new System.Drawing.Size(332, 313);
          this.groupBox2.TabIndex = 1;
          this.groupBox2.TabStop = false;
          this.groupBox2.Text = "Input/Output Information";
          // 
          // DisableDeviceSharing
          // 
          this.DisableDeviceSharing.Location = new System.Drawing.Point(76, 257);
          this.DisableDeviceSharing.Name = "DisableDeviceSharing";
          this.DisableDeviceSharing.Size = new System.Drawing.Size(184, 19);
          this.DisableDeviceSharing.TabIndex = 7;
          this.DisableDeviceSharing.Text = "Disable Device Sharing";
          // 
          // label10
          // 
          this.label10.AutoSize = true;
          this.label10.Location = new System.Drawing.Point(9, 234);
          this.label10.Name = "label10";
          this.label10.Size = new System.Drawing.Size(47, 12);
          this.label10.TabIndex = 15;
          this.label10.Text = "Sharing";
          // 
          // SubLicSharing
          // 
          this.SubLicSharing.Location = new System.Drawing.Point(194, 232);
          this.SubLicSharing.Name = "SubLicSharing";
          this.SubLicSharing.Size = new System.Drawing.Size(130, 17);
          this.SubLicSharing.TabIndex = 6;
          this.SubLicSharing.Text = "SubLicSharing";
          // 
          // MainSharing
          // 
          this.MainSharing.Checked = true;
          this.MainSharing.CheckState = System.Windows.Forms.CheckState.Checked;
          this.MainSharing.Location = new System.Drawing.Point(76, 232);
          this.MainSharing.Name = "MainSharing";
          this.MainSharing.Size = new System.Drawing.Size(118, 17);
          this.MainSharing.TabIndex = 5;
          this.MainSharing.Text = "MainSharing";
          this.MainSharing.CheckStateChanged += new System.EventHandler(this.MainSharing_CheckStateChanged);
          // 
          // ServerName
          // 
          this.ServerName.DropDownWidth = 191;
          this.ServerName.ItemHeight = 12;
          this.ServerName.Items.AddRange(new object[] {
                                                          "RNBO_STANDALONE",
                                                          "RNBO_SPN_DRIVER",
                                                          "RNBO_SPN_LOCAL",
                                                          "RNBO_SPN_BROADCAST",
                                                          "RNBO_SPN_ALL_MODES",
                                                          "RNBO_SPN_SERVER_MODES",
                                                          "NO-NET"});
          this.ServerName.Location = new System.Drawing.Point(76, 198);
          this.ServerName.Name = "ServerName";
          this.ServerName.Size = new System.Drawing.Size(244, 20);
          this.ServerName.TabIndex = 4;
          // 
          // label9
          // 
          this.label9.Location = new System.Drawing.Point(9, 203);
          this.label9.Name = "label9";
          this.label9.Size = new System.Drawing.Size(51, 16);
          this.label9.TabIndex = 12;
          this.label9.Text = "Server ";
          // 
          // label8
          // 
          this.label8.Location = new System.Drawing.Point(9, 168);
          this.label8.Name = "label8";
          this.label8.Size = new System.Drawing.Size(62, 17);
          this.label8.TabIndex = 10;
          this.label8.Text = "Protocol";
          // 
          // label7
          // 
          this.label7.Location = new System.Drawing.Point(9, 120);
          this.label7.Name = "label7";
          this.label7.Size = new System.Drawing.Size(51, 16);
          this.label7.TabIndex = 8;
          this.label7.Text = "Status";
          // 
          // label6
          // 
          this.label6.Location = new System.Drawing.Point(9, 90);
          this.label6.Name = "label6";
          this.label6.Size = new System.Drawing.Size(51, 18);
          this.label6.TabIndex = 6;
          this.label6.Text = "Output";
          // 
          // label4
          // 
          this.label4.Location = new System.Drawing.Point(160, 26);
          this.label4.Name = "label4";
          this.label4.Size = new System.Drawing.Size(94, 17);
          this.label4.TabIndex = 1;
          this.label4.Text = "Access Code";
          // 
          // CellNumber
          // 
          this.CellNumber.Location = new System.Drawing.Point(76, 20);
          this.CellNumber.MaxLength = 2;
          this.CellNumber.Name = "CellNumber";
          this.CellNumber.Size = new System.Drawing.Size(52, 21);
          this.CellNumber.TabIndex = 0;
          this.CellNumber.Text = "";
          // 
          // StatusLine
          // 
          this.StatusLine.BackColor = System.Drawing.SystemColors.InactiveBorder;
          this.StatusLine.CausesValidation = false;
          this.StatusLine.ItemHeight = 12;
          this.StatusLine.Location = new System.Drawing.Point(76, 120);
          this.StatusLine.Name = "StatusLine";
          this.StatusLine.Size = new System.Drawing.Size(244, 28);
          this.StatusLine.TabIndex = 10;
          // 
          // TerminalClientCheck
          // 
          this.TerminalClientCheck.Checked = true;
          this.TerminalClientCheck.CheckState = System.Windows.Forms.CheckState.Checked;
          this.TerminalClientCheck.Location = new System.Drawing.Point(186, 284);
          this.TerminalClientCheck.Name = "TerminalClientCheck";
          this.TerminalClientCheck.Size = new System.Drawing.Size(92, 19);
          this.TerminalClientCheck.TabIndex = 8;
          this.TerminalClientCheck.Text = "Enable";
          // 
          // label11
          // 
          this.label11.AutoSize = true;
          this.label11.Location = new System.Drawing.Point(9, 284);
          this.label11.Name = "label11";
          this.label11.Size = new System.Drawing.Size(131, 12);
          this.label11.TabIndex = 15;
          this.label11.Text = "Check terminal client";
          // 
          // pictureBox1
          // 
          this.pictureBox1.Location = new System.Drawing.Point(31, 9);
          this.pictureBox1.Name = "pictureBox1";
          this.pictureBox1.Size = new System.Drawing.Size(41, 37);
          this.pictureBox1.TabIndex = 0;
          this.pictureBox1.TabStop = false;
          // 
          // label1
          // 
          this.label1.Location = new System.Drawing.Point(82, 9);
          this.label1.Name = "label1";
          this.label1.Size = new System.Drawing.Size(266, 19);
          this.label1.TabIndex = 1;
          this.label1.Text = "Sentinel SuperPro Evaluation Program.";
          // 
          // label2
          // 
          this.label2.Location = new System.Drawing.Point(82, 28);
          this.label2.Name = "label2";
          this.label2.Size = new System.Drawing.Size(348, 18);
          this.label2.TabIndex = 2;
          this.label2.Text = "Copyright (C) 2009 SafeNet, Inc. All rights reserved.";
          // 
          // MainForm
          // 
          this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
          this.ClientSize = new System.Drawing.Size(985, 703);
          this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                        this.groupBox5,
                                                                        this.groupBox4,
                                                                        this.groupBox3,
                                                                        this.groupBox2,
                                                                        this.groupBox1,
                                                                        this.label2,
                                                                        this.label1,
                                                                        this.pictureBox1});
          this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
          this.MaximizeBox = false;
          this.Name = "MainForm";
          this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
          this.Text = "Sentinel SuperPro Evaluation Program";
          this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
          this.Load += new System.EventHandler(this.Form1_Load);
          this.groupBox1.ResumeLayout(false);
          this.groupBox3.ResumeLayout(false);
          this.groupBox4.ResumeLayout(false);
          this.groupBox5.ResumeLayout(false);
          this.groupBox2.ResumeLayout(false);
          this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
         uint status = 0;
         oSuperPro = new Superpro();

         try
         {
            status = oSuperPro.RNBOsproFormatPacket(Superpro.SPRO_APIPACKET_SIZE);
            if (status != 0)
            {
               return;
            }
         }
         catch
         {
            MessageBox.Show("Error during API call. Probably sx32w.dll is missing.", "Application Error");
            return;
         }

         try
         {
            MainForm MainFormObj = new MainForm();
            MainFormObj.ShowDialog();
         }
         catch
         {
            return;
         }
      }

      /*******************************************************************************************
      * Procedure : Form1_Load
      *
      * Purpose   : perform some opertaion at the time of Main form load.
      *
      * Descrip   : loads the initial main frame 
      *******************************************************************************************/
      private void Form1_Load(object sender, System.EventArgs e)
      {
         uint status = 0;

         try
         {
            //Call RNBOsproFormatPacket API at the time of Main form load
            status = oSuperPro.RNBOsproFormatPacket(Superpro.SPRO_APIPACKET_SIZE);
            if (status != 0)
            {
               MessageBox.Show("Error during FormatPacket API call.", "Application Error");
               Close();
               return;
            }
            ComboBoxProtocolFlag.SelectedIndex = 0;
         }
         catch(DllNotFoundException)
         {
            MessageBox.Show("Error during API call. Probably sx32w.dll is missing.", "Application Error");
            Close();
            return;
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      ******************************************************************************************/

      /*******************************************************************************************
      * Procedure : FormatPkt_Click
      *
      * Purpose   : called on FormatPacket button click
      *
      * Descrip   : RNBOsproFormatPacket API call is here
      *******************************************************************************************/
      private void FormatPkt_Click(object sender, System.EventArgs e)
      {
         uint status = 0;

         ServerName.Text = "";
         ComboBoxProtocolFlag.SelectedText = "";
         ComboBoxProtocolFlag.SelectedIndex = 0;

         //**************RNBOsproFormatPacket API **********************
         status = oSuperPro.RNBOsproFormatPacket(Superpro.SPRO_APIPACKET_SIZE);
         //If API successfull then
         if (status == 0)
         {
            //Clear all the input text box
            clearTextBox_succ("FormatPacket");
         }
         else
         {
            //Display API failure message with API return code.
            clearTextBox_fail("FormatPacket", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : SetProtocol_Click
      *
      * Purpose   : called on Setprotocol button click
      *
      * Descrip   : RNBOsproSetProtocol API call is here
      *******************************************************************************************/
      private void SetProtocol_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         int protocolFlag = -1;

         //Get protocol selected element value from ComboBox
         protocolFlag = ComboBoxProtocolFlag.SelectedIndex;

         if (protocolFlag == -1) // if protocol flag value is not selected
         {
            MessageBox.Show("Select a value for protocol to proceed.", "SetProtocol", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         //Assign valid constant value for protocol flag defined in Superpro.cs 
         switch (protocolFlag)
         {
            case 0:
               protocolFlag = (int)Superpro.PROTOCOL_FLAG.NSPRO_TCP_PROTOCOL;
               break;
            case 1:
               protocolFlag = (int)Superpro.PROTOCOL_FLAG.NSPRO_IPX_PROTOCOL;
               break;
            case 2:
               protocolFlag = (int)Superpro.PROTOCOL_FLAG.NSPRO_NETBEUI_PROTOCOL;
               break;
         }

         //**************RNBOsproSetProtocol API **********************
         status = oSuperPro.RNBOsproSetProtocol(protocolFlag);
         //If API successfull
         if (status == 0)
         {
            //Clear all the input text box
            clearTextBox_succ("SetProtocol");
         }
         else //If API failed then
         {
            //Display API failure message with API return code.
            clearTextBox_fail("SetProtocol", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : SetContactSrvBtn_Click
      *
      * Purpose   : Called on SetContactSrv button click
      *
      * Descrip   : RNBOsproSetContactServer API call is here
      *******************************************************************************************/
      private void SetContactSrvBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         string serverName = ""; // string variable for Server value

         //Get Contact server string value entered by user
         serverName = ServerName.Text;
         //Check Servername for length
         if (serverName.Trim().Length > 63)
         {
            MessageBox.Show("ContactServer name length must not be exceeded 63.", "SetContactServer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproSetContactServer API **********************
         status = oSuperPro.RNBOsproSetContactServer(serverName);
         //If API successfull
         if (status == 0)
         {
            //Clear all input text box on API success
            clearTextBox_succ("SetContactServer");
         }
         else
         {
            //Display API failure message with API return code.
            clearTextBox_fail("SetContactServer", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : FindFirstBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
      *
      * Purpose   : Called on FindFirstUnit button click
      *
      * Descrip   : RNBOsproFindFirstUnit API call is here
      *******************************************************************************************/
      private void FindFirstBtn_Click(object sender, System.EventArgs e)
      {
         int i_IsValid;
         ushort status = 0;
         string sDevID = "";// string variable for DevID
         ushort DevID = 0;

         //Get input string for DevID entered by user
         sDevID = Input.Text;
         //Perform validation for DevID string value and convert into integer.
         i_IsValid = isValidData(sDevID.Trim(), VALIDDATA_LENGTH, ref DevID);
         if (i_IsValid == 1) //If DevID is blank string
         {
            MessageBox.Show("Specify DeveloperID in input box to proceed.", "FindFirstUnit", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If DevID is of Invalid length
         {
            MessageBox.Show("DeveloperID must be in hex with length not exceeding 4 digits.", "FindFirstUnit", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If DevID string is not valid HexString
         {
            MessageBox.Show("DeveloperID must be in hex with length not exceeding 4 digits.", "FindFirstUnit", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproFindFirstUnit API **********************
         status = oSuperPro.RNBOsproFindFirstUnit(DevID);
         // If API successfull
         if (status == 0)
         {
            //Clear all input text box on API success
            clearTextBox_succ("FindFirstUnit");
         }
         else
         {
            //Display API failure message with API return code.
            clearTextBox_fail("FindFirstUnit", status);
         }
         return;
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : FindNextBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
      *
      * Purpose   : Called on FindNextUnit button click
      *
      * Descrip   : RNBOsproFindNextUnit API call is here
      *******************************************************************************************/
      private void FindNextBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;

         //**************RNBOsproFindNextUnit API **********************
         status = oSuperPro.RNBOsproFindNextUnit();
         //Clear all input text box on API success
         if (status == 0)
         {
            //Clear all input text box on API success
            clearTextBox_succ("FindNextUnit");
         }
         else
         {
            //Diplay API failure message with API return code.
            clearTextBox_fail("FindNextUnit", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : GetContactSrv_Click
      *
      * Purpose   : Called on GetContactServer button click
      *
      * Descrip   : RNBOsproGetContactServer API call is here
      *******************************************************************************************/
      private void GetContactSrv_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         byte[] serverName = new byte[Superpro.MAX_NAME_LEN];//For get contact server

         //**************RNBOsproGetContactServer API **********************
         status = oSuperPro.RNBOsproGetContactServer(serverName, Superpro.MAX_NAME_LEN);
         //If API get successfull
         if (status == 0)
         {
            //Display contact server name in server name box
            Output.Text = AE.GetString(serverName).ToUpper();
            //Clear all input text box on API success
            clearTextBox_succ("GetContactServer");
         }
         else
         {
            //Blank server name box to clear previously diplayed server value
            Output.Text = "";
            //Display API failure message with API return code.
            clearTextBox_fail("GetContactServer", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : HeartBeat_Click
      *
      * Purpose   : Called on SetHeartBeat button click
      *
      * Descrip   : RNBOsproSetHeartBeat API call is here
      *******************************************************************************************/
      private void HeartBeat_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         int heartBeat = 0;
         string sHeartBeat = "";

         //Get heart beat value as string
         sHeartBeat = Input.Text;
         //If heart beat value is blank
         if (sHeartBeat.Trim().Length == 0)
         {
            MessageBox.Show("Specify heartbeat value to proceed.", "SetHeartBeat", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //Convert heart beat value from string to integer
         try
         {
            heartBeat = Convert.ToInt32(Input.Text, 10);
         }
         catch (OverflowException)
         {
            //If heartbeat string value is not valid integer string value
            MessageBox.Show("Heartbeat value must be an integer between 60 to 2592000. Enter -1 for infinite heartbeat.", "SetHeartBeat", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         catch (FormatException)
         {
            //If heartbeat string value is not valid integer string value
            MessageBox.Show("Heartbeat value must be an integer between 60 to 2592000. Enter -1 for infinite heartbeat.", "SetHeartBeat", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         if ((heartBeat == Superpro.INFINITE_HEARTBEAT) || (heartBeat >= Superpro.MIN_HEARTBEAT && heartBeat <= Superpro.MAX_HEARTBEAT))
         {
            //**************RNBOsproSetHeartBeat API **********************
            status = oSuperPro.RNBOsproSetHeartBeat(heartBeat);
            //If API successfull
            if (status == 0)
            {
               //Clear all input box on API success        
               clearTextBox_succ("SetHeartBeat");
            }
            else
            {
               //Display API failure message with API return code.
               clearTextBox_fail("SetHeartBeat", status);
            }
         }
         //If heart beat value in not valid
         else
         {
            MessageBox.Show("Heartbeat value must be an integer between 60 to 2592000. Enter -1 for infinite heartbeat.", "SetHeartBeat", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : ReadBtn_Click
      *
      * Purpose   : Called on Read button click
      *
      * Descrip   : RNBOsproRead API call is here
      *******************************************************************************************/
      private void ReadBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort cellAdd = 0;
         ushort data = 0;
         int i_IsValid = -1;
         string scellAdd = "";

         //Get Cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         //Perform validation for CellAddress string value and convert into integer.
         i_IsValid = isValidData(scellAdd.Trim(), CELLADDRESS_LENGTH, ref cellAdd);

         if (i_IsValid == 1)//If celladdress value is blank 
         {
            MessageBox.Show("Specify Cell No. to proceed.", "Read", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Read", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If celladdress string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Read", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproRead API **********************
         status = oSuperPro.RNBOsproRead(cellAdd, ref data);
         //If API successful
         if (status == 0)
         {
            //Clear all input box on API success        
            clearTextBox_succ("Read");
            //Display read data
            Output.Text = Convert.ToString(data, 16);
         }
         else
         {
            //Clear output text box
            Output.Text = "";
            //Display API failure message with API return code.
            clearTextBox_fail("Read", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : XReadBtn_Click
      *
      * Purpose   : Called on Extendedread button click
      *
      * Descrip   : RNBOsproExtendedread API call is here
      *******************************************************************************************/
      private void XReadBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort cellAdd = 0;
         ushort data = 0;
         byte accessCode = 0;
         int i_IsValid = -1;
         string scellAdd = "";

         //Get Cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         //Perform validation for CellAddress string value and convert into integer.
         i_IsValid = isValidData(scellAdd, 2, ref cellAdd);
         if (i_IsValid == 1)//If celladdress value is blank 
         {
            MessageBox.Show("Specify Cell No. to proceed.", "ExtendedRead", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "ExtendedRead", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If celladdress string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "ExtendedRead", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproExtendedRead API **********************/
         status = oSuperPro.RNBOsproExtendedRead(cellAdd, ref data, ref accessCode);
         //If API successfull
         if (status == 0)
         {
            //Clear all input box on API success        
            clearTextBox_succ("ExtendedRead");

            //Display read data and thier accesscode
            AccessCode.Text = Convert.ToString(accessCode, 16);
            Output.Text = Convert.ToString(data, 16);
         }
         else
         {
            //Clear output and accessCode text box
            AccessCode.Text = "";
            Output.Text = "";
            //Display API failure message with API return code.
            clearTextBox_fail("ExtendedRead", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : WriteBtn_Click
      *
      * Purpose   : Called on Write button click
      *
      * Descrip   : RNBOsproWrite API call is here
      *******************************************************************************************/
      private void WriteBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort cellAdd = 0;
         ushort data = 0;
         byte accessCode = 0;
         int i_IsValid = -1;
         int j_IsValid = -1;
         string scellAdd = "";
         string sData = "";
         string sAccessCode = "";

         //Get Cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         // Get data value as string enterd by user
         sData = Input.Text;
         //Get accessCode value as string enterd by user
         sAccessCode = AccessCode.Text;
         //Perform validation for CellAddress string value and convert into integer.
         i_IsValid = isValidData(scellAdd.Trim(), CELLADDRESS_LENGTH, ref cellAdd);
         if (i_IsValid == 1)//If Cell address value is blank 
         {
            MessageBox.Show("Specify Cell No. to proceed.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If Cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If celladdress string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         //Perform validation for data string value and convert into integer.
         j_IsValid = isValidData(sData.Trim(), VALIDDATA_LENGTH, ref data);
         if (j_IsValid == 1)//If data value is blank 
         {
            MessageBox.Show("Specify data to be written in input box to proceed.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (j_IsValid == 2)//If data string value length is invalid
         {
            MessageBox.Show("Data to be written must be a hex with length not exceeding 4 digit.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (j_IsValid == 3)//If data string value length is invalid
         {
            MessageBox.Show("Data to be written must be a hex with length not exceeding 4 digit.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (sAccessCode.Trim().Length == 0)//If accesscode string is blank
         {
            MessageBox.Show("Specify an Access Code to proceed.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         try
         {
            //Convert accesscode from string to integer
            accessCode = Convert.ToByte(sAccessCode, 10);
         }
         catch (OverflowException)
         {
            //If access code value is not valid integer string
            MessageBox.Show("Access Code must be between 0 to 3 or 7.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         catch (FormatException)
         {
            //If access code value is not valid integer string
            MessageBox.Show("Access Code must be between 0 to 3 or 7.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (accessCode < MIN_ACCESSCODE_RANGE || (accessCode > 3 && accessCode != MAX_ACCESSCODE_RANGE))
         {
            //If access code value is not valid in valid range defined for accesscode
            MessageBox.Show("Access Code must be between 0 to 3 or 7.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //Check for write password value
         if ((!Key_WritePW) && (!Key_OWritePW))
         {
            //If write password value is blank or 0 then
            MessageBox.Show("Specify Write Password using Passwords button to proceed.", "Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproWrite API **********************
         status = oSuperPro.RNBOsproWrite(WritePW, cellAdd, ref data, ref accessCode);
         //If API successfull
         if (status == 0)
         {
            //Clear all input box on API success        
            clearTextBox_succ("Write");
         }
         else
         {
            //Display API failure message with API return code.
            clearTextBox_fail("Write", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : OverwriteBtn_Click
      *
      * Purpose   : Called on Overwrite button click
      *
      * Descrip   : RNBOsproOverwrite API call is here
      *******************************************************************************************/
      private void OverwriteBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort cellAdd = 0;
         ushort data = 0;
         byte accessCode = 0;
         int i_IsValid = -1;
         int j_IsValid = -1;
         string scellAdd = "";
         string sData = "";
         string sAccessCode = "";

         //Get Cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         //Get data value as string enterd by user
         sData = Input.Text;
         //Get accessCode value as string enterd by user
         sAccessCode = AccessCode.Text;
         //Perform validation for CellAddress string value and convert into integer.
         i_IsValid = isValidData(scellAdd.Trim(), CELLADDRESS_LENGTH, ref cellAdd);
         if (i_IsValid == 1)//if celladdress value is blank 
         {
            MessageBox.Show("Specify Cell No. to proceed.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If celladdress string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         //Perform validation for data string value and convert into integer.
         j_IsValid = isValidData(sData.Trim(), VALIDDATA_LENGTH, ref data);
         if (j_IsValid == 1)//If data value is blank 
         {
            MessageBox.Show("Specify data to be written in input box to proceed.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (j_IsValid == 2)//If data string value length is invalid
         {
            MessageBox.Show("Data to be written must be a hex with length not exceeding 4 digit.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (j_IsValid == 3)//If data string value length is invalid
         {
            MessageBox.Show("Data to be written must be a hex with length not exceeding 4 digit.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (sAccessCode.Length == 0)//If accesscode string is blank
         {
            MessageBox.Show("Specify an Access Code to proceed.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         try
         {
            //Convert accesscode from string to integer
            accessCode = Convert.ToByte(sAccessCode, 10);
         }
         catch (OverflowException)
         {
            //If access code value is not valid integer string
            MessageBox.Show("Access Code must be between 0 to 3 or 7.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         catch (FormatException)
         {
            MessageBox.Show("Access Code must be between 0 to 3 or 7.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         if (accessCode < MIN_ACCESSCODE_RANGE ||
            (accessCode > 3 && accessCode != MAX_ACCESSCODE_RANGE))
         {
            //If access code value is not valid in valid range defined for accesscode
            MessageBox.Show("Access Code must be between 0 to 3 or 7.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //Check for write and overwrite passwords value
         if (!Key_OWritePW)
         {
            //If  passwords value is blank or 0 then
            MessageBox.Show("Specify Write, Overwrite Passwords using Passwords button to proceed.", "Overwrite", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }

         //**************RNBOsproOverwrite API **********************/
         status = oSuperPro.RNBOsproOverwrite(WritePW, OverWritePW1, OverWritePW2, cellAdd, ref data, ref accessCode);
         //If API successfull
         if (status == 0)
         {
            //Clear all input box on API success        
            clearTextBox_succ("Overwrite");
         }
         else
         {
            //Display API failure messafe with API return code.
            clearTextBox_fail("Overwrite", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : QueryBtn_Click
      *
      * Purpose   : Called on Query button click
      *
      * Descrip   : RNBOsproQuery API call is here
      *******************************************************************************************/
      private void QueryBtn_Click(object sender, System.EventArgs e)
      {
         uint resp32 = 0;
         byte[] queryData;
         byte[] queryResp;
         ushort status = 0;
         ushort cellAdd = 0;
         int i_IsValid = -1;
         string scellAdd = "";
         string squeryData = "";

         // Get cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         //Perform validation for CellAddress string value and convert into integer.
         i_IsValid = isValidData(scellAdd.Trim(), CELLADDRESS_LENGTH, ref cellAdd);
         if (i_IsValid == 1)//if cell address value is blank 
         {
            MessageBox.Show("Specify Cell No. to proceed.", "Query", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Query", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If cell address string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Query", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //Get Querydata value as string enterd by user
         squeryData = Input.Text;
         //Perform validation for cell address string value and convert into integer.
         i_IsValid = isValidQueryData(squeryData.Trim());
         if (i_IsValid == 1)//If query data value is blank 
         {
            MessageBox.Show("Specify a query string to proceed.", "Query", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If query dara string value length is invalid
         {
            MessageBox.Show("Query string must be in hex.\n The length of the string must be even and between 8 to 224.", "Query", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If query is in valid hex string
         {
            MessageBox.Show("Query string must be in hex.\n The length of the string must be even and between 8 to 224.", "Query", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //Allocate array for input query and output response
         queryData = new byte[squeryData.Length / 2];
         queryResp = new byte[squeryData.Length / 2];
         //Convert query string in valid query API inputs as per all interface logic
         queryData = ConvertQueryData(squeryData);
         //**************RNBOsproQuery API ************************
         status = oSuperPro.RNBOsproQuery(cellAdd, queryData, queryResp, ref resp32, (ushort)(squeryData.Length / 2));
         //If API successful
         if (status == 0)
         {
            //Clear all input box on API success
            clearTextBox_succ("Query");
            //Display out respnse as hex string
            Output.Text = ConvertResponse(queryResp);
         }
         else
         {
            //Clear output text box
            Output.Text = "";
            //Diplay API failure message with API return code.
            clearTextBox_fail("Query", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : ActivateBtn_Click
      *
      * Purpose   : Called on Activate button click
      *
      * Descrip   : RNBOsproActivate API call is here
      *******************************************************************************************/
      private void ActivateBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort cellAdd = 0;
         int i_IsValid = -1;
         string scellAdd = "";

         //Get cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         //Perform validation for Cell Address string value and convert into integer.
         i_IsValid = isValidData(scellAdd.Trim(), CELLADDRESS_LENGTH, ref cellAdd);
         if (i_IsValid == 1)//If celladdress value is blank 
         {
            MessageBox.Show("Specify Cell No. to proceed.", "Activate", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Activate", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If cell address string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Activate", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         if ((!Key_WritePW) && (!Key_OWritePW))//check for write password value
         {
            //If write password value is blank or 0
            MessageBox.Show("Specify Write Password using Passwords button to proceed.", "Activate", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //Display Activate password form to seek activate passwords
         ActivateForm ActivateFormForm = new ActivateForm();
         ActivateFormForm.ShowDialog();//Activate form invokation

         //**************RNBOsproActivate API **********************
         status = oSuperPro.RNBOsproActivate(WritePW, ActivatePwrd1, ActivatePwrd2, cellAdd);
         //If API successfull
         if (status == 0)
         {
            //Clear all input box on API success
            clearTextBox_succ("Activate");
         }
         else
         {
            //Display API failure message with API return code.
            clearTextBox_fail("Activate", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : DecrementBtn_Click
      *
      * Purpose   : Called on Decrement button click
      *
      * Descrip   : RNBOsproDecrement API call is here
      *******************************************************************************************/
      private void DecrementBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort cellAdd = 0;
         int i_IsValid = -1;
         string scellAdd = "";

         //Get Cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         //Perform validation for Cell Address string value and convert into integer.
         i_IsValid = isValidData(scellAdd.Trim(), CELLADDRESS_LENGTH, ref cellAdd);
         if (i_IsValid == 1)//If cell address value is blank 
         {
            MessageBox.Show("Specify Cell No. to proceed.", "Decrement", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Decrement", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If cell address string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "Decrement", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if ((!Key_WritePW) && (!Key_OWritePW))//Check for write password value
         {
            //If write password value is blank or 0
            MessageBox.Show("Specify Write Password using Passwords button to proceed.", "Decrement", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproDecrement API **********************
         status = oSuperPro.RNBOsproDecrement(WritePW, cellAdd);
         //If API successfull
         if (status == 0)
         {
            //Clear all input box on API success
            clearTextBox_succ("Decrement");
         }
         else
         {
            //Display API failure message with API return code.
            clearTextBox_fail("Decrement", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : VersionBtn_Click
      *
      * Purpose   : Called on GetVersion button click
      *
      * Descrip   : RNBOsproGetVersion API call is here
      *******************************************************************************************/
      private void VersionBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         byte maj = 0;
         byte min = 0;
         byte rev = 0;
         byte ostype = 0;

         //**************RNBOsproGetVersion API **********************
         status = oSuperPro.RNBOsproGetVersion(ref maj, ref min, ref rev, ref ostype);
         //If API successfull
         if (status == 0)
         {
            string driverType = "";
            //Assign OS type string value
            switch (ostype)
            {
               case Superpro.RB_WIN3x_LOCAL_DRVR:
                  driverType = ostype + " (Windows 3.x Local Driver)";
                  break;
               case Superpro.RB_WIN3x_SYS_DRVR:
                  driverType = ostype + " (Windows 3.x System Driver)";
                  break;
               case Superpro.RB_WINNT_SYS_DRVR:
                  driverType = ostype + " (Windows NT System Driver)";
                  break;
               case Superpro.RB_WIN32s_LOCAL_DRVR:
                  driverType = ostype + " (WIN32s Local Driver)";
                  break;
               case Superpro.RB_OS2_SYS_DRVR:
                  driverType = ostype + " (OS/2 System Driver)";
                  break;
               case Superpro.RB_WIN95_SYS_DRVR:
                  driverType = ostype + " (Windows 95 System Driver)";
                  break;
               case Superpro.RB_NW_LOCAL_DRVR:
                  driverType = ostype + " (Netware local driver)";
                  break;
               case Superpro.RB_DOSRM_LOCAL_DRVR:
                  driverType = ostype + " (DOS Real Mode Local Driver)";
                  break;
               default:
                  driverType = ostype + " (Unknown Driver Type)";
                  break;
            }
            //Display version info value
            MessageBox.Show("Major Version \t:" + Convert.ToString(maj) + "\n" + "Minor Version \t:" + Convert.ToString(min) + "\n" + "Revision      \t:" + Convert.ToString(rev) + "\n" + "OS Driver Type\t:" + driverType, "GetVersion", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //Clear all input box on API success
            clearTextBox_succ("GetVersion");
         }
         else
         {
            //Diplay API failure message with API return code.
            clearTextBox_fail("GetVersion", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : GetHardLmt_Click
      *
      * Purpose   : called on GetHardLimit button click
      *
      * Descrip   : RNBOsproGetHardLimit API call is here
      *******************************************************************************************/
      private void GetHardLmt_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort hardLimit = 0;

         //**************RNBOsproGetHardLimit API **********************
         status = oSuperPro.RNBOsproGetHardLimit(out hardLimit);
         //If API successfull
         if (status == 0)
         {
            //Clear all input box on API success  
            clearTextBox_succ("GetHardLimit");
            //Display hardlimit value
            Output.Text = "HardLimit = " + Convert.ToString(hardLimit, 10);
         }
         else
         {
            //Clear output box
            Output.Text = "";
            //Display API failure messafe with API return code.             
            clearTextBox_fail("GetHardLimit", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : StatusBtn_Click
      *
      * Purpose   : Called on GetFullStatus button click
      *
      * Descrip   : RNBOsproGetFullStatus API call is here
      *******************************************************************************************/
      private void StatusBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;

         //**************RNBOsproGetFullstatus API **********************
         status = oSuperPro.RNBOsproGetFullStatus();
         //Clear all input box
         CellNumber.Text = "";
         AccessCode.Text = "";
         Input.Text = "";
         Output.Text = "";

         StatusLine.Items.Clear();
         //Display API success full message in status box
         StatusLine.Items.Add("GetFullStatus successful!");
         StatusLine.Items.Add("Status of last API called is " + status + ".");
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : KeyInfo_Click
      *
      * Purpose   : Called on KeyInfo button click
      *
      * Descrip   : RNBOsproKeyInfo API call is here
      *******************************************************************************************/
      private void KeyInfo_Click(object sender, System.EventArgs e)
      {
         KeyInfo KeyInfoForm = new KeyInfo();
         //Display key info form
         KeyInfoForm.ShowDialog();
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : GetSubLicBtn_Click
      *
      * Purpose   : Called on GetSubLicense button click
      *
      * Descrip   : RNBOsproGetSubLicense API call is here
      *******************************************************************************************/
      private void GetSubLicBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort cellAdd = 0;
         int i_IsValid = -1;
         string scellAdd = "";

         //Get cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         //Perform validation for cell address string value and convert into integer.
         i_IsValid = isValidData(scellAdd.Trim(), CELLADDRESS_LENGTH, ref cellAdd);
         if (i_IsValid == 1)//If cell address value is blank
         {
            MessageBox.Show("Specify Cell No. to proceed.", "GetSubLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "GetSubLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If cell address string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "GetSubLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproGetSubLicense API **********************
         status = oSuperPro.RNBOsproGetSubLicense(cellAdd);
         //If API successfull
         if (status == 0)
         {
            //Clear all input box on API success        
            clearTextBox_succ("GetSubLicense");
         }
         else
         {
            // Display API failure message with API return code.                
            clearTextBox_fail("GetSubLicense", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : ReleaseLicBtn_Click
      *
      * Purpose   : Called on ReleaseLicense button click
      *
      * Descrip   : RNBOsproReleaseLicense API call is here
      *******************************************************************************************/
      private void ReleaseLicBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         ushort cellAdd = 0;
         ushort numLic = 0;
         int i_IsValid = -1;
         string scellAdd = "";
         string snumLic = "";

         //Get Cell address value as string enterd by user
         scellAdd = CellNumber.Text;
         //Perform validation for cell address string value and convert into integer.
         i_IsValid = isValidData(scellAdd.Trim(), CELLADDRESS_LENGTH, ref cellAdd);
         if (i_IsValid == 1)//If cell address value is blank
         {
            MessageBox.Show("Specify Cell No. to proceed.", "ReleaseLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 2)//If cell address string value length is invalid
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "ReleaseLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if (i_IsValid == 3)//If cell address string is in valid hex string
         {
            MessageBox.Show("Cell No. must be a hex with length not exceeding 2 digit.", "ReleaseLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         snumLic = Input.Text;
         if (snumLic.Trim().Length == 0)//If number of license  value is blank 
         {
            MessageBox.Show("Specify number of licenses to be released in the input box to proceed.", "ReleaseLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         try
         {
            //Convert number of license value into integer
            numLic = Convert.ToUInt16(snumLic, 10);
         }
         catch (OverflowException)
         {
            //If number of license value is not valid integer string 
            MessageBox.Show("Number of sublicense to release must be an integer between 0 to 65535.", "ReleaseLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         catch (FormatException)
         {
            //If number of license value is not valid integer string 
            MessageBox.Show("Number of sublicense to release must be an integer between 0 to 65535.", "ReleaseLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         if ((numLic < 0 || numLic > 65535))//Check for valid value of number of license
         {
            MessageBox.Show("Number of sublicense to release must be an integer between 0 to 65535.", "ReleaseLicense", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproReleaseLicense API **********************
         status = oSuperPro.RNBOsproReleaseLicense(cellAdd, ref numLic);
         //If API successfull
         if (status == 0)
         {
            WritePW = 0; //Key write password
            OverWritePW1 = 0; //Key Overwrite password1
            OverWritePW2 = 0; //Key Overwrite password2
            Key_WritePW = false;
            Key_OWritePW = false;
            //Clear all input box on API success
            CellNumber.Text = "";
            AccessCode.Text = "";
            Input.Text = "";
            if (cellAdd != 0)
            {
               Output.Text = Convert.ToString(numLic);
            }
            else
            {
               Output.Text = "";
            }
            StatusLine.Items.Clear();
            StatusLine.Items.Add("ReleaseLicense successful!");
         }
         else
         {
            //Diplay API failure message with API return code.
            clearTextBox_fail("ReleaseLicense", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : EnumServer_Click
      *
      * Purpose   : Called on EnumServer button click
      *
      * Descrip   : RNBOsproEnumServer API call is here
      *******************************************************************************************/
      private void EnumServer_Click(object sender, System.EventArgs e)
      {
         EnumServer EnumForm = new EnumServer();
         //Display EnumServer Box
         EnumForm.ShowDialog();
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : ViewBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
      *
      * Purpose   : Called on KeyView button click
      *
      * Descrip   : Retrieves the memory size,form factor and other details about the Sentinel keys.
      *******************************************************************************************/
      private void ViewBtn_Click(object sender, System.EventArgs e)
      {
         ushort data = 0;
         byte accessCode = 0;
         ushort status = 0;
         uint rows = 0;  //Loop variable;
         uint columns;           //Loop variable
         string gViewText = ""; //String variable to display in keyview list box
         int keyFamily = 0;
         int KeyFormFactor = 0;
         int KeyMemory = 0;
         int totalCells = 0;
         int factor = 0;
         string space_pad1;
         string space_pad2;
         string space_pad3;
         string space_pad4;
         string space_pad7;


         Cursor.Current = Cursors.WaitCursor;
         ViewList.Items.Clear();
         //Get actual memory size of the key
         status = oSuperPro.RNBOsproGetKeyType(ref keyFamily, ref  KeyFormFactor, ref KeyMemory);
         if (status != 0)
         {
            MessageBox.Show("Key not found! Return code is " + Convert.ToString(status) + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }
         else
         {
            if (KeyMemory == SSP_64_CELL_LIMIT)
            {
               factor = ROWS_16;
               totalCells = (ushort)(KeyMemory);
               ViewList.ScrollAlwaysVisible = false;
            }
            if (KeyMemory == SSP_128_CELL_LIMIT)
            {
               factor = ROWS_32;
               totalCells = (ushort)(KeyMemory);
               ViewList.ScrollAlwaysVisible = true;
            }
            if (KeyMemory == SSP_256_CELL_LIMIT)
            {
               factor = ROWS_64;
               totalCells = (ushort)(KeyMemory);
               ViewList.ScrollAlwaysVisible = true;
            }
         }
         //Heading for key view
         string viewString;
         viewString = "  Adr    Data    AC         Adr    Data    AC         Adr    Data    AC         Adr    Data    AC  ";
         ViewList.Items.Add(viewString);
         //Formating for keyview
         viewString = "  ---    ----    --         ---    ----    --         ---    ----    --         ---    ----    --  ";
         ViewList.Items.Add(viewString);

         //Loop to display  rows in key view list box
         for (rows = 0; rows < ((totalCells / 4)); rows++)
         {
            //Assign blank to temp string variables used for allignment
            gViewText = "";
            space_pad1 = "";
            space_pad2 = "";
            space_pad3 = "";
            space_pad4 = "";
            space_pad7 = "";

            //Loop to make 4 cell key data in each row of list box
            for (columns = 0; columns < 4; columns++)
            {
               space_pad4 = "".PadLeft(2);//For just allignment and formmating of key view
               space_pad1 = Convert.ToString(rows + factor * columns, 16).PadLeft(2, '0');// calculate celladdress value in hex
               data = 0;
               accessCode = 0;
               //Call RNBOsproExtendedRead API to display key view
               status = oSuperPro.RNBOsproExtendedRead((ushort)(rows + factor * columns), ref data, ref accessCode);
               //If API get successfull
               if (status != 0)
               {
                  space_pad2 = "????".PadLeft(9);//For just allignment and formmating of key view
                  space_pad3 = "?".PadLeft(6);//else display unknown accessCode(?) 
                  space_pad7 = "".PadLeft(7);
                  //concat one string to display one cell view
                  gViewText = gViewText + space_pad4 + space_pad1 + space_pad2 + space_pad3 + space_pad7;
               }
               //If API succesfull
               else
               {
                  space_pad2 = Convert.ToString(data, 16).PadLeft(4, '0');// cell data
                  space_pad3 = Convert.ToString(accessCode, 16).PadLeft(1, '0');//accesscode
                  string space_pad5 = "".PadLeft(5);//For just allignment and formmating of key view
                  string space_pad6 = "".PadLeft(5);//For just allignment and formmating of key view
                  space_pad7 = "".PadLeft(7);
                  //concat one string to display one cell view
                  gViewText = gViewText + space_pad4 + space_pad1 + space_pad5 + space_pad2 + space_pad6 + space_pad3 + space_pad7;
               }
            }
            //Add row in ListBOX
            ViewList.Items.Add(gViewText.ToUpper());
            //ViewList.Items.Add(line);
         }
         Cursor.Current = Cursors.Default;
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : PasswordBtn_Click
      *
      * Purpose   : Called on Password button click
      *
      * Descrip   : This function is to Password dialog box to enter write and overwrite password of key
      *******************************************************************************************/
      private void PasswordBtn_Click(object sender, System.EventArgs e)
      {
         //Display password form to seek key passwords form user
         Password PasswordForm = new Password();
         PasswordForm.ShowDialog();
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : ExitBtn_Click
      *
      * Purpose   : Called on Exit button click
      *
      * Descrip   : This function is to call releaseLicense API at the time of application exit
      *******************************************************************************************/
      private void ExitBtn_Click(object sender, System.EventArgs e)
      {
         Close();
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
      *
      * Purpose   : called on Initialize button click
      *
      * Descrip   : RNBOsproInitialize API call is here
      *******************************************************************************************/
      private void InitializeBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;

         //**************RNBOsproInitialize API **********************/
         status = oSuperPro.RNBOsproInitialize();
         //If API get successfull
         if (status == 0)
         {
            //Clear all input box on API success
            clearTextBox_succ("Initialize");
         }
         else
         {
            //Display API failure message with return code of API
            clearTextBox_fail("Initialize", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : isValidData(ByRef thisString As String, ByVal length As Integer, ByRef OutData As Int32) As Int16
      *
      * Purpose   : This will call to validate different user inputs.
      *
      * Descrip   : This is used to to check valid hex string and valid length of inputs.
      *******************************************************************************************/
      public static int isValidData(string thisString, ushort length, ref ushort OutData)
      {
         if (thisString == null)
         {
            return 1;
         }
         //If string blank then retun 1
         if (thisString.Length <= 0)
            return 1;
         //If string length is invalid then return 2
         if (thisString.Length > length)
            return 2;
         //String is not valid hex string then return 3 
         if (readHexData(thisString, ref OutData) == -1)
            return 3;
         //If data is valid then return 0
         return 0;
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : readHexData(string thisString,ref uint OutData) 
      *
      * Purpose   : This will call to convert hexstring into integer value
      *******************************************************************************************/
      public static int readHexData(string thisString, ref ushort OutData)
      {
         if (thisString == null)
         {
            return -1;
         }

         int i = 0;
         char[] singleChar = new char[1];

         //Loop for all character in string
         while (i < thisString.Length)
         {
            singleChar = thisString.ToCharArray(i, 1);

            //Check for valid hex character
            // if not a valid hex character then rerurn -1
            if ((((int)singleChar[0] < '0') || ((int)singleChar[0] > '9')) && (((int)singleChar[0] < 'A') || ((int)singleChar[0] > 'F') && ((int)singleChar[0] < 'a') || ((int)singleChar[0] > 'f')))
               return -1;
            i++;
         }
         //If valid hex string then convert into integer
         try
         {
            OutData = Convert.ToUInt16(thisString, 16);
         }
         catch (OverflowException)
         {
            return -1;
         }
         catch (FormatException)
         {
            return -1;
         }
         //If valid hex data then return 0   
         return 0;
      }
      /*******************************************************************************************
      * END OF FUNCTION
      ********************************************************************************************

      /*******************************************************************************************
      * Procedure : isValidQueryData(ByRef input As String) As Int16
      *
      * Purpose   : Perform some validation on query data
      *******************************************************************************************/
      public static int isValidQueryData(string input)
      {
         if (input == null)
         {
            return 1;
         }
         string thisString;
         int stringLength;

         thisString = input.ToUpper();
         stringLength = thisString.Length;
         int i = 0;

         if (stringLength <= 0)//Check for blank querydata string
            return 1;
         //Check for even length query data
         if (stringLength > (Superpro.SPRO_MAX_QUERY_SIZE * 2) ||
            stringLength < MINIMUM_QUERYDATA_LENGTH ||
            ((stringLength % 2) != 0))
            return 2;

         char[] singleChar = new char[1];
         //Check for valid hex string
         while (i < stringLength)
         {
            singleChar = thisString.ToCharArray(i, 1);

            //If not a vallid hex character then return 3
            if ((((int)singleChar[0] < '0') || ((int)singleChar[0] > '9')) &&
               (((int)singleChar[0] < 'A') || ((int)singleChar[0] > 'F') &&
               ((int)singleChar[0] < 'a') || ((int)singleChar[0] > 'f')))
               return 3;
            i++;
         }
         //if valid querydata then return 0
         return 0;
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : ConvertQueryData(ByRef input As String) As Int16
      *
      * Purpose   : Convert input query data in byte
      *******************************************************************************************/
      static byte[] ConvertQueryData(string input)
      {
         int i = 0, j = 0;
         char[] singleChar = new char[1];//character variable
         char[] singleChar1 = new char[1];//character variable
         byte[] queryBuffer = new byte[input.Length / 2];//buffur for querydata
         string thisString;
         int stringLength;
         int hiByte, loByte;

         thisString = input.ToUpper();//convert query string into upercase
         stringLength = thisString.Length;

         //Here we will convert query string into array of length /2 of byte
         for (i = 0; i < stringLength; i += 2)
         {
            //Get the character from input query string
            singleChar = thisString.ToCharArray(i, 1);
            //Get ith +1 character from input query string
            singleChar1 = thisString.ToCharArray(i + 1, 1);
            //Convert ith character into there aschi value
            if ((singleChar[0] >= '0') && (singleChar[0] <= '9'))
               hiByte = (int)(singleChar[0] - 48) * 16;
            else
               hiByte = (int)(singleChar[0] - 55) * 16;

            if ((singleChar1[0] >= '0') && (singleChar1[0] <= '9'))
               loByte = (int)singleChar1[0] - 48;
            else
               loByte = (int)singleChar1[0] - 55;
            //Add ascii value of ith and ith+1 character and assign to jth element of 
            //Array of length/2 of byte data type
            queryBuffer[j] = (byte)(hiByte + loByte);
            j++;//increment j by 1
         }
         return queryBuffer;//return array of byte
      }

      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : ConvertResponse(byte[] charString) 
      *
      * Purpose   : Convert query response in readable char
      *******************************************************************************************/
      static string ConvertResponse(byte[] charString)
      {
         StringBuilder hexValueBuffer = new StringBuilder();
         StringBuilder RevhexValueBuffer = new StringBuilder();
         int i;
         int combinedResponseLength = 0;
         bool TruncationFlag = true;

         //Convert query response to hex string
         for (i = 0; i < charString.Length; i++)
            hexValueBuffer.Append(IntToHex(charString[i], 2));

         //For reversing 
         for (int j = 0; j < hexValueBuffer.Length; j += 2)
         {
            RevhexValueBuffer.Append(hexValueBuffer[j + 1]);
            RevhexValueBuffer.Append(hexValueBuffer[j]);
         }

         if (RevhexValueBuffer.Length >= 40)
         {
             if (RevhexValueBuffer.Length <= 64)
             {
                 combinedResponseLength = RevhexValueBuffer.Length - 32;
             }
             else
             {
                 combinedResponseLength = RevhexValueBuffer.Length / 2;
             }

             for (i = combinedResponseLength; i < RevhexValueBuffer.Length; i++)
             {
                 if (RevhexValueBuffer[i] != '0')
                 {
                     TruncationFlag = false;
                 }
             }

             if (TruncationFlag)
             {
                 RevhexValueBuffer.Remove(combinedResponseLength, RevhexValueBuffer.Length - combinedResponseLength);
             }
         }
         return RevhexValueBuffer.ToString();
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : IntToHex(int decValue, int length)
      *
      * Purpose   : Convert int to ascii char
      *******************************************************************************************/
      static string IntToHex(int decValue, int length)
      {
         StringBuilder hexValueBuffer = new StringBuilder();
         char hexChar;
         int quotient = decValue;
         int remainder;
         int count = 0;

         //Convert response into double length hex string to display valid hex query response for user
         while ((quotient > 0) || (count < length))
         {
            remainder = quotient % 16;
            if (remainder <= 9)
               hexChar = (char)(remainder + 48);
            else
               hexChar = (char)(remainder + 55);

            hexValueBuffer.Append(hexChar);
            quotient /= 16;
            count++;
         }
         return (hexValueBuffer.ToString());
      }/*End of InttoHex fn*/
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : clearTextBox_succ(string API)
      *
      * Purpose   : This will call when API get success.
      *
      * Descrip   : THis is used to clear diff. input box when API get success.
      *******************************************************************************************/
      public void clearTextBox_succ(string API)
      {
         if (API == null)
         {
            return;
         }

         CellNumber.Text = "";
         Input.Text = "";
         StatusLine.Items.Clear();
         StatusLine.Items.Add(API + " successful!");

         //Clear diffrent on success of API
         if (API.Equals("FormatPacket") || API.Equals("Initialize") ||
             API.Equals("SetContactServer") || API.Equals("SetProtocol") ||
             API.Equals("FindFirstUnit") || API.Equals("FindNextUnit") ||
             API.Equals("SetHeartBeat") || API.Equals("Write") ||
             API.Equals("Overwrite") || API.Equals("Activate") ||
             API.Equals("Decrement") || API.Equals("GetVersion") ||
             API.Equals("GetSubLicense") || API.Equals("ReleaseLicense") ||
             API.Equals("Cleanup") || API.Equals("GetKeyType") ||
             API.Equals("SetSharedLicense") || API.Equals("CheckTerminalService") ||
             API.Equals("SetDeveloperCode") || API.Equals("SetConfigFile"))
         {
            AccessCode.Text = "";
            Output.Text = "";
            return;
         }
         if (API.Equals("Read") || API.Equals("GetHardLimit") ||
            API.Equals("GetContactServer") || API.Equals("Query"))
         {
            AccessCode.Text = "";
            return;
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*******************************************************************************************
      * Procedure : clearTextBox_fail(string API,uint retCode)
      *
      * Purpose   : This will call when API get fail
      *
      * Descrip   : THis is used to display API return code when API failed.
      *******************************************************************************************/
      public void clearTextBox_fail(string API, uint retCode)
      {
         //display API failure message with API return code
         StatusLine.Items.Clear();
         StatusLine.Items.Add(API + " failed!");
         StatusLine.Items.Add("Return code is " + retCode + ".");
      }
      /*******************************************************************************************
      * END OF FUNCTION
      *******************************************************************************************/

      /*********************************************************************************************
      * Procedure   : KeyTypeBtn_Click(object sender,System.EventArg e)
      * Purpose     : Called on KeyTypeBtn button click
      * Description : Retrieves the memory size,form factor and other details  about 
      *               the Sentinel Keys
      *********************************************************************************************/
      private void KeyTypeBtn_Click(object sender, System.EventArgs e)
      {
         ushort status = 0;
         int keyFamily = 0;
         int keyFormFactor = 0;
         int keyMemorySize = 0;
         string skeyFamily = "";
         string skeyFormFactor = "";

         //**************RNBOsproGetKeyType API **********************/
         status = oSuperPro.RNBOsproGetKeyType(ref keyFamily, ref keyFormFactor, ref keyMemorySize);
         //If API successfull
         if (status == 0)
         {
            //Display Key Type value
            if (keyFamily == 0)
               skeyFamily = "SP_SUPERPRO_FAMILY_KEY";
            else if (keyFamily == 1)
               skeyFamily = "SP_ULTRAPRO_FAMILY_KEY";
            else
               skeyFamily = "SP_UNKNOWN_FAMILY_KEY";

           if (keyFormFactor == 0)
               skeyFormFactor = "SP_KEY_FORM_FACTOR_PARALLEL";
           else if (keyFormFactor == 1)
               skeyFormFactor = "SP_KEY_FORM_FACTOR_USB";
           else if (keyFormFactor == 2)
               skeyFormFactor = "SP_KEY_FORM_FACTOR_SOFT";

            //Clear all input box on API success
            clearTextBox_succ("GetKeyType");

            MessageBox.Show("Key Family\t:" + skeyFamily + "\n" +
                            "Key Form Factor\t:" + skeyFormFactor + "\n" +
                            "Key Memory Size\t:" + Convert.ToString(keyMemorySize) + " Cells",
                            "GetKeyType", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
            //Diplay API failure message with API return code.
            clearTextBox_fail("GetKeyType", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      * *****************************************************************************************/

      /*******************************************************************************************
      * Procedure   : CleanUpBtn_Click(object sender, System.EventArgs e)
      * Purpose     : Called on KeyTypeBtn button click
      * Description : Cleans the system resources issued to the SuperPro API packet/library.
      *******************************************************************************************/
      private void ClearUpBtn_Click(object sender, System.EventArgs e)
      {
         //**************RNBOsproCleanup API **********************
         oSuperPro.RNBOsproCleanup();
         WritePW = 0; //Key write password
         OverWritePW1 = 0; //Key Overwrite password1
         OverWritePW2 = 0; //Key Overwrite password2
         Key_WritePW = false;
         Key_OWritePW = false;
         //clear all input box on API success
         clearTextBox_succ("Cleanup");
      }
      /*******************************************************************************************
      * END OF FUNCTION
      ******************************************************************************************/

      private void ViewList_SelectedIndexChanged(object sender, System.EventArgs e)
      {
      }
      /*******************************************************************************************
      * Procedure   : SetSharedLicenseBtn_Click(object sender, System.EventArgs e)
      * Purpose     : Called on SetSharedLicenseBtn button click
      * Description : Enables license sharing for the user limit specified in your design
      *******************************************************************************************/
      private void SetSharedLicenseBtn_Click(object sender, System.EventArgs e)
      {
         ushort shareMainLic, shareSubLic;
         ushort status;
         shareMainLic = Superpro.SP_DISABLE_MAINLIC_SHARING;
         shareSubLic = Superpro.SP_DISABLE_SUBLIC_SHARING;

         if (MainSharing.Checked)
         {
            shareMainLic = Superpro.SP_ENABLE_MAINLIC_SHARING;
         }

         if (SubLicSharing.Checked)
         {
            shareSubLic = Superpro.SP_ENABLE_SUBLIC_SHARING;
         }

         if (DisableDeviceSharing.Checked)
         {
            shareMainLic |= Superpro.SP_DISABLE_DEVICE_SHARING;
         }

         //**************RNBOsproSetSharedLicense API **********************
         status = oSuperPro.RNBOsproSetSharedLicense(shareMainLic, shareSubLic);
         //If API successfull
         if (status == 0)
         {
            //Clear all the input text box
            clearTextBox_succ("SetSharedLicense");
         }
         else //If API failed then
         {
            //Display API failure message with API return code.
            clearTextBox_fail("SetSharedLicense", status);
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      * *****************************************************************************************/

      /*******************************************************************************************
      * Procedure   : MainSharing_CheckStateChanged(object sender, System.EventArgs e)
      * Purpose     : Called on MainSharing's check box state changes
      * Description : For toggling functionality
      *******************************************************************************************/
      private void MainSharing_CheckStateChanged(object sender, System.EventArgs e)
      {
         if (MainSharing.Checked == false)
         {
            SubLicSharing.Checked = false;
            SubLicSharing.Enabled = false;
         }
         else
         {
            SubLicSharing.Enabled = true;
         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      * *****************************************************************************************/

      /*******************************************************************************************
      * Procedure   : MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
      * Purpose     : Called when Application closed by clicking on X 
      * Description : For releasing license if any issued
      *******************************************************************************************/
      private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
      {
         ushort numOfLicense = 0;

         //Call RNBOsproReleaseLicense API to release all the license issued for this client
         try
         {
            oSuperPro.RNBOsproReleaseLicense(0x0, ref numOfLicense);
         }
         catch (Exception)
         {

         }
      }
      /*******************************************************************************************
      * END OF FUNCTION
      * *****************************************************************************************/


      /*******************************************************************************************
      * Procedure   : CheckTerminalServiceBtn_Click(object sender, System.EventArgs e)
      * Purpose     : Called on CheckTerminalServiceBtn button click
      * Description : Allow or disallow the terminal clients checking for licenses
      *******************************************************************************************/
      private void CheckTerminalServiceBtn_Click(object sender, System.EventArgs e)
      {
         int allowCheck;
         ushort status;
         allowCheck = Superpro.SP_ALLOW_CHECK_TERMINAL_CLIENT;

         if (TerminalClientCheck.Checked == true)
         {
            allowCheck = Superpro.SP_ALLOW_CHECK_TERMINAL_CLIENT;
         }
         if (TerminalClientCheck.Checked == false)
         {
            allowCheck = Superpro.SP_DISALLOW_CHECK_TERMINAL_CLIENT;
         }

         //**************RNBOsproCheckTerminalService API **********************
         status = oSuperPro.RNBOsproCheckTerminalService(allowCheck);
         //If API successfull
         if (status == 0)
         {
            //Clear all the input text box
            clearTextBox_succ("CheckTerminalService");
         }
         else //If API failed then
         {
            //Display API failure message with API return code.
            clearTextBox_fail("CheckTerminalService", status);
         }
      }
      /*******************************************************************************************
       * END OF FUNCTION
       * *****************************************************************************************/

      /*******************************************************************************************
      * Procedure   : SetDeveloperCodeBtn_Click(object sender, System.EventArgs e)
      * Purpose     : Called on SetDeveloperCodeBtn button click
      * Description : Set or varify the developer code
      *******************************************************************************************/
      private void SetDeveloperCodeBtn_Click(object sender, System.EventArgs e)
      {
         if (Input.Text.Trim().Length == 0)
         {
            MessageBox.Show("Specify the Developer Code to proceed.", "SetDeveloperCode");
            return;
         }

         string szCode = Input.Text.Trim();

         if ((szCode.Length % 2 != 0) || (szCode.Length > 2048))
         {
            MessageBox.Show("The length of Developer Code must be even and less than 2048.", "SetDeveloperCode");
            return;
         }

         if (System.Text.RegularExpressions.Regex.IsMatch(szCode, "[^0-9a-fA-F]"))
         {
            MessageBox.Show("Developer Code must be in hex.", "SetDeveloperCode");
            return;
         }

         byte[] baDeveloperCode = ConvertQueryData(szCode);

         ushort status = oSuperPro.RNBOsproSetDeveloperCode(baDeveloperCode, (uint)baDeveloperCode.Length);
         if (status == 0)
         {
            clearTextBox_succ("SetDeveloperCode");
         }
         else
         {
            clearTextBox_fail("SetDeveloperCode", status);
         }
      }

      /*******************************************************************************************
       * Procedure : SetConfigFileBtn_Click
       *
       * Purpose   : Called on SetConfigFile button click
       *
       * Descrip   : RNBOsproSetConfigFile API call is here
       *******************************************************************************************/
      private void SetConfigFileBtn_Click(object sender, EventArgs e)
      {
         ushort status = 0;
         string cfgFileName = ""; // string variable for Server value

         //Get Contact server string value entered by user
         cfgFileName = Input.Text;
         //Check Servername for length
         if (cfgFileName.Trim().Length > 256)
         {
            MessageBox.Show("Configuration file name length must not be exceeded 256.", "SetConfigFile", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         if (cfgFileName.Trim().Length == 0)
         {
            MessageBox.Show("Please specify a configuration file and go on.", "SetConfigFile", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
         }

         //**************RNBOsproSetContactServer API **********************
         status = oSuperPro.RNBOsproSetConfigFile(cfgFileName);
         //If API successfull
         if (status == 0)
         {
            //Clear all input text box on API success
            clearTextBox_succ("SetConfigFile");
         }
         else
         {
            //Display API failure message with API return code.
            clearTextBox_fail("SetConfigFile", status);
         }
      }
      /*******************************************************************************************
       * END OF FUNCTION
       * *****************************************************************************************/
   }
}
