23 cout <<
"*****************************************************************************\n";
24 cout <<
"************************** GCmdT() example *****************************\n";
25 cout <<
"*****************************************************************************\n";
26 cout <<
"GCmdT() will return a trimmed response of GCommand()\n";
27 cout <<
"The command 'PR ?,?' will return the relative "
28 "position of the A and B axes\n";
30 cout <<
"<<PR ?,? with GCommand(): " << buf <<
">>\n";
32 cout <<
"<<PR ?,? with GCmdT(): " << buf <<
">>\n";
34 e(
GCmdT(g,
"MG TIME", buf,
sizeof(buf), &front));
35 cout <<
"<<MG TIME with GCmdT() and front trimmed: " << front <<
">>" <<
"\n\n";
37 cout <<
"*****************************************************************************\n";
38 cout <<
"************************** GCmdI() example *****************************\n";
39 cout <<
"*****************************************************************************\n";
40 cout <<
"GCmdI() will return the value of GCommand() parsed as an int\n";
41 cout <<
"The command 'MG _LMS' will return the available "
42 "space in the vector buffer of the S plane.\n";
44 cout <<
"MG _LMS with GCmdT(): " << buf <<
"\n";
45 e(
GCmdI(g,
"MG _LMS", &value));
46 cout <<
"MG _LMS with GCmdI(): " << value <<
"\n\n";
48 cout <<
"*****************************************************************************\n";
49 cout <<
"************************** GCmd() example ******************************\n";
50 cout <<
"*****************************************************************************\n";
51 cout <<
"GCmd() will execute the given command but does not return a value.\n";
52 cout <<
"GCmd is useful for basic operations such as beginning"
53 " motion or setting speed\n";
55 e(
GCmd(g,
"SP 5000"));
56 cout <<
"GCmd(g, \"BG A\");\n";
57 cout <<
"GCmd(g, \"SP 5000\");\n\n";
60 cout <<
"*****************************************************************************\n";
61 cout <<
"************************** GCmdD() example ******************************\n";
62 cout <<
"*****************************************************************************\n";
63 cout <<
"GCmdD() will return the value of GCommand parsed as a double\n";
64 cout <<
"The command 'MG @AN[1]' will return the value of Analog Input 1\n";
65 e(
GCmdD(g,
"MG @AN[1]", &d_value));
66 cout <<
"MG @AN[1] with GCmdD(): " << d_value <<
"\n\n";
68 cout <<
"*****************************************************************************\n";
69 cout <<
"************************ Galil Double Format ***************************\n";
70 cout <<
"*****************************************************************************\n";
71 double d_val = 0.00235;
72 sprintf(buf,
"%.4f", d_val);
73 cout <<
"Galil Controllers expect double values to be formatted to 4 "
75 cout <<
"Unformatted double value: " << d_val <<
"\n";
76 cout <<
"Formatted double value rounded to 4 decimal places: " << buf <<
"\n\n";
78 cout <<
"*****************************************************************************\n";
79 cout <<
"******************* G_UTIL_ERROR_CONTEXT example ***********************\n";
80 cout <<
"*****************************************************************************\n";
82 GSize size =
sizeof(buf);
84 cout <<
"GUtility() with G_UTIL_ERROR_CONTEXT: " << buf <<
"\n";
86 return GALIL_EXAMPLE_OK;
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.
GCLIB_DLL_EXPORTED GReturn GCALL GCmdT(GCon g, GCStringIn command, GCStringOut trimmed_response, GSize response_len, GCStringOut *front)
Wrapper around GCommand that trims the response.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
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.
unsigned int GSize
Size of buffers, etc.
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
#define G_UTIL_ERROR_CONTEXT
GUtility(), provides additional error context, where available.
GCLIB_DLL_EXPORTED GReturn GCALL GCmdI(GCon g, GCStringIn command, int *value)
Wrapper around GCommand that provides the return value of a command parsed into an int.
GCLIB_DLL_EXPORTED GReturn GCALL GCmdD(GCon g, GCStringIn command, double *value)
Wrapper around GCommand that provides the return value of a command parsed into a double.
GCLIB_DLL_EXPORTED GReturn GCALL GCmd(GCon g, GCStringIn command)
Wrapper around GCommand for use when the return value is not desired.
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
GReturn commands(GCon g)
Demonstrates various uses of GCommand() and GUtility().