| gclib 1.35.5 Communications API for Galil controllers and PLCs |

message_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
28 try
29 {
30 if (argc != 2) //Invalid number of arguments
31 {
32 cerr << "Incorrect number of arguments provided\n";
33 cerr << "Usage: message_example.exe <ADDRESS>\n";
34 pause();
35 return GALIL_EXAMPLE_ERROR;
36 }
37
38 char* address = argv[1]; //Retrieve address from command line
39 sprintf(buf, "%s --subscribe MG", address);
40 e(GOpen(buf, &g)); //Opens a connection at the provided address
41
42 //Demonstrates how to receive messages from the controller
43 //and detect differences in Trace and crashed code.
44 rc = message(g);
45 }
46 catch (GReturn gr)
47 {
48 error(g, gr); //see examples.h for error handling
49 pause();
50 return GALIL_EXAMPLE_ERROR;
51 }
52
53 pause();
54 return GALIL_EXAMPLE_OK;
55 }
examples.h
GOpen
GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon *g)
Open a connection to a Galil Controller.
GReturn
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:93
G_SMALL_BUFFER
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
Definition: gclib.h:89
GCon
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:94
main
int main(int argc, char *argv[])
Main function for Commands Example.
Definition: commands_example.cpp:18
e
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: examples.h:33
message
GReturn message(GCon g)
Demonstrates how to receive messages from the controller and detect differences in Trace and crashed ...
Definition: message.cpp:14
error
void error(GCon g, GReturn rc)
An example of error handling and debugging information.
Definition: examples.h:40
pause
int pause()
Pauses console apps for a user key stroke.
Definition: examples.h:62