gclib examples  0
Example Projects for the Communications API for Galil controllers and PLCs
message_example.cpp
Go to the documentation of this file.
1 
38 #include "examples.h"
39 
40 #include <iostream> //std::cout
41 using namespace std;
42 
44 
48 int main(int argc, char * argv[])
49 {
50  GReturn rc = GALIL_EXAMPLE_OK;
51  char buf[G_SMALL_BUFFER];
52 
53  //var used to refer to a unique connection. A valid connection is nonzero.
54  GCon g = 0;
55 
56  try
57  {
58  if (argc != 2) //Invalid number of arguments
59  {
60  cerr << "Incorrect number of arguments provided\n";
61  cerr << "Usage: message_example.exe <ADDRESS>\n";
62  return GALIL_EXAMPLE_ERROR;
63  }
64 
65  char* address = argv[1]; //Retrieve address from command line
66  sprintf(buf, "%s --subscribe MG", address);
67  e(GOpen(buf, &g)); //Opens a connection at the provided address
68 
69  //Demonstrates how to receive messages from the controller
70  //and detect differences in Trace and crashed code.
71  rc = message(g);
72  }
73  catch (GReturn gr)
74  {
75  GError(gr, buf, G_SMALL_BUFFER); //Get Error Information
76  cout << buf << '\n';
77  if (g)
78  {
79  GSize size = sizeof(buf);
80  GUtility(g, G_UTIL_ERROR_CONTEXT, buf, &size);
81  cout << buf << '\n'; //further context
82  }
83  return GALIL_EXAMPLE_ERROR;
84  }
85 
86  return rc;
87 }
int main(int argc, char *argv[])
Main function for Message Example.
GReturn message(GCon g)
Demonstrates how to receive messages from the controller and detect differences in Trace and crashed ...
Definition: message.cpp:10
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: examples.h:22