gclib  2.0.8
Communications API for Galil controllers and PLCs
C#.NET

gclib ships with gclib.cs, a C# class which exposes the functionality of the gclib. In addition, a C# forms example is included which demonstrates how to use gclib.cs.

For brevity, these instructions assume the default installation location of C:\Program Files (x86)\Galil\gclib.

Running the C# Example

Copy files

  • Navigate to a convenient, empty, writable location, e.g. C:\temp.
  • Copy the contents of C:\Program Files (x86)\Galil\gclib\examples\cs\2013_12.0\gclib_example to this location.

Open in Microsoft Visual Studio 2013

  • Open gclib_example.sln in Visual Studio. This demo was tested on MSVS 2013.

Add existing item, gclib.cs

  • In the Solution Explorer, right-click on gclib_example and choose Add->Existing Item...
  • Choose C:\Program Files (x86)\Galil\gclib\source\wrappers\cs\gclib.cs

Run Demo

  • Type F5 to run the program.
  • Type a valid GOpen() address in the text box and click Go.

Create Project from scratch with MSVC 2013

For brevity, these instructions assume the default installation location of C:\Program Files (x86)\Galil\gclib.

Configure Project

  • Launch Visual Studio 2013
  • Choose File->New->Project
  • In the New Project dialog, choose Visual C# -> Windows Forms Application
  • Type gclib_example for the Name
  • Choose a Location, e.g. C:\Users\user\Desktop
  • Check Create directory for solution
  • Click OK, the project will configure itself
  • In the Solution Explorer, right click on Solution 'gclib_example' (1 project) and choose Configuration Manager...
    • In the gclib_example project row, click in the Platform column and choose <New...>
      • Choose x86 from Type or select the new platform:
      • Choose Any CPU from Copy settings from:
      • Check Create new solutions platform
      • Click OK.
    • If x64 support is also desired, repeat the <New...> procedure for x64
    • In the Active solution platform combobox at the top of the Configuration Manager dialog, choose <Edit...>
      • Select Any CPU and click the Remove button
      • Click Close
    • Close the Configuration Manager dialog
  • In the Solution Explorer, right-click on gclib_example and choose Properties
    • Choose the Build item on the left
      • In the Configuration: combobox, choose All Configurations
      • Choose x86 from the Platform combobox
      • In Conditional compilation symbols type x86
    • If x64 is to be used also, add an x64 token as well to the x64 Platform
    • Save and close the Properties window
  • In the Solution Explorer, right-click on gclib_example and choose Add->Existing Item
    • Navigate to the installation location C:\Program Files (x86)\Galil\gclib\source\wrappers\cs
    • Choose gclib.cs
  • In the Solution Explorer double-click on gclib.cs
    • Note that there is a preprocessor definition starting with #if x86 and #elif x64
    • Note that these sections of code enable/disable with the choice of the Solution Platform x86/x64, usually found in the Visual Studio toolbar
    • If a non-default gclib installation location is used, the paths in these sections of code must be updated to reflect the dll locations

Add some simple code

  • In the Solution Explorer right-click on Form1.cs and choose View Code
  • Replace the text in Form1.vb with the following code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace gclib_example
{
    public partial class Form1 : Form
    {
        gclib gclib = new gclib();
        public Form1()
        {

            InitializeComponent();
            this.Text = "gclib simple example";
            TextBox tb = new TextBox();
            tb.Multiline = true;
            tb.Dock = DockStyle.Fill;
            tb.Parent = this;
            try
            {
                //calls to gclib should be in a try-catch
                tb.AppendText("GVersion: " + gclib.GVersion() + "\n");
                gclib.GOpen("192.168.0.42"); //Set an appropriate IP address here
                tb.AppendText("GInfo: " + gclib.GInfo() + "\n");
                tb.AppendText("GCommand: " + gclib.GCommand("MG TIME") + "\n");

            }
            catch(Exception ex)
            {
                tb.AppendText("ERROR: " + ex.Message);

            }
            finally
            {
                gclib.GClose(); //Don't forget to close!
            }

        }
    }
}
  • In the gclib.GOpen() call, indicate a correct IP address for the controller that is used for this project
  • Hit F5 to run the project