| gclib 1.35.5 Communications API for Galil controllers and PLCs |

commands_example.cpp
Go to the documentation of this file.
1
9 #include "examples.h"
10
11 using namespace std;
12
14
18 int main(int argc, char * argv[])
19 {
20 char buf[G_SMALL_BUFFER];
21
22 //var used to refer to a unique connection. A valid connection is nonzero.
23 GCon g = 0;
24
25 try
26 {
27 if (argc != 2) //Invalid number of arguments
28 {
29 cerr << "Incorrect number of arguments provided\n";
30 cerr << "Usage: commands_example.exe <ADDRESS>\n";
31 pause();
32 return GALIL_EXAMPLE_ERROR;
33 }
34
35 char* address = argv[1]; //Retrieve address from command line
36 e(GOpen(address, &g)); //Opens a connection at the provided address
37
38 //Demonstrates various uses of GCommand() and GUtility().
39 commands(g);
40 }
41 catch (GReturn gr)
42 {
43 error(g, gr); //see examples.h for error handling
44 pause();
45 return GALIL_EXAMPLE_ERROR;
46 }
47
48 pause();
49 return GALIL_EXAMPLE_OK;
50 }
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
commands
GReturn commands(GCon g)
Demonstrates various uses of GCommand() and GUtility().
Definition: commands.cpp:16
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