| gclib 1.35.5 Communications API for Galil controllers and PLCs |

position_tracking_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 < 2 || argc > 3) //Invalid number of arguments
32 {
33 cerr << "Incorrect number of arguments provided\n";
34 cerr << "Usage: position_tracking_example.exe <ADDRESS> <SPEED=5000>\n";
35 pause();
36 return GALIL_EXAMPLE_ERROR;
37 }
38
39 char* address = argv[1]; //Retrieve address from command line
40 e(GOpen(address, &g)); //Opens a connection at the provided address
41
42 if (argc == 3) //Position tracking with custom speed
43 {
44 //Retrieve speed from command line and convert to int
45 char* end;
46 int speed = strtol(argv[2], &end, 10);
47 //If this character is not a null character,
48 //the user did not enter a valid integer for speed
49 if (*end != '\0')
50 {
51 cerr << "An invalid speed was entered. "
52 "Please enter a valid integer for speed.\n"
53 "Usage: position_tracking_example.exe <ADDRESS> <SPEED=5000>\n";
54 pause();
55 return GALIL_EXAMPLE_ERROR;
56 }
57
58 //Puts controller into Position Tracking Mode and accepts user-entered positions
59 rc = position_tracking(g, speed);
60 }
61 else if (argc == 2) //Position tracking with default speed
62 {
63 //Puts controller into Position Tracking Mode and accepts user - entered positions
64 rc = position_tracking(g);
65 }
66 }
67 catch (GReturn gr)
68 {
69 error(g, gr);
70 pause();
71 return GALIL_EXAMPLE_ERROR;
72 }
73
74 pause();
75 return GALIL_EXAMPLE_OK;
76 }
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
position_tracking
GReturn position_tracking(GCon g, int speed=5000)
Puts controller into Position Tracking Mode and accepts user-entered positions.
Definition: position_tracking.cpp:15
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