gclib  2.0.8
Communications API for Galil controllers and PLCs
commands_example.cpp
Go to the documentation of this file.
1 
9 #include "examples.h"
10 
11 using namespace std;
12 
14 
18 int main(int argc, char * argv[])
19 {
20  char buf[G_SMALL_BUFFER];
21 
22  //var used to refer to a unique connection. A valid connection is nonzero.
23  GCon g = 0;
24 
25  try
26  {
27  if (argc != 2) //Invalid number of arguments
28  {
29  cerr << "Incorrect number of arguments provided\n";
30  cerr << "Usage: commands_example.exe <ADDRESS>\n";
31  pause();
32  return GALIL_EXAMPLE_ERROR;
33  }
34 
35  char* address = argv[1]; //Retrieve address from command line
36  e(GOpen(address, &g)); //Opens a connection at the provided address
37 
38  //Demonstrates various uses of GCommand() and GUtility().
39  commands(g);
40  }
41  catch (GReturn gr)
42  {
43  error(g, gr); //see examples.h for error handling
44  pause();
45  return GALIL_EXAMPLE_ERROR;
46  }
47 
48  pause();
49  return GALIL_EXAMPLE_OK;
50 }
GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon *g)
Open a connection to a Galil Controller.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:93
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
Definition: gclib.h:89
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:94
int main(int argc, char *argv[])
Main function for Commands Example.
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: examples.h:33
GReturn commands(GCon g)
Demonstrates various uses of GCommand() and GUtility().
Definition: commands.cpp:16
void error(GCon g, GReturn rc)
An example of error handling and debugging information.
Definition: examples.h:40
int pause()
Pauses console apps for a user key stroke.
Definition: examples.h:62