gclib  556
Communications API for Galil controllers and PLCs
motion_complete_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 
20 int main(int argc, char * argv[])
21 {
22  GReturn rc = GALIL_EXAMPLE_OK;
23  char buf[G_SMALL_BUFFER];
24 
25  //var used to refer to a unique connection. A valid connection is nonzero.
26  GCon g = 0;
27  try
28  {
29  if (argc != 2) //Invalid number of arguments
30  {
31  cerr << "Incorrect number of arguments provided\n";
32  cerr << "Usage: motion_complete_example.exe <ADDRESS>\n";
33  return GALIL_EXAMPLE_ERROR;
34  }
35 
36  char* address = argv[1]; //Retrieve address from command line
37  sprintf(buf, "%s --subscribe EI", address); //Subscribe to event interrupts
38  e(GOpen(buf, &g)); //Opens a connection at the provided address
39 
40  //Uses interrupts to track when the motion of controller is completed
41  rc = motion_complete(g);
42  }
43  catch (GReturn gr)
44  {
45  GError(gr, buf, G_SMALL_BUFFER); //Get Error Information
46  cout << buf << '\n';
47  if (g)
48  {
49  GSize size = sizeof(buf);
50  GUtility(g, G_UTIL_ERROR_CONTEXT, buf, &size);
51  cout << buf << '\n'; //further context
52  }
53  return GALIL_EXAMPLE_ERROR;
54  }
55 
56  return rc;
57 }
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:92
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:70
GReturn motion_complete(GCon g)
Uses interrupts to track when the motion of controller is completed.
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:459
unsigned int GSize
Size of buffers, etc.
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:87
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:91