gclib examples  0
Example Projects for the Communications API for Galil controllers and PLCs
commands_example.cpp
Go to the documentation of this file.
1 
69 #include "examples.h"
70 
71 #include <iostream> //std::cout
72 
73 using namespace std;
74 
76 /*
77 \link commands_example.cpp \endlink takes one arguments at the command line:
78  an IP Address to a Galil controllers.
79 */
80 int main(int argc, char * argv[])
81 {
82  char buf[G_SMALL_BUFFER];
83 
84  //var used to refer to a unique connection. A valid connection is nonzero.
85  GCon g = 0;
86 
87  try
88  {
89  if (argc != 2) //Invalid number of arguments
90  {
91  cerr << "Incorrect number of arguments provided\n";
92  cerr << "Usage: commands_example.exe <ADDRESS>\n";
93  return GALIL_EXAMPLE_ERROR;
94  }
95 
96  char* address = argv[1]; //Retrieve address from command line
97  e(GOpen(address, &g)); //Opens a connection at the provided address
98 
99  //Demonstrates various uses of GCommand() and GUtility().
100  commands(g);
101  }
102  catch (GReturn gr)
103  {
104  GError(gr, buf, G_SMALL_BUFFER); //Get Error Information
105  cout << buf << '\n';
106  if (g)
107  {
108  GSize size = sizeof(buf);
109  GUtility(g, G_UTIL_ERROR_CONTEXT, buf, &size);
110  cout << buf << '\n'; //further context
111  }
112  return GALIL_EXAMPLE_ERROR;
113  }
114 
115  return GALIL_EXAMPLE_OK;
116 }
GReturn commands(GCon g)
Demonstrates various uses of GCommand() and GUtility().
Definition: commands.cpp:12
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 Commands Example.