11 cout <<
"\n************************************************************************\n";
12 cout <<
"Example GRead() and GWrite() usage\n";
13 cout <<
"************************************************************************\n";
17 GSize total_bytes = 0;
31 string program =
"i=0\r#loop\ri=i+1\rWT10\rJP#loop,i<10,\rEN\r";
40 x_e(
GWrite(g, program.c_str(), program.size()));
53 total_bytes += read_bytes;
54 rc =
GRead(g, buf,
sizeof(buf), &read_bytes);
58 cout <<
"\nRead " << total_bytes <<
" byte(s)\n";
59 cout.write(buf, total_bytes);
71 cout <<
"Program test OK.\n";
72 return GALIL_EXAMPLE_OK;
76 cout <<
"Program test failed. " << i <<
"\n";
77 return GALIL_EXAMPLE_ERROR;
GCLIB_DLL_EXPORTED void GCALL GSleep(unsigned int timeout_ms)
Uses GUtility() and G_UTIL_SLEEP to provide a blocking sleep call which can be useful for timing-base...
GCLIB_DLL_EXPORTED GReturn GCALL GTimeout(GCon g, short timeout_ms)
Uses GUtility() and G_UTIL_TIMEOUT_OVERRIDE to set the library timeout.
GCLIB_DLL_EXPORTED GReturn GCALL GWrite(GCon g, GBufIn buffer, GSize buffer_len)
Performs a write on the connection.
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 GRead(GCon g, GBufOut buffer, GSize buffer_len, GSize *bytes_read)
Performs a read on the connection.
GCLIB_DLL_EXPORTED GReturn GCALL GCmd(GCon g, GCStringIn command)
Wrapper around GCommand for use when the return value is not desired.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
#define G_NO_ERROR
Return value if function succeeded.
unsigned int GSize
Size of buffers, etc.
#define G_USE_INITIAL_TIMEOUT
GUtility(), for timeout override. Set G_UTIL_TIMEOUT_OVERRIDE to this value to use initial GOpen() ti...
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
void x_e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
int x_gread_gwrite(GCon g)
Example GRead() and GWrite() usage.