gclib examples  0
Example Projects for the Communications API for Galil controllers and PLCs
motion_complete_example.cpp
Go to the documentation of this file.
1 
30 #include "examples.h"
31 
32 #include <iostream> //std::cout
33 using namespace std;
34 
36 
40 int main(int argc, char * argv[])
41 {
42  GReturn rc = GALIL_EXAMPLE_OK;
43  char buf[G_SMALL_BUFFER];
44 
45  //var used to refer to a unique connection. A valid connection is nonzero.
46  GCon g = 0;
47  try
48  {
49  if (argc != 2) //Invalid number of arguments
50  {
51  cerr << "Incorrect number of arguments provided\n";
52  cerr << "Usage: motion_complete_example.exe <ADDRESS>\n";
53  return GALIL_EXAMPLE_ERROR;
54  }
55 
56  char* address = argv[1]; //Retrieve address from command line
57  sprintf(buf, "%s --subscribe EI", address); //Subscribe to event interrupts
58  e(GOpen(buf, &g)); //Opens a connection at the provided address
59 
60  //Uses interrupts to track when the motion of controller is completed
61  rc = motion_complete(g);
62  }
63  catch (GReturn gr)
64  {
65  GError(gr, buf, G_SMALL_BUFFER); //Get Error Information
66  cout << buf << '\n';
67  if (g)
68  {
69  GSize size = sizeof(buf);
70  GUtility(g, G_UTIL_ERROR_CONTEXT, buf, &size);
71  cout << buf << '\n'; //further context
72  }
73  return GALIL_EXAMPLE_ERROR;
74  }
75 
76  return rc;
77 }
GReturn motion_complete(GCon g)
Uses interrupts to track when the motion of controller is completed.
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: examples.h:22
int main(int argc, char *argv[])
Main Function for Motion Complete Example.