gclib 2.0.9
Communications API for Galil controllers and PLCs
 
Loading...
Searching...
No Matches
x_simple.c
Go to the documentation of this file.
1
6#include <stdio.h> //printf()
7#include <stdlib.h> //exit()
8
9#include "gclibo.h" //by including the open-source header, all other headers are pulled in.
10
11GCon g = 0; //var used to refer to a unique connection
12
13//check return code from most gclib calls
14void check(GReturn rc)
15{
16 if (rc != G_NO_ERROR)
17 {
18 printf("ERROR: %d", rc);
19 if (g)
20 GClose(g);
21 exit (rc);
22 }
23}
24
25int main()
26{
27 char buf[1024]; //traffic buffer
28
29 check(GVersion(buf, sizeof(buf)));
30 printf("version: %s\n", buf); //Print the library version
31
32 check(GOpen("192.168.0.43", &g)); //Open a connection to Galil, store the identifier in g.
33
34 check(GInfo(g, buf, sizeof(buf)));
35 printf("info: %s\n", buf); //Print the connection info
36
37 check(GCommand(g, "MG TIME", buf, sizeof(buf), 0)); //Send MG TIME. Because response is ASCII, don't care about bytes read.
38 printf("response: %s\n", buf); //Print the response
39
40 if (g) //don't call close on a nullptr
41 GClose(g); //Don't forget to close!
42
43 return G_NO_ERROR;
44}
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition gclib.h:93
GCLIB_DLL_EXPORTED GReturn GCALL GClose(GCon g)
Closes a connection to a Galil Controller.
GCLIB_DLL_EXPORTED GReturn GCALL GVersion(GCStringOut ver, GSize ver_len)
Uses GUtility(), G_UTIL_VERSION and G_UTIL_GCAPS_VERSION to provide the library and gcaps version num...
Definition gclibo.c:29
#define G_NO_ERROR
Return value if function succeeded.
GCLIB_DLL_EXPORTED GReturn GCALL GCommand(GCon g, GCStringIn command, GBufOut buffer, GSize buffer_len, GSize *bytes_returned)
Performs a command-and-response transaction on the connection.
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition gclib.h:94
GCLIB_DLL_EXPORTED GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
Uses GUtility() and G_UTIL_INFO to provide a useful connection string.
Definition gclibo.c:49
GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon *g)
Open a connection to a Galil Controller.
int main(int argc, char *argv[])
Main function for Commands Example.
GReturn vector(GCon g, char *file)
Puts controller into Vector Mode and accepts a file defining vector points.
Definition vector.cpp:36