| gclib 556 Communications API for Galil controllers and PLCs |

record_position_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
21 int main(int argc, char * argv[])
22 {
23 GReturn rc = GALIL_EXAMPLE_OK;
24 char buf[G_SMALL_BUFFER];
25
26 //var used to refer to a unique connection. A valid connection is nonzero.
27 GCon g = 0;
28
29 try
30 {
31 if (argc != 4) //Invalid number of arguments
32 {
33 cerr << "Incorrect number of arguments provided\n";
34 cerr << "Usage: record_position_example.exe <ADDRESS> <File A> <File B>\n";
35 return GALIL_EXAMPLE_ERROR;
36 }
37
38 char* fileA = argv[2]; //Retrieve filepath from command line
39 char* fileB = argv[3]; //Retrieve filepath from command line
40 char* address = argv[1]; //Retrieve address from command line
41 e(GOpen(address, &g)); //Opens a connection at the provided address
42
43 //Record user's training and saves to a text file
44 rc = record_position(g, fileA, fileB);
45 }
46 catch (GReturn gr)
47 {
48 GError(gr, buf, G_SMALL_BUFFER); //Get Error Information
49 cout << buf << '\n';
50 if (g)
51 {
52 GSize size = sizeof(buf);
53 GUtility(g, G_UTIL_ERROR_CONTEXT, buf, &size);
54 cout << buf << '\n'; //further context
55 }
56 return GALIL_EXAMPLE_ERROR;
57 }
58 return rc;
59 }
record_position
GReturn record_position(GCon g, char *fileA, char *fileB)
Record user's training and saves to a text file.
Definition: record_position.cpp:20
examples.h
GCon
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:92
GUtility
GCLIB_DLL_EXPORTED GReturn GCALL GUtility(GCon g, GOption request, GMemory memory1, GMemory memory2)
Provides read/write access to driver settings and convenience features based on the request variable.
main
int main(int argc, char *argv[])
Main function for Commands Example.
Definition: commands_example.cpp:20
G_UTIL_ERROR_CONTEXT
#define G_UTIL_ERROR_CONTEXT
GUtility(), provides additional error context, where available.
Definition: gclib.h:70
GOpen
GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon *g)
Open a connection to a Galil Controller.
GError
GCLIB_DLL_EXPORTED void GCALL GError(GReturn rc, GCStringOut error, GSize error_len)
Provides a human-readable description string for return codes.
Definition: gclibo.c:459
GSize
unsigned int GSize
Size of buffers, etc.
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:87
e
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: examples.h:30
GReturn
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:91