These API examples are a collection of quick-start projects that demonstrate host computer communication with a Galil controller using the programming language of your choice. The output of a Microsoft Visual Basic API example is shown below.
Figure 1: Sample Microsoft Visual Basic API example program output.
Each API example project is contained in a .zip file and includes the following.
- All source files that comprise a fully working project
- A readme file that explains how the project was created from scratch
- An image that shows what the running program should look like (see Figure 1)
The gclib API is recommended for all new designs of supported controllers, and should be considered when updating existing projects.
API examples are available for the GalilTools Communication Library as well as prior generation libraries.
GalilTools Communication Library
Hierarchy of the GalilTools Communication Library
Figure 2: Hierarchy of GalilTools Communication Library.
Figure 2 helps define the hierarchy of the GalilTools Communication Library. The following should be taken into consideration when choosing which level of the GalilTools Communication Library to use.
- For the majority of new Windows-based applications, the COM version of the library should be used. This library interfaces with the most programming languages and has support for event-driven programming.
- When compiling a Windows C++ application which relies on galil1.dll or galil2.dll, care should be taken to select the dll and lib files that corresponds to the build machine's architecture, compiler version, and build type (debug or release).
- All of the Windows GalilTools Communication Library binaries can be found here.
- For new Linux-based applications, libGalil.so should be used. This library binary is packaged with Linux versions of GalilTools.
API Programming Examples for GalilTools Communication Library
Developer | Programming Language |
Version | GalilTools COM Library (Galil.tlb) |
GalilTools STL Library (Galil2.dll) |
GalilTools QT Library (Galil1.dll) (libgalil.so) |
---|---|---|---|---|---|
Microsoft | Visual Basic |
VS 2012
|
Download | ||
Microsoft | Visual Basic | VS 2010 | Download | ||
Microsoft | Visual Basic | VS 2008 | Download | ||
Microsoft | Visual Basic | VS 2005 | Download | ||
Microsoft | Visual Basic | VS 2003 | Download | ||
Microsoft | Visual Basic | VS 6.0 | Download | ||
Microsoft | Visual C# | VS 2012 | Download | ||
Microsoft | Visual C# | VS 2010 | Download | ||
Microsoft | Visual C# | VS 2008 | Download | ||
Microsoft | Visual C# | VS 2005 | Download | ||
Microsoft | Visual C# | VS 2003 | Download | ||
Microsoft | Visual C++ | VS 2010 | Download | Download | Download |
Microsoft | Visual C++ | VS 2008 | Download | Download | Download |
Microsoft | Visual C++ | VS 2005 | Download | Download | Download |
Microsoft | Visual C++ | VS 6.0 | Download | ||
GNU (Linux) | C++ |
4.3.0
|
Download | ||
National Instruments | Labview |
11.0, 10.0 ... 8.0
|
Download | ||
Microsoft | Excel |
Office 2002
|
Download | ||
Microsoft | HTML (JScript) |
Internet Explorer
|
Download | ||
Microsoft | JScript |
VS 5.7
|
Download | ||
Microsoft | VBScript |
VS 5.7
|
Download | ||
MathWorks | Matlab |
7.0 R14
|
Download |
Table 1: API programming examples for the GalilTools Communication Library. Note that GalilTools QT Library and GalilTools STL Library use galil.h.
Local and Host Programming
Commercial digital motion controllers are more flexible and more easy to use than analog or proprietary solutions because they can be programmed to perform a specific task. All modern Galil controllers can be used in two different ways as outlined below.
- Local Programming: A Galil DMC program file is downloaded to the controller. This program is then run from the controller's local memory. Using local programming exclusively can eliminate the need for a computer altogether, thus eliminating cost and complexity.
- Host Programming: Individual Galil DMC commands are sent from a host computer to the controller's communication bus (Ethernet, RS-232, USB, PCI, etc.). The host could be a computer running Windows, Linux, QNX or it could be an embedded device such as a touch screen. This method is often used when many devices (motion controller, barcode scanner, vision system, etc.) must be coordinated by a host.
A combination of methods 1 and 2 may also be used. This gives the option of offloading specific tasks to the motion controller, leaving high-level tasks to the host.
How to Use API programming Examples
The source code below is from the GalilTools Communication Library > GalilTools COM Library > Visual Basic 2010 project. This source file is found in the .zip file along with an instructive readme file.
Since each API example download includes a complete example, the projects can be compiled and run with minimal effort. If there are any issues, please make sure that the Galil library reference has been added to the project and that the library has been installed. Complete instructions are included in the readme.
What Next?
The API examples can be quickly adapted to meet the requirements of a real motion control application. The commands seen in the examples will be replaced with application-specific commands similar to those in Listing 1.
'Command String Description PRX= 1000;' Move the X axis 1000 counts BG X;' Begin motion MG _BGY;' Y axis still in motion MG _RPZ;' Z axis commanded position MG @IN[1];' State of digital input 1? SB 1;' Set digital output 1 MG _LFW;' State of W axis forward limit switch MG MyArray[3];' Value of element 3 of MyArray MG MyVar;' Value contained in the variable MyVar
Listing 1: Common command strings sent from a host program to the controller.
Using a Galil library allows programmers to quickly generate motion, query whether motion is complete, set and get I/O point states, query axis positions, variables, array elements, and much more. See your controller's command reference and user manual for more information.
Some application specific examples can be found on the Galil C++/COM API Example Code page.
Please see the Event Driven Programming Tech Talk for more information about the data record and interrupts.
Avoid Trippoint Commands
Note that the following trippoint commands are not normally sent from host programs because they may require a long time to execute and block further communication until they complete.
AA, AD, AI, AM, AP, AR, AS, AT, AV, MC, MF, MR, WT
Similar functionality can be gained by looking at the data record, polling, or using interrupts. For example, MG _BGn (where n is the axis of interest) can be polled instead of using AM. Examples that monitor for motion completion can be found on the Galil C++/COM API Example Code page under the Motion Complete Example Code.
If you do decide to send any of these commands from a host and you are working with a controller that allows you to do so, be aware of the following.
- You must wait until the trippoint condition has been met before the controller will process subsequent commands
- A timeout error may occur
Application Examples
Review the code below to see how easy it is to use the GalilTools API to create feature rich applications. Each "Example" project shows a small amount of code that demonstrates a specific function. Demo applications can be found on the Sample DMC Code page.
See a full listing of the example code descriptions in the examples manual.
Example Code | Description | Language | Type | Link |
---|---|---|---|---|
Motion Complete | readme | C++ C# VB |
console | Download Download Download |
Input Interrupt | readme | VB | forms application | Download |
Motion Buffering | readme | VB | console | Download |
Variable Loader | readme | VB | forms application | Download |
Save Data Record to Disk | readme | VB | forms application | Download |
Legacy Programming Libraries
The API legacy programming examples use older libraries and drivers that are incompatible with recent versions of Windows. Accordingly, they are not recommended for new applications. The GalilTools Communication Library is recommended for all new designs of supported controllers, and should be considered when updating existing projects.
Developer | Programming Language |
Version | DMCWin32 (DMC32.dll) |
ActiveX Toolkit (dmcshell.ocx) |
DMC.NET (DMCdNet.dll) |
---|---|---|---|---|---|
Borland | Delphi | 5 | Download | Download | |
Entivity | Think & Do Live! | 5.4 | Download | ||
Entivity | Think & Do Studio | 6.5 | Download | ||
MathWorks | MATLAB | 6 Release 12 | Download | ||
Microsoft | Visual Basic | 6.0 | Download | Download | |
Microsoft | Visual Basic | .NET 2003 | Download | Download | Download |
Microsoft | Visual Basic | 2005 Express | Download | Download | Download |
Microsoft | Visual C# | .NET 2003 | Download | Download | Download |
Microsoft | Visual C# | 2005 Express | Download | Download | Download |
Microsoft | Visual C++ | 6.0 | Download | Download | |
Microsoft | Visual C++ | .NET 2003 | Download | Download | Download |
Microsoft | Visual C++ | 2005 Express | Download | Download | Download |
Microsoft | Visual J# | .NET 2003 | Download | Download | Download |
Microsoft | Visual J# | 2005 Express | Download | Download | Download |
National Instruments | LabVIEW | 8.0 | Download | Download | |
National Instruments | LabVIEW | 8.5 | Download | Download | |
WonderWare | InTouch | 9.0 | Download |
Table 2: API programming languages and communication libraries for prior generation drivers.