| gclib 2.0.7 Communications API for Galil controllers and PLCs |

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
11 GCon g = 0; //var used to refer to a unique connection
12
13 //check return code from most gclib calls
14 void 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
25 int 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 }
gclibo.h
GClose
GCLIB_DLL_EXPORTED GReturn GCALL GClose(GCon g)
Closes a connection to a Galil Controller.
GVersion
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
GCommand
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.
GInfo
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
GOpen
GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon *g)
Open a connection to a Galil Controller.
GReturn
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:93
G_NO_ERROR
#define G_NO_ERROR
Return value if function succeeded.
Definition: gclib_errors.h:13
GCon
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:94
main
int main(int argc, char *argv[])
Main function for Commands Example.
Definition: commands_example.cpp:18