65 for (i = read - 1; i >= 0; i--)
67 c = trimmed_response[i];
68 if ((c ==
':') || (c ==
'\n') || (c ==
'\r'))
69 trimmed_response[i] = 0;
76 *front = trimmed_response;
80 c = trimmed_response[i++];
117 char cmd[] =
"MG_BGm";
121 GSize len = strlen(axes);
123 for (i = 0; i < len; i++)
146 return GCmd(g,
"DR 0");
158 period_arg = period_ms / dt;
162 if (strstr(buf,
"DMC18"))
163 period_arg = log(period_arg) / log(2.0);
164 else if ((strstr(buf,
"DMC40") != NULL)
165 || (strstr(buf,
"DMC500") != NULL)
166 || (strstr(buf,
"RIO") != NULL))
168 if (period_arg < 2) period_arg = 2;
170 else if ((strstr(buf,
"DMC41") != NULL) || (strstr(buf,
"DMC21") != NULL))
172 if (period_arg < 8) period_arg = 8;
174 else if ((strstr(buf,
"DMC3") != NULL))
176 if (period_arg < 4) period_arg = 4;
180 sprintf(buf,
"DR %d", (
int)period_arg);
188 char* program_buffer;
191 if (!(file = fopen(file_path,
"rb")))
194 fseek(file, 0, SEEK_END);
195 file_size = ftell(file);
201 if (!(program_buffer = malloc(file_size + 1)))
207 if (file_size != fread(program_buffer, 1, file_size, file))
210 free(program_buffer);
213 program_buffer[file_size] = 0;
223 if (file_size) free(program_buffer);
231 char* program_buffer;
234 if (!(file = fopen(file_path,
"wb")))
237 if (!(program_buffer = malloc(MAXPROG)))
245 file_size = strlen(program_buffer);
246 if (file_size != fwrite(program_buffer, 1, file_size, file))
251 free(program_buffer);
263 error_message = G_NO_ERROR_S;
267 error_message = G_GCLIB_ERROR_S;
271 error_message = G_GCLIB_UTILITY_ERROR_S;
274 case G_GCLIB_UTILITY_IP_TAKEN:
275 error_message = G_GCLIB_UTILITY_IP_TAKEN_S;
279 error_message = G_GCLIB_NON_BLOCKING_READ_EMPTY_S;
283 error_message = G_TIMEOUT_S;
287 error_message = G_OPEN_ERROR_S;
291 error_message = G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND_S;
295 error_message = G_DATA_RECORD_ERROR_S;
299 error_message = G_UNSUPPORTED_FUNCTION_S;
303 error_message = G_BAD_ADDRESS_S;
307 error_message = G_FIRMWARE_LOAD_NOT_SUPPORTED_S;
311 error_message = G_ARRAY_NOT_DIMENSIONED_S;
315 error_message = G_ILLEGAL_DATA_IN_PROGRAM_S;
319 error_message = G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT_S;
323 error_message = G_INVALID_PREPROCESSOR_OPTIONS_S;
327 error_message = G_BAD_RESPONSE_QUESTION_MARK_S;
331 error_message = G_BAD_VALUE_RANGE_S;
335 error_message = G_BAD_FULL_MEMORY_S;
339 error_message = G_BAD_LOST_DATA_S;
343 error_message = G_BAD_FILE_S;
347 error_message =
"internal error";
351 strncpy(error, error_message, error_len);
352 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_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 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...
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_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() and G_UTIL_VERSION to provide the library version number.
#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.
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.
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 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.
GReturn GCALL GIpRequests(GCStringOut requests, GSize requests_len)
Provides a list of all Galil controllers requesting IP addresses via BOOT-P or DHCP.
#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.
const char * GCStringIn
C-string input to the library. Implies null-termination.
#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 ...
#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() and G_UTIL_ADDRESSES to provide a listing of all available connection addresses...
GReturn GCALL GAssign(char *ip, char *mac)
Assigns IP address over the Ethernet to a controller at a given MAC address.
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_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.