13 #ifndef _CRT_SECURE_NO_WARNINGS
14 #define _CRT_SECURE_NO_WARNINGS
37 str_len = strlen(ver) + 1;
42 ver[str_len - 1] =
' ';
84 #if defined(__linux__) || defined(__APPLE__)
97 #if defined(__linux__) || defined(__APPLE__)
113 if (requests_len == 0 || strlen(requests))
141 sprintf(buf,
"GSetServer: %d", rc);
162 sprintf(buf,
"GServerStatus: %d", rc);
182 sprintf(buf,
"GListServers: %d", rc);
195 unsigned short options = publish | (save << 1);
209 sprintf(buf,
"GPublishServer: %d", rc);
230 sprintf(buf,
"GRemoteConnections: %d", rc);
252 for (i = read - 1; i >= 0; i--)
254 c = trimmed_response[i];
255 if ((c ==
':') || (c ==
'\n') || (c ==
'\r'))
256 trimmed_response[i] = 0;
263 *front = trimmed_response;
267 c = trimmed_response[i++];
302 char pred[] =
"_BGm=0";
305 GSize len = strlen(axes);
307 for (i = 0; i < len; i++)
324 strcat(cmd, predicate);
327 for (; trials != 0; --trials)
349 return GCmd(g,
"DR 0");
361 period_arg = period_ms / dt;
365 if (strstr(buf,
"DMC18"))
366 period_arg = log(period_arg) / log(2.0);
367 else if ((strstr(buf,
"DMC40") != NULL)
368 || (strstr(buf,
"DMC500") != NULL)
369 || (strstr(buf,
"RIO") != NULL))
371 if (period_arg < 2) period_arg = 2;
373 else if ((strstr(buf,
"DMC41") != NULL) || (strstr(buf,
"DMC21") != NULL))
375 if (period_arg < 8) period_arg = 8;
377 else if ((strstr(buf,
"DMC3") != NULL))
379 if (period_arg < 4) period_arg = 4;
383 sprintf(buf,
"DR %d", (
int)period_arg);
391 char* program_buffer;
394 if (!(file = fopen(file_path,
"rb")))
397 fseek(file, 0, SEEK_END);
398 file_size = ftell(file);
404 if (!(program_buffer = malloc(file_size + 1)))
410 if (file_size != fread(program_buffer, 1, file_size, file))
413 free(program_buffer);
416 program_buffer[file_size] = 0;
426 if (file_size) free(program_buffer);
434 char* program_buffer;
437 if (!(file = fopen(file_path,
"wb")))
440 if (!(program_buffer = malloc(
MAXPROG)))
448 file_size = strlen(program_buffer);
449 if (file_size != fwrite(program_buffer, 1, file_size, file))
454 free(program_buffer);
466 error_message = G_NO_ERROR_S;
470 error_message = G_GCLIB_ERROR_S;
474 error_message = G_GCLIB_UTILITY_ERROR_S;
478 error_message = G_GCLIB_UTILITY_IP_TAKEN_S;
482 error_message = G_GCLIB_NON_BLOCKING_READ_EMPTY_S;
486 error_message = G_TIMEOUT_S;
490 error_message = G_OPEN_ERROR_S;
494 error_message = G_ALREADY_OPEN_S;
498 error_message = G_READ_ERROR_S;
502 error_message = G_WRITE_ERROR_S;
506 error_message = G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND_S;
510 error_message = G_DATA_RECORD_ERROR_S;
514 error_message = G_UNSUPPORTED_FUNCTION_S;
518 error_message = G_BAD_ADDRESS_S;
522 error_message = G_BAD_FIRMWARE_LOAD_S;
526 error_message = G_FIRMWARE_LOAD_NOT_SUPPORTED_S;
530 error_message = G_ARRAY_NOT_DIMENSIONED_S;
534 error_message = G_CONNECTION_NOT_ESTABLISHED_S;
538 error_message = G_ILLEGAL_DATA_IN_PROGRAM_S;
542 error_message = G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT_S;
546 error_message = G_INVALID_PREPROCESSOR_OPTIONS_S;
550 error_message = G_BAD_RESPONSE_QUESTION_MARK_S;
554 error_message = G_BAD_VALUE_RANGE_S;
558 error_message = G_BAD_FULL_MEMORY_S;
562 error_message = G_BAD_LOST_DATA_S;
566 error_message = G_BAD_FILE_S;
570 error_message = G_GCAPS_OPEN_ERROR_S;
574 error_message = G_GCAPS_SUBSCRIPTION_ERROR_S;
578 error_message =
"internal error";
582 strncpy(
error, error_message, error_len);
583 error[error_len - 1] = 0;
587 void LogMsg(
const char* msg)
590 struct tm * timeinfo;
593 timeinfo = localtime(&rawtime);
594 char* time_string = asctime(timeinfo);
597 const char* filename =
"C:/ProgramData/Galil/gcaps/gclib_mdns_log.txt";
599 const char* filename =
"/var/tmp/gclib_mdns_log.txt";
603 logfile = fopen(filename,
"a");
604 fprintf(logfile,
"%s | %s", msg, time_string);
GCLIB_DLL_EXPORTED GReturn GCALL GMotionComplete(GCon g, GCStringIn axes)
Blocking call that returns once all axes specified have completed their motion.
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 GPublishServer(GCStringIn name, GOption publish, GOption save)
Uses GUtility(), G_UTIL_GCAPS_PUBLISH_SERVER to publish local gcaps server to the local network.
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.
GCLIB_DLL_EXPORTED 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 ...
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownloadFile(GCon g, GCStringIn file_path, GCStringIn preprocessor)
Program download from file.
GCLIB_DLL_EXPORTED 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...
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 GListServers(GCStringOut servers, GSize servers_len)
Uses GUtility(), G_UTIL_GCAPS_LIST_SERVERS to provide a list of all available gcaps services on the l...
GCLIB_DLL_EXPORTED 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...
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.
GCLIB_DLL_EXPORTED GReturn GCALL GRemoteConnections(GCStringOut connections, GSize connections_length)
Uses GUtility(), G_UTIL_GCAPS_REMOTE_CONNECTIONS to get a list of remote addresses connected to the l...
GCLIB_DLL_EXPORTED GReturn GCALL GProgramUpload(GCon g, GBufOut buffer, GSize buffer_len)
Uploads a program from the controller's program buffer.
GCLIB_DLL_EXPORTED void GCALL GError(GReturn rc, GCStringOut error, GSize error_len)
Provides a human-readable description string for return codes.
GCLIB_DLL_EXPORTED GReturn GCALL GProgramUploadFile(GCon g, GCStringIn file_path)
Program upload to file.
GCLIB_DLL_EXPORTED GReturn GCALL GRecordRate(GCon g, double period_ms)
Sets the asynchronous data record to a user-specified period via DR.
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 GServerStatus(GCStringOut status, GSize status_len)
Uses GUtility(), G_UTIL_GCAPS_SERVER_STATUS to get information on the local server name and if it is ...
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownload(GCon g, GCStringIn program, GCStringIn preprocessor)
Downloads a program to the controller's program buffer.
GCLIB_DLL_EXPORTED GReturn GCALL GWaitForBool(GCon g, GCStringIn predicate, int trials)
Blocking call that returns when the controller evaluates the predicate as true.
GCLIB_DLL_EXPORTED GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
Uses GUtility() and G_UTIL_INFO to provide a useful connection string.
GCLIB_DLL_EXPORTED GReturn GCALL GSetServer(GCStringIn server_name)
Uses GUtility(), G_UTIL_GCAPS_SET_SERVER to set the new active server.
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.
GCLIB_DLL_EXPORTED 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...
#define G_BAD_RESPONSE_QUESTION_MARK
Operation received a ?, indicating controller has a TC error.
#define G_WRITE_ERROR
Device write failed. E.G. Socket was closed by remote host. See G_UTIL_GCAPS_KEEPALIVE.
#define G_DATA_RECORD_ERROR
Data record error, e.g. DR attempted on serial connection.
#define G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND
GCommand() was called with an illegal command, e.g. ED, DL or QD.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
#define G_BAD_VALUE_RANGE
Bad value or range, e.g. GCon g variable passed to function was bad.
#define G_UTIL_INFO
GUtility(), get a connection info string.
int GOption
Option integer for various formatting, etc.
#define G_BAD_FIRMWARE_LOAD
Bad firmware upgrade.
#define POLLINGINTERVAL
Interval, in milliseconds, for polling commands, e.g. GWaitForBool().
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
#define G_ALREADY_OPEN
Serial or PCI file has a flock placed on it, presumably by another gclib connection.
#define G_GCLIB_ERROR
General library error. Indicates internal API caught an unexpected error. Contact Galil support if th...
#define G_GCAPS_OPEN_ERROR
gcaps connection couldn't open. Server is not running or is not reachable.
#define G_OPEN_ERROR
Device could not be opened. E.G. Serial port or PCI device already open.
#define G_NO_ERROR
Return value if function succeeded.
#define G_INVALID_PREPROCESSOR_OPTIONS
GProgramDownload was called with a bad preprocessor directive.
#define G_UTIL_GCAPS_IPREQUEST
GUtility(), get a list of hardware requesting IPs from the gcaps server.
#define G_UTIL_GCAPS_PUBLISH_SERVER
GUtility(), make local gcaps server discoverable by other gcaps servers on the local network.
#define G_BAD_FULL_MEMORY
Not enough memory for an operation, e.g. all connections allowed for a process already taken.
unsigned int GSize
Size of buffers, etc.
#define GCALL
Specify calling convention for Windows.
#define G_UTIL_PING
GUtility(), uses ICMP ping to determine if an IP address is reachable and assigned.
#define G_UTIL_VERSION
GUtility(), get a library version string.
#define G_UTIL_GCAPS_PING
GUtility(), uses ICMP ping to determine if an IP address is reachable and assigned....
#define G_UTIL_IPREQUEST
GUtility(), get a list of hardware requesting IPs.
#define G_ARRAY_NOT_DIMENSIONED
Array operation was called on an array that was not in the controller's array table,...
#define MAXPROG
Maximum size for a program.
#define G_UTIL_GCAPS_SERVER_STATUS
GUtility(), get information on the local server's name and if it is published to the local network.
#define G_UTIL_ASSIGN
GUtility(), assign IP addresses over the network.
#define G_UTIL_TIMEOUT_OVERRIDE
GUtility(), read/write access to timeout override.
#define G_FIRMWARE_LOAD_NOT_SUPPORTED
Firmware is not supported on this bus, e.g. Ethernet for the DMC-21x3 series.
#define G_UTIL_GCAPS_ADDRESSES
GUtility(), get a list of available connections from the gcaps server.
#define G_UTIL_ADDRESSES
GUtility(), get a list of available connections.
#define G_BAD_ADDRESS
Bad address.
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
#define G_GCAPS_SUBSCRIPTION_ERROR
GMessage(), GRecord(), GInterrupt() called on a connection without –subscribe switch.
#define G_UTIL_GCAPS_ASSIGN
GUtility(), assign IP addresses over the network from the gcaps server.
#define G_CONNECTION_NOT_ESTABLISHED
Function was called with no connection.
#define G_GCLIB_UTILITY_ERROR
An invalid request value was specified to GUtility.
#define G_UTIL_SLEEP
GUtility(), specify an interval to sleep.
#define G_UNSUPPORTED_FUNCTION
Function cannot be called on this bus. E.G. GInterrupt() on serial.
#define G_UTIL_GCAPS_SET_SERVER
GUtility(), set the new active gcaps server.
#define G_BAD_FILE
Bad file path, bad file contents, or bad write.
#define G_GCLIB_POLLING_FAILED
GWaitForBool out of polling trials.
#define G_READ_ERROR
Device read failed. E.G. Socket was closed by remote host. See G_UTIL_GCAPS_KEEPALIVE.
#define G_BAD_LOST_DATA
Lost data, e.g. GCommand() response buffer was too small for the controller's response.
#define G_UTIL_GCAPS_LIST_SERVERS
GUtility(), get a list of all available gcaps servers on the local network.
#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 ...
char * GCStringOut
C-string output from the library. Implies null-termination.
const char * GCStringIn
C-string input to the library. Implies null-termination.
#define G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT
Program preprocessor could not compress the program within the user's constraints.
#define G_GCLIB_UTILITY_IP_TAKEN
The IP cannot be assigned because ping returned a reply.
#define G_UTIL_GCAPS_VERSION
GUtility(), get the version of the gcaps server.
#define G_TIMEOUT
Operation timed out. Timeout is set by the –timeout option in GOpen() and can be overriden by GSettin...
#define G_UTIL_GCAPS_REMOTE_CONNECTIONS
GUtility(), get a list of remote addresses connected to local server.
#define G_ILLEGAL_DATA_IN_PROGRAM
Data to download not valid, e.g. \ in data.
#define G_LINE_BUFFER
For writes, via command interpreter, to the Galil.
void error(GCon g, GReturn rc)
An example of error handling and debugging information.