| gclib 1.32.6 Communications API for Galil controllers and PLCs |

examples.h
Go to the documentation of this file.
1
13 #ifndef examples_h
14 #define examples_h
15
16 #define _CRT_SECURE_NO_WARNINGS //use traditional C calls like sprintf()
17
18 #include "gclib.h"
19 #include "gclibo.h"
20
21 #include <iostream> //std::cout
22 #include <cstdio> //std::getchar
23
24 #define GALIL_EXAMPLE_OK 0//return code for correct code execution
25 #define GALIL_EXAMPLE_ERROR -100 //return code for error in example code
26
27
29
33 inline void e(GReturn rc)
34 {
35 if (rc != G_NO_ERROR)
36 throw rc;
37 }
38
40 inline void error(GCon g, GReturn rc)
41 {
42 char buf[G_SMALL_BUFFER];
43 GError(rc, buf, G_SMALL_BUFFER); //Get Error Information
44 std::cout << buf << '\n';
45 if (g)
46 {
47 GSize size = sizeof(buf);
48 GUtility(g, G_UTIL_ERROR_CONTEXT, buf, &size);
49
50 if (buf[0])
51 std::cout << buf << '\n'; //further context
52
53 if ((rc == G_BAD_RESPONSE_QUESTION_MARK)
54 && (GCommand(g, "TC1", buf, G_SMALL_BUFFER, 0) == G_NO_ERROR))
55 {
56 std::cout << buf << '\n'; //Error code from controller
57 }
58 }
59 }
60
62 inline int pause()
63 {
64
65 std::cout << "Enter any key to exit..." << std::endl;
66 return std::getchar();
67
68 }
69
71
79 GReturn position_tracking(GCon g, int speed = 5000);
80
82
89 GReturn jog(GCon g);
90
92
100 GReturn vector(GCon g, char* file);
101
103
111 GReturn ip_assigner(char* serial_num, int address);
112
114
121 GReturn commands(GCon g);
122
124
131 GReturn motion_complete(GCon g);
132
134
141 GReturn message(GCon g);
142
144
153 GReturn record_position(GCon g, char* fileA, char* fileB);
154
156
165 GReturn contour(GCon g, char* fileA, char* fileB);
166
168
175 GReturn remote_server(const char* server_name);
176
178
183 GReturn remote_client();
184
185 #endif //examples_h
186
187
gclib.h
gclibo.h
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.
GCommand
GCLIB_DLL_EXPORTED GReturn GCALL GCommand(GCon g, GCStringIn command, GBufOut buffer, GSize buffer_len, GSize *bytes_returned)
Performs a command-and-response transaction on the connection.
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
G_BAD_RESPONSE_QUESTION_MARK
#define G_BAD_RESPONSE_QUESTION_MARK
Operation received a ?, indicating controller has a TC error.
Definition: gclib_errors.h:70
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
G_NO_ERROR
#define G_NO_ERROR
Return value if function succeeded.
Definition: gclib_errors.h:13
GSize
unsigned int GSize
Size of buffers, etc.
Definition: gclib.h:95
GCon
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:94
G_UTIL_ERROR_CONTEXT
#define G_UTIL_ERROR_CONTEXT
GUtility(), provides additional error context, where available.
Definition: gclib.h:70
e
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: examples.h:33
contour
GReturn contour(GCon g, char *fileA, char *fileB)
Record user's training and plays back training through contour mode.
Definition: contour.cpp:20
motion_complete
GReturn motion_complete(GCon g)
Uses interrupts to track when the motion of controller is completed.
Definition: motion_complete.cpp:18
commands
GReturn commands(GCon g)
Demonstrates various uses of GCommand() and GUtility().
Definition: commands.cpp:16
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
message
GReturn message(GCon g)
Demonstrates how to receive messages from the controller and detect differences in Trace and crashed ...
Definition: message.cpp:14
remote_client
GReturn remote_client()
Lists available remote servers and allows connection to remote server.
Definition: remote_client.cpp:89
remote_server
GReturn remote_server(const char *server_name)
Publishes local gcaps server to the network.
Definition: remote_server.cpp:39
ip_assigner
GReturn ip_assigner(char *serial_num, int address)
Assigns controller an IP Adress given a serial number and a 1 byte address.
Definition: ip_assigner.cpp:26
jog
GReturn jog(GCon g)
Puts controller into Jog Mode and accepts user input to adjust the speed.
Definition: jog.cpp:29
vector
GReturn vector(GCon g, char *file)
Puts controller into Vector Mode and accepts a file defining vector points.
Definition: vector.cpp:36
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
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