gclib  480
Communications API for Galil controllers and PLCs
vector_example.cpp
Go to the documentation of this file.
1 
10 #include "examples.h"
11 
12 #include <iostream> //std::cout
13 using namespace std;
14 
16 
22 int main(int argc, char * argv[])
23 {
24  GReturn rc = GALIL_EXAMPLE_OK;
25  char buf[G_SMALL_BUFFER];
26 
27  //var used to refer to a unique connection. A valid connection is nonzero.
28  GCon g = 0;
29 
30  try
31  {
32  if (argc != 3)
33  {
34  cerr << "Incorrect number of arguments provided\n";
35  cerr << "Usage: Vector_Example.exe <ADDRESS> <FILE>\n";
36  return GALIL_EXAMPLE_ERROR;
37  }
38 
39  char* file = argv[2]; //Retrieve file from command line
40  char* address = argv[1]; //Retrieve address from command line
41  e(GOpen(address, &g)); //Opens a connection at the provided address
42 
43  // Puts controller into Vector Mode and accepts a file defining vector points
44  rc = vector(g, file);
45  }
46  catch (GReturn gr)
47  {
48  GError(gr, buf, G_SMALL_BUFFER); //Get Error Information
49  cout << buf << '\n';
50  if (g)
51  {
52  GSize size = sizeof(buf);
53  GUtility(g, G_UTIL_ERROR_CONTEXT, buf, &size);
54  cout << buf << '\n'; //further context
55  }
56  return GALIL_EXAMPLE_ERROR;
57  }
58 
59  return rc;
60 }
GReturn vector(GCon g, char *file)
Puts controller into Vector Mode and accepts a file defining vector points.
Definition: vector.cpp:36
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:85
GCLIB_DLL_EXPORTED GReturn GCALL GUtility(GCon g, GOption request, GMemory memory1, GMemory memory2)
Provides read/write access to driver settings and convenience features based on the request variable.
int main(int argc, char *argv[])
Main function for Commands Example.
#define G_UTIL_ERROR_CONTEXT
GUtility(), provides additional error context, where available.
Definition: gclib.h:68
GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon *g)
Open a connection to a Galil Controller.
GCLIB_DLL_EXPORTED void GCALL GError(GReturn rc, GCStringOut error, GSize error_len)
Provides a human-readable description string for return codes.
Definition: gclibo.c:336
unsigned int GSize
Size of buffers, etc.
Definition: gclib.h:86
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
Definition: gclib.h:80
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: examples.h:30
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:84