Galil Communications Api With Visual Basic - Galil Motion Control DMC-18 2 Series User Manual

Table of Contents

Advertisement

#include <windows.h>
#include <dmccom.h>
long rc;
HANDLEDMC hDmc;
HWND hWnd;
int main(void)
{
// Connect to controller number 1
rc = DMCOpen(1, hWnd, &hDmc);
if (rc == DMCNOERROR)
{
char szBuffer[64];
// Move the X axis 1000 counts
rc = DMCCommand(hDmc, "PR1000;BGX;", szBuffer,
sizeof(szBuffer));
// Disconnect from controller number 1 as the last action
rc = DMCClose(hDmc);
}
return 0;
}

Galil Communications API with Visual Basic

Declare Functions
To use the Galil communications API functions, add the module file included in the
C:\ProgramFiles\Galil\DMCWIN\VB directory named DMCCOM40.BAS. This module declares the
routines making them available for the VB project. To add this file, select 'Add Module' from the
'Project' menu in VB5/6.
Sending Commands in VB
Most commands are sent to the controller with the DMCCommand() function. This function allows
any Galil command to be sent from VB to the controller. The DMCCommand() function will return the
response from the controller as a string. Before sending any commands the DMCCOpen() function
must be called. This function establishes communication with the controller and is called only once.
This example code illustrates the use of DMCOpen() and DMCCommand(). A connection is made to
controller #1 in the Galil registry upon launching the application. Then, the controller is sent the
command 'TPX' whenever a command button is pressed. The response is then placed in a text box.
When the application is closed, the controller is disconnected.
To use this example, start a new Visual Basic project, place a Text Box and a Command Button on a
Form, add the DMCCOM40.BAS module, and type the following code:
Dim m_nController As Integer
Dim m_hDmc As Long
Dim m_nRetCode As Long
DMC-18x2
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com
DMCOpen() function is successful, the variable will contain the handle to the Galil
controller, which is required for all subsequent function calls. The following simple
example program written as a Visual C console application tells the controller to
move the X axis 1000 encoder counts. Remember to add DMC32.LIB to your project
prior to compiling.
Chapter 4 - Software Tools and Communications • 47

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Dmc-1812Dmc-1822Dmc-1832Dmc-1842

Table of Contents