9 #ifndef _CRT_SECURE_NO_WARNINGS 10 #define _CRT_SECURE_NO_WARNINGS //use traditional C calls like strncpy() 33 str_len = strlen(ver) + 1;
38 ver[str_len - 1] =
' ';
80 #if defined(__linux__) || defined(__APPLE__) 90 #if defined(__linux__) || defined(__APPLE__) 125 for (i = read - 1; i >= 0; i--)
127 c = trimmed_response[i];
128 if ((c ==
':') || (c ==
'\n') || (c ==
'\r'))
129 trimmed_response[i] = 0;
136 *front = trimmed_response;
140 c = trimmed_response[i++];
177 char cmd[] =
"MG_BGm";
181 GSize len = strlen(axes);
183 for (i = 0; i < len; i++)
206 return GCmd(g,
"DR 0");
218 period_arg = period_ms / dt;
222 if (strstr(buf,
"DMC18"))
223 period_arg = log(period_arg) / log(2.0);
224 else if ((strstr(buf,
"DMC40") != NULL)
225 || (strstr(buf,
"DMC500") != NULL)
226 || (strstr(buf,
"RIO") != NULL))
228 if (period_arg < 2) period_arg = 2;
230 else if ((strstr(buf,
"DMC41") != NULL) || (strstr(buf,
"DMC21") != NULL))
232 if (period_arg < 8) period_arg = 8;
234 else if ((strstr(buf,
"DMC3") != NULL))
236 if (period_arg < 4) period_arg = 4;
240 sprintf(buf,
"DR %d", (
int)period_arg);
248 char* program_buffer;
251 if (!(file = fopen(file_path,
"rb")))
254 fseek(file, 0, SEEK_END);
255 file_size = ftell(file);
261 if (!(program_buffer = malloc(file_size + 1)))
267 if (file_size != fread(program_buffer, 1, file_size, file))
270 free(program_buffer);
273 program_buffer[file_size] = 0;
283 if (file_size) free(program_buffer);
291 char* program_buffer;
294 if (!(file = fopen(file_path,
"wb")))
297 if (!(program_buffer = malloc(
MAXPROG)))
305 file_size = strlen(program_buffer);
306 if (file_size != fwrite(program_buffer, 1, file_size, file))
311 free(program_buffer);
323 error_message = G_NO_ERROR_S;
327 error_message = G_GCLIB_ERROR_S;
331 error_message = G_GCLIB_UTILITY_ERROR_S;
335 error_message = G_GCLIB_UTILITY_IP_TAKEN_S;
339 error_message = G_GCLIB_NON_BLOCKING_READ_EMPTY_S;
343 error_message = G_TIMEOUT_S;
347 error_message = G_OPEN_ERROR_S;
351 error_message = G_READ_ERROR_S;
355 error_message = G_WRITE_ERROR_S;
359 error_message = G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND_S;
363 error_message = G_DATA_RECORD_ERROR_S;
367 error_message = G_UNSUPPORTED_FUNCTION_S;
371 error_message = G_BAD_ADDRESS_S;
375 error_message = G_BAD_FIRMWARE_LOAD_S;
379 error_message = G_FIRMWARE_LOAD_NOT_SUPPORTED_S;
383 error_message = G_ARRAY_NOT_DIMENSIONED_S;
387 error_message = G_ILLEGAL_DATA_IN_PROGRAM_S;
391 error_message = G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT_S;
395 error_message = G_INVALID_PREPROCESSOR_OPTIONS_S;
399 error_message = G_BAD_RESPONSE_QUESTION_MARK_S;
403 error_message = G_BAD_VALUE_RANGE_S;
407 error_message = G_BAD_FULL_MEMORY_S;
411 error_message = G_BAD_LOST_DATA_S;
415 error_message = G_BAD_FILE_S;
419 error_message = G_GCAPS_OPEN_ERROR_S;
423 error_message = G_GCAPS_SUBSCRIPTION_ERROR_S;
427 error_message =
"internal error";
431 strncpy(error, error_message, error_len);
432 error[error_len - 1] = 0;
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...
#define G_SMALL_BUFFER
Most reads/writes to Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
Uses GUtility() and G_UTIL_INFO to provide a useful connection string.
unsigned int GSize
Size of buffers, etc.
#define G_UTIL_IPREQUEST
GUtility(), get a list of hardware requesting IPs.
#define G_UTIL_GCAPS_IPREQUEST
GUtility(), get a list of hardware requesting IPs from the gcaps server.
#define G_UTIL_PING
GUtility(), uses ICMP ping to determine if an IP address is reachable and assigned.
#define G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT
Program preprocessor could not compress the program within the user's constraints.
GReturn GCALL GCmdT(GCon g, GCStringIn command, GCStringOut trimmed_response, GSize response_len, GCStringOut *front)
Wrapper around GCommand that trims the response.
#define MAXPROG
Maximum size for a program.
#define G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND
GCommand() was called with an illegal command, e.g. ED, DL or QD.
#define G_DATA_RECORD_ERROR
Data record error, e.g. DR attempted on serial connection.
#define G_OPEN_ERROR
Device could not be opened. E.G. Serial port or PCI device already open.
#define G_ILLEGAL_DATA_IN_PROGRAM
Data to download not valid, e.g. \ in data.
GReturn GCALL GProgramUploadFile(GCon g, GCStringIn file_path)
Program upload to file.
#define G_BAD_RESPONSE_QUESTION_MARK
Operation received a ?, indicating controller has a TC error.
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...
#define G_ARRAY_NOT_DIMENSIONED
Array operation was called on an array that was not in the controller's array table, see LA command.
#define G_TIMEOUT
Operation timed out. Timeout is set by the –timeout option in GOpen() and can be overriden by GSetti...
#define G_GCAPS_SUBSCRIPTION_ERROR
GMessage(), GRecord(), GInterrupt() called on a connection without –subscribe switch.
#define POLLINGINTERVAL
Interval, in milliseconds, for polling commands, e.g. GMotionComplete().
GReturn GCALL GCmdI(GCon g, GCStringIn command, int *value)
Wrapper around GCommand that provides the return value of a command parsed into an int...
#define G_GCLIB_UTILITY_ERROR
An invalid request value was specified to GUtility.
GReturn GCALL GMotionComplete(GCon g, GCStringIn axes)
Blocking call that returns once all axes specified have completed their motion.
#define G_UTIL_SLEEP
GUtility(), specify an interval to sleep.
#define G_GCAPS_OPEN_ERROR
gcaps connection couldn't open. Server is not running or is not reachable.
#define G_UNSUPPORTED_FUNCTION
Function cannot be called on this bus. E.G. GInterrupt() on serial.
GReturn GCALL GCmd(GCon g, GCStringIn command)
Wrapper around GCommand for use when the return value is not desired.
#define G_GCLIB_ERROR
General library error. Indicates internal API caught an unexpected error. Contact Galil support if th...
#define G_UTIL_ADDRESSES
GUtility(), get a list of available connections.
GReturn GCALL GVersion(GCStringOut ver, GSize ver_len)
Uses GUtility(), G_UTIL_VERSION and G_UTIL_GCAPS_VERSION to provide the library and gcaps version num...
#define G_UTIL_INFO
GUtility(), get a connection info string.
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen()...
#define G_UTIL_TIMEOUT_OVERRIDE
GUtility(), read/write access to timeout override.
#define G_UTIL_GCAPS_VERSION
GUtility(), get the version of the gcaps server.
void GCALL GError(GReturn rc, GCStringOut error, GSize error_len)
Provides a human-readable description string for return codes.
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownload(GCon g, GCStringIn program, GCStringIn preprocessor)
Downloads a program to the controller's program buffer.
#define G_READ_ERROR
Device read failed. E.G. Socket was closed by remote host. See G_UTIL_GCAPS_KEEPALIVE.
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.
#define G_BAD_FIRMWARE_LOAD
Bad firmware upgrade.
GCLIB_DLL_EXPORTED GReturn GCALL GProgramUpload(GCon g, GBufOut buffer, GSize buffer_len)
Uploads a program from the controller's program buffer.
GReturn GCALL GTimeout(GCon g, short timeout_ms)
Uses GUtility() and G_UTIL_TIMEOUT_OVERRIDE to set the library timeout.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
#define G_GCLIB_UTILITY_IP_TAKEN
The IP cannot be assigned because ping returned a reply.
GReturn GCALL GIpRequests(GCStringOut requests, GSize requests_len)
Uses GUtility(), G_UTIL_GCAPS_IPREQUEST or G_UTIL_IPREQUEST to provide a list of all Galil controller...
#define G_INVALID_PREPROCESSOR_OPTIONS
GProgramDownload was called with a bad preprocessor directive.
#define G_BAD_LOST_DATA
Lost data, e.g. GCommand() response buffer was too small for the controller's response.
#define G_UTIL_VERSION
GUtility(), get a library version string.
#define G_BAD_FULL_MEMORY
Not enough memory for an operation, e.g. all connections allowed for a process already taken...
#define G_BAD_VALUE_RANGE
Bad value or range, e.g. GCon g variable passed to function was bad.
#define G_WRITE_ERROR
Device write failed. E.G. Socket was closed by remote host. See G_UTIL_GCAPS_KEEPALIVE.
const char * GCStringIn
C-string input to the library. Implies null-termination.
#define G_UTIL_GCAPS_PING
GUtility(), uses ICMP ping to determine if an IP address is reachable and assigned. Ping sent from the gcaps server.
#define G_NO_ERROR
Return value if function succeeded.
#define G_GCLIB_NON_BLOCKING_READ_EMPTY
GMessage, GInterrupt, and GRecord can be called with a zero timeout. If there wasn't data waiting in ...
GReturn GCALL GAssign(GCStringIn ip, GCStringIn mac)
Uses GUtility(), G_UTIL_GCAPS_ASSIGN or G_UTIL_ASSIGN to assign an IP address over the Ethernet to a ...
#define G_FIRMWARE_LOAD_NOT_SUPPORTED
Firmware is not supported on this bus, e.g. Ethernet for the DMC-21x3 series.
char * GCStringOut
C-string output from the library. Implies null-termination.
GReturn GCALL GAddresses(GCStringOut addresses, GSize addresses_len)
Uses GUtility(), G_UTIL_GCAPS_ADDRESSES or G_UTIL_ADDRESSES to provide a listing of all available con...
GReturn GCALL GCmdD(GCon g, GCStringIn command, double *value)
Wrapper around GCommand that provides the return value of a command parsed into a double...
#define GCALL
Specify calling convention for Windows.
#define G_UTIL_GCAPS_ADDRESSES
GUtility(), get a list of available connections from the gcaps server.
#define G_BAD_ADDRESS
Bad address.
GReturn GCALL GProgramDownloadFile(GCon g, GCStringIn file_path, GCStringIn preprocessor)
Program download from file.
GReturn GCALL GRecordRate(GCon g, double period_ms)
Sets the asynchronous data record to a user-specified period via DR.
#define G_BAD_FILE
Bad file path, bad file contents, or bad write.
#define G_UTIL_ASSIGN
GUtility(), assign IP addresses via Boot-P reply.
#define G_UTIL_GCAPS_ASSIGN
GUtility(), assign IP addresses via Boot-P reply from the gcaps server.