| gclib 528 Communications API for Galil controllers and PLCs |

gclibo.c
Go to the documentation of this file.
1
11 #include "gclibo.h"
12
13 #ifndef _CRT_SECURE_NO_WARNINGS
14 #define _CRT_SECURE_NO_WARNINGS //use traditional C calls like strncpy()
15 #endif
16
17 #include <stdlib.h> //atoi, atof
18 #include <string.h> //strcpy
19 #include <stdio.h> //fopen
20 #include <math.h> //log()
21 #include <time.h>
22
23
24 void GCALL GSleep(unsigned int timeout_ms)
25 {
26 GUtility(0, G_UTIL_SLEEP, &timeout_ms, 0);
27 }
28
29 GReturn GCALL GVersion(GCStringOut ver, GSize ver_len)
30 {
31 int str_len;
32 GReturn rc;
33 if ((rc = GUtility(0, G_UTIL_VERSION, ver, &ver_len)) != G_NO_ERROR)
34 return rc;
35
36 #ifdef G_USE_GCAPS
37 str_len = strlen(ver) + 1;
38 ver_len -= str_len;
39 if (ver_len > 0
40 && GUtility(0, G_UTIL_GCAPS_VERSION, ver + str_len, &ver_len) == G_NO_ERROR)
41 {
42 ver[str_len - 1] = ' '; //add a delimiter
43 }
44 #endif
45
46 return rc;
47 }
48
49 GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
50 {
51 return GUtility(g, G_UTIL_INFO, info, &info_len);
52 }
53
54 GReturn GCALL GAddresses(GCStringOut addresses, GSize addresses_len)
55 {
56 #ifdef G_USE_GCAPS
57 GReturn rc;
58 if (G_NO_ERROR == (rc = GUtility(0, G_UTIL_GCAPS_ADDRESSES, addresses, &addresses_len)))
59 return rc;
60 #endif
61
62 return GUtility(0, G_UTIL_ADDRESSES, addresses, &addresses_len);
63 }
64
65 GReturn GCALL GTimeout(GCon g, short timeout_ms)
66 {
67 return GUtility(g, G_UTIL_TIMEOUT_OVERRIDE, &timeout_ms, 0);
68 }
69
70 GReturn GCALL GAssign(GCStringIn ip, GCStringIn mac)
71 {
72 /*
73 * On Linux and Apple, the IP address is pinged prior to assigning.
74 * On Windows, pinging first can make the arp table stale, and the
75 * IP address unreachable for several seconds. We skip ping so that
76 * we can immediately connect.
77 */
78
79 GReturn rc;
80 int reply = 0; //ping reply is nonzero
81
82 #ifdef G_USE_GCAPS
83
84 #if defined(__linux__) || defined(__APPLE__)
85 GUtility(0, G_UTIL_GCAPS_PING, (void*)ip, &reply); //ping to see if IP address is already taken
86 if (reply)
87 return G_GCLIB_UTILITY_IP_TAKEN;
88 #endif
89
90 if (G_NO_ERROR == (rc = GUtility(0, G_UTIL_GCAPS_ASSIGN, (void*)ip, (void*)mac)))
91 return rc;
92 #endif
93
94 #if defined(__linux__) || defined(__APPLE__)
95 GUtility(0, G_UTIL_PING, (void*)ip, &reply); //ping to see if IP address is already taken
96 if (reply)
97 return G_GCLIB_UTILITY_IP_TAKEN;
98 #endif
99
100 return GUtility(0, G_UTIL_ASSIGN, (void*)ip, (void*)mac);
101 }
102
103 GReturn GCALL GIpRequests(GCStringOut requests, GSize requests_len)
104 {
105 #ifdef G_USE_GCAPS
106 GReturn rc;
107 if (G_NO_ERROR == (rc = GUtility(0, G_UTIL_GCAPS_IPREQUEST, requests, &requests_len)))
108 return rc;
109 #endif
110
111 return GUtility(0, G_UTIL_IPREQUEST, requests, &requests_len);
112 }
113
114 GReturn GCALL GSetServer(GCStringIn server_name)
115 {
116 GReturn rc;
117 #ifdef G_USE_GCAPS
118 rc = GUtility(0, G_UTIL_GCAPS_SET_SERVER, (void*)server_name, 0);
119 #else
120 rc = G_GCAPS_OPEN_ERROR;
121 #endif
122
123 #ifdef GCLIB_LOGGING
124 if (rc != G_NO_ERROR)
125 {
126 char buf[256];
127 sprintf(buf, "GSetServer: %d", rc);
128 LogMsg(buf);
129 }
130 #endif
131
132 return rc;
133 }
134
135 GReturn GCALL GServerStatus(GCStringOut status, GSize status_len)
136 {
137 GReturn rc = G_NO_ERROR;
138 #ifdef G_USE_GCAPS
139 rc = GUtility(0, G_UTIL_GCAPS_SERVER_STATUS, status, &status_len);
140 #else
141 rc = G_GCAPS_OPEN_ERROR;
142 #endif
143
144 #ifdef GCLIB_LOGGING
145 if (rc != G_NO_ERROR)
146 {
147 char buf[256];
148 sprintf(buf, "GServerStatus: %d", rc);
149 LogMsg(buf);
150 }
151 #endif
152 return rc;
153 }
154
155 GReturn GCALL GListServers(GCStringOut servers, GSize servers_len)
156 {
157 GReturn rc;
158 #ifdef G_USE_GCAPS
159 rc = GUtility(0, G_UTIL_GCAPS_LIST_SERVERS, servers, &servers_len);
160 #else
161 rc = G_GCAPS_OPEN_ERROR;
162 #endif
163
164 #ifdef GCLIB_LOGGING
165 if (rc != G_NO_ERROR)
166 {
167 char buf[256];
168 sprintf(buf, "GListServers: %d", rc);
169 LogMsg(buf);
170 }
171 #endif
172 return rc;
173 }
174
175 GReturn GCALL GPublishServer(GCStringIn name, GOption publish, GOption save)
176 {
177 GReturn rc;
178 #ifdef G_USE_GCAPS
179 //bit 0 -> publish = 1, remove = 0
180 //bit 1 -> save = 1, do not save = 0
181 unsigned short options = publish | (save << 1);
182
183 if (G_NO_ERROR == (rc = GUtility(0, G_UTIL_GCAPS_PUBLISH_SERVER, (void*)name, &options)))
184 {
185
186 }
187 #else
188 rc = G_GCAPS_OPEN_ERROR;
189 #endif
190
191 #ifdef GCLIB_LOGGING
192 if (rc != G_NO_ERROR)
193 {
194 char buf[256];
195 sprintf(buf, "GPublishServer: %d", rc);
196 LogMsg(buf);
197 }
198 #endif
199
200 return rc;
201 }
202
203 GReturn GCALL GRemoteConnections(GCStringOut connections, GSize connections_length)
204 {
205 GReturn rc;
206 #ifdef G_USE_GCAPS
207 rc = GUtility(0, G_UTIL_GCAPS_REMOTE_CONNECTIONS, connections, &connections_length);
208 #else
209 rc = G_GCAPS_OPEN_ERROR;
210 #endif
211
212 #ifdef GCLIB_LOGGING
213 if (rc != G_NO_ERROR)
214 {
215 char buf[256];
216 sprintf(buf, "GRemoteConnections: %d", rc);
217 LogMsg(buf);
218 }
219 #endif
220 return rc;
221 }
222
223 GReturn GCALL GCmd(GCon g, GCStringIn command)
224 {
225 char buf[G_SMALL_BUFFER]; //response usually brief, e.g. :
226 return GCommand(g, command, buf, G_SMALL_BUFFER, 0);
227 }
228
229 GReturn GCALL GCmdT(GCon g, GCStringIn command, GCStringOut trimmed_response, GSize response_len, GCStringOut* front)
230 {
231 GSize read;
232 GReturn rc;
233 int i;
234 char c;
235 if ((rc = GCommand(g, command, trimmed_response, response_len, &read)) != G_NO_ERROR)
236 return rc;
237 //if here, the data is already null-terminated, just trim.
238 for (i = read - 1; i >= 0; i--) //read does NOT include null terminator.
239 {
240 c = trimmed_response[i];
241 if ((c == ':') || (c == '\n') || (c == '\r'))
242 trimmed_response[i] = 0; //trim it
243 else
244 break; //we hit non-trimmable data, bail out.
245 }
246
247 if (front) //null to skip "trim" on front.
248 {
249 *front = trimmed_response;
250 i = 0;
251 do
252 {
253 c = trimmed_response[i++];
254 if (c == ' ')
255 (*front)++;
256 else
257 break;
258 } while (1); //exit will be any non-space, including null terminator
259 }
260
261 return G_NO_ERROR;
262 }
263
264 GReturn GCALL GCmdI(GCon g, GCStringIn command, int* value)
265 {
266 char buf[G_SMALL_BUFFER]; //response should be ~19 chars
267 GSize read;
268 GReturn rc;
269 if ((rc = GCommand(g, command, buf, G_SMALL_BUFFER, &read)) != G_NO_ERROR)
270 return rc;
271 *value = atoi(buf);
272 return G_NO_ERROR;
273 }
274
275 GReturn GCALL GCmdD(GCon g, GCStringIn command, double* value)
276 {
277 char buf[G_SMALL_BUFFER]; //response should be ~19 chars
278 GSize read;
279 GReturn rc;
280 if ((rc = GCommand(g, command, buf, G_SMALL_BUFFER, &read)) != G_NO_ERROR)
281 return rc;
282 *value = atof(buf);
283 return G_NO_ERROR;
284 }
285
286 GReturn GCALL GMotionComplete(GCon g, GCStringIn axes)
287 {
288 char pred[] = "_BGm=0"; //predicate for polling the axis' motion status, m is a place holder replaced below.
289 GReturn rc;
290 GSize i = 0; //C, not C++
291 GSize len = strlen(axes);
292
293 for (i = 0; i < len; i++) //iterate through all chars in axes
294 {
295 pred[3] = axes[i]; //set the axis
296 rc = GWaitForBool(g, pred, -1); //poll forever. Change this if a premature exit is desired.
297 if (rc != G_NO_ERROR)
298 return rc;
299 }//axes
300
301 return G_NO_ERROR;
302 }
303
304 GReturn GCALL GWaitForBool(GCon g, GCStringIn predicate, int trials)
305 {
306 char cmd[G_LINE_BUFFER];
307 char buf[G_LINE_BUFFER];
308 int rc;
309 strcpy(cmd, "MG (");
310 strcat(cmd, predicate);
311 strcat(cmd, ")"); //enclose in parenthesis
312
313 for (; trials != 0; --trials) //negative value will poll "forever"
314 {
315 rc = GCommand(g, cmd, buf, G_SMALL_BUFFER, 0); //check the predicate
316 if (rc != G_NO_ERROR)
317 return rc;
318
319 if (atoi(buf)) //nonzero is true, bad atoi returns 0
320 return G_NO_ERROR;
321 else
322 GSleep(POLLINGINTERVAL);
323 }
324 //if we're here, the trials ran out
325 return G_GCLIB_POLLING_FAILED;
326 }
327
328 GReturn GCALL GRecordRate(GCon g, double period_ms)
329 {
330 char buf[G_SMALL_BUFFER];
331 double dt;
332 double period_arg;
333
334 if (period_ms == 0) //turn off
335 return GCmd(g, "DR 0");
336
337 if (GCmdD(g, "TM?", &dt) == G_NO_ERROR)
338 {
339 dt /= 1024.0; //ms per controller sample
340 if (!dt) dt = 1; //don't want to divide by zero below
341 }
342 else
343 {
344 dt = 0.9765625; //RIO doesn't have TM
345 }
346
347 period_arg = period_ms / dt; //data record specified in samples between records
348
349 if (GCmdT(g, "\x12\x16", buf, sizeof(buf), 0) == G_NO_ERROR) //Revision string, ^R^V
350 {
351 if (strstr(buf, "DMC18")) //PCI controller
352 period_arg = log(period_arg) / log(2.0); //PCI DR arg is 2^n.
353 else if ((strstr(buf, "DMC40") != NULL) //4000
354 || (strstr(buf, "DMC500") != NULL) //50000
355 || (strstr(buf, "RIO") != NULL)) // RIO
356 {
357 if (period_arg < 2) period_arg = 2; //lowest non-zero DR
358 }
359 else if ((strstr(buf, "DMC41") != NULL) || (strstr(buf, "DMC21") != NULL)) //4103, 2103
360 {
361 if (period_arg < 8) period_arg = 8; //lowest non-zero DR
362 }
363 else if ((strstr(buf, "DMC3") != NULL)) //30010, 31010
364 {
365 if (period_arg < 4) period_arg = 4; //lowest non-zero DR
366 }
367 }
368
369 sprintf(buf, "DR %d", (int)period_arg);
370 return GCmd(g, buf);
371 }
372
373 GReturn GCALL GProgramDownloadFile(GCon g, GCStringIn file_path, GCStringIn preprocessor)
374 {
375 FILE *file;
376 long file_size;
377 char* program_buffer;
378 GReturn rc = G_NO_ERROR;
379
380 if (!(file = fopen(file_path, "rb"))) //open file for reading, binary mode
381 return G_BAD_FILE;
382
383 fseek(file, 0, SEEK_END); //find end of file
384 file_size = ftell(file); //add one to null terminate below
385 rewind(file);
386
387 if (file_size) //don't malloc 0.
388 {
389
390 if (!(program_buffer = malloc(file_size + 1))) //allocate memory for the data, +1 for null termination below
391 {
392 fclose(file);
393 return G_BAD_FULL_MEMORY;
394 }
395
396 if (file_size != fread(program_buffer, 1, file_size, file))
397 {
398 fclose(file);
399 free(program_buffer); //free memory
400 return G_BAD_FILE;
401 }
402 program_buffer[file_size] = 0; //null terminate, malloc was one byte larger for this
403 }
404 else
405 {
406 program_buffer = ""; //nullstring
407 }
408
409 fclose(file); //done with file, close it
410
411 rc = GProgramDownload(g, program_buffer, preprocessor); //call the gclib downloader
412 if (file_size) free(program_buffer); //free memory
413 return rc;
414 }
415
416 GReturn GCALL GProgramUploadFile(GCon g, GCStringIn file_path)
417 {
418 FILE *file;
419 GReturn rc = G_NO_ERROR;
420 char* program_buffer;
421 long file_size;
422
423 if (!(file = fopen(file_path, "wb"))) //open file for writing, binary mode
424 return G_BAD_FILE;
425
426 if (!(program_buffer = malloc(MAXPROG))) //allocate memory for the data
427 {
428 fclose(file);
429 return G_BAD_FULL_MEMORY;
430 }
431
432 if ((rc = GProgramUpload(g, program_buffer, MAXPROG)) == G_NO_ERROR)
433 {
434 file_size = strlen(program_buffer);
435 if (file_size != fwrite(program_buffer, 1, file_size, file))
436 rc = G_BAD_FILE;
437 }
438
439 fclose(file);
440 free(program_buffer);
441 return rc;
442 }
443
444
445 void GCALL GError(GReturn rc, GCStringOut error, GSize error_len)
446 {
447 char* error_message;
448
449 switch (rc)
450 {
451 case G_NO_ERROR:
452 error_message = G_NO_ERROR_S;
453 break;
454
455 case G_GCLIB_ERROR:
456 error_message = G_GCLIB_ERROR_S;
457 break;
458
459 case G_GCLIB_UTILITY_ERROR:
460 error_message = G_GCLIB_UTILITY_ERROR_S;
461 break;
462
463 case G_GCLIB_UTILITY_IP_TAKEN:
464 error_message = G_GCLIB_UTILITY_IP_TAKEN_S;
465 break;
466
467 case G_GCLIB_NON_BLOCKING_READ_EMPTY:
468 error_message = G_GCLIB_NON_BLOCKING_READ_EMPTY_S;
469 break;
470
471 case G_TIMEOUT:
472 error_message = G_TIMEOUT_S;
473 break;
474
475 case G_OPEN_ERROR:
476 error_message = G_OPEN_ERROR_S;
477 break;
478
479 case G_READ_ERROR:
480 error_message = G_READ_ERROR_S;
481 break;
482
483 case G_WRITE_ERROR:
484 error_message = G_WRITE_ERROR_S;
485 break;
486
487 case G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND:
488 error_message = G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND_S;
489 break;
490
491 case G_DATA_RECORD_ERROR:
492 error_message = G_DATA_RECORD_ERROR_S;
493 break;
494
495 case G_UNSUPPORTED_FUNCTION:
496 error_message = G_UNSUPPORTED_FUNCTION_S;
497 break;
498
499 case G_BAD_ADDRESS:
500 error_message = G_BAD_ADDRESS_S;
501 break;
502
503 case G_BAD_FIRMWARE_LOAD:
504 error_message = G_BAD_FIRMWARE_LOAD_S;
505 break;
506
507 case G_FIRMWARE_LOAD_NOT_SUPPORTED:
508 error_message = G_FIRMWARE_LOAD_NOT_SUPPORTED_S;
509 break;
510
511 case G_ARRAY_NOT_DIMENSIONED:
512 error_message = G_ARRAY_NOT_DIMENSIONED_S;
513 break;
514
515 case G_CONNECTION_NOT_ESTABLISHED:
516 error_message = G_CONNECTION_NOT_ESTABLISHED_S;
517 break;
518
519 case G_ILLEGAL_DATA_IN_PROGRAM:
520 error_message = G_ILLEGAL_DATA_IN_PROGRAM_S;
521 break;
522
523 case G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT:
524 error_message = G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT_S;
525 break;
526
527 case G_INVALID_PREPROCESSOR_OPTIONS:
528 error_message = G_INVALID_PREPROCESSOR_OPTIONS_S;
529 break;
530
531 case G_BAD_RESPONSE_QUESTION_MARK:
532 error_message = G_BAD_RESPONSE_QUESTION_MARK_S;
533 break;
534
535 case G_BAD_VALUE_RANGE:
536 error_message = G_BAD_VALUE_RANGE_S;
537 break;
538
539 case G_BAD_FULL_MEMORY:
540 error_message = G_BAD_FULL_MEMORY_S;
541 break;
542
543 case G_BAD_LOST_DATA:
544 error_message = G_BAD_LOST_DATA_S;
545 break;
546
547 case G_BAD_FILE:
548 error_message = G_BAD_FILE_S;
549 break;
550
551 case G_GCAPS_OPEN_ERROR:
552 error_message = G_GCAPS_OPEN_ERROR_S;
553 break;
554
555 case G_GCAPS_SUBSCRIPTION_ERROR:
556 error_message = G_GCAPS_SUBSCRIPTION_ERROR_S;
557 break;
558
559 default:
560 error_message = "internal error";
561 break;
562 }
563
564 strncpy(error, error_message, error_len);
565 error[error_len - 1] = 0; //ensure null termination
566 }
567
568 #ifdef GCLIB_LOGGING
569 void LogMsg(const char* msg)
570 {
571 time_t rawtime;
572 struct tm * timeinfo;
573
574 time(&rawtime);
575 timeinfo = localtime(&rawtime);
576 char* time_string = asctime(timeinfo);
577
578 #ifdef _WIN32
579 const char* filename = "C:/ProgramData/Galil/gcaps/gclib_mdns_log.txt";
580 #else
581 const char* filename = "/var/tmp/gclib_mdns_log.txt";
582 #endif // _WIN32
583
584 FILE *logfile;
585 logfile = fopen(filename, "a");
586 fprintf(logfile, "%s | %s", msg, time_string);
587 fclose(logfile);
588 }
589 #endif
590
G_UTIL_GCAPS_PUBLISH_SERVER
#define G_UTIL_GCAPS_PUBLISH_SERVER
GUtility(), make local gcaps server discoverable by other gcaps servers on the local network.
Definition: gclib.h:80
G_UTIL_VERSION
#define G_UTIL_VERSION
GUtility(), get a library version string.
Definition: gclib.h:62
G_UTIL_GCAPS_LIST_SERVERS
#define G_UTIL_GCAPS_LIST_SERVERS
GUtility(), get a list of all available gcaps servers on the local network.
Definition: gclib.h:79
G_ARRAY_NOT_DIMENSIONED
#define G_ARRAY_NOT_DIMENSIONED
Array operation was called on an array that was not in the controller's array table,...
Definition: gclib_errors.h:58
G_GCLIB_NON_BLOCKING_READ_EMPTY
#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 ...
Definition: gclib_errors.h:25
G_TIMEOUT
#define G_TIMEOUT
Operation timed out. Timeout is set by the –timeout option in GOpen() and can be overriden by GSettin...
Definition: gclib_errors.h:31
POLLINGINTERVAL
#define POLLINGINTERVAL
Interval, in milliseconds, for polling commands, e.g. GWaitForBool().
Definition: gclibo.h:40
GCmdT
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.
Definition: gclibo.c:229
GRecordRate
GCLIB_DLL_EXPORTED GReturn GCALL GRecordRate(GCon g, double period_ms)
Sets the asynchronous data record to a user-specified period via DR.
Definition: gclibo.c:328
G_BAD_FIRMWARE_LOAD
#define G_BAD_FIRMWARE_LOAD
Bad firmware upgrade.
Definition: gclib_errors.h:88
G_UTIL_ADDRESSES
#define G_UTIL_ADDRESSES
GUtility(), get a list of available connections.
Definition: gclib.h:65
G_WRITE_ERROR
#define G_WRITE_ERROR
Device write failed. E.G. Socket was closed by remote host. See G_UTIL_GCAPS_KEEPALIVE.
Definition: gclib_errors.h:40
GCon
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:92
G_UTIL_GCAPS_SERVER_STATUS
#define G_UTIL_GCAPS_SERVER_STATUS
GUtility(), get information on the local server's name and if it is published to the local network.
Definition: gclib.h:82
G_BAD_VALUE_RANGE
#define G_BAD_VALUE_RANGE
Bad value or range, e.g. GCon g variable passed to function was bad.
Definition: gclib_errors.h:73
GUtility
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.
MAXPROG
#define MAXPROG
Maximum size for a program.
Definition: gclibo.h:38
G_GCLIB_ERROR
#define G_GCLIB_ERROR
General library error. Indicates internal API caught an unexpected error. Contact Galil support if th...
Definition: gclib_errors.h:16
G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND
#define G_COMMAND_CALLED_WITH_ILLEGAL_COMMAND
GCommand() was called with an illegal command, e.g. ED, DL or QD.
Definition: gclib_errors.h:46
G_READ_ERROR
#define G_READ_ERROR
Device read failed. E.G. Socket was closed by remote host. See G_UTIL_GCAPS_KEEPALIVE.
Definition: gclib_errors.h:37
G_GCLIB_UTILITY_IP_TAKEN
#define G_GCLIB_UTILITY_IP_TAKEN
The IP cannot be assigned because ping returned a reply.
Definition: gclib_errors.h:22
G_BAD_RESPONSE_QUESTION_MARK
#define G_BAD_RESPONSE_QUESTION_MARK
Operation received a ?, indicating controller has a TC error.
Definition: gclib_errors.h:70
G_UTIL_ASSIGN
#define G_UTIL_ASSIGN
GUtility(), assign IP addresses via Boot-P reply.
Definition: gclib.h:67
G_BAD_FILE
#define G_BAD_FILE
Bad file path, bad file contents, or bad write.
Definition: gclib_errors.h:82
G_BAD_FULL_MEMORY
#define G_BAD_FULL_MEMORY
Not enough memory for an operation, e.g. all connections allowed for a process already taken.
Definition: gclib_errors.h:76
G_GCAPS_SUBSCRIPTION_ERROR
#define G_GCAPS_SUBSCRIPTION_ERROR
GMessage(), GRecord(), GInterrupt() called on a connection without –subscribe switch.
Definition: gclib_errors.h:94
GError
GCLIB_DLL_EXPORTED void GCALL GError(GReturn rc, GCStringOut error, GSize error_len)
Provides a human-readable description string for return codes.
Definition: gclibo.c:445
GVersion
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...
Definition: gclibo.c:29
GWaitForBool
GCLIB_DLL_EXPORTED GReturn GCALL GWaitForBool(GCon g, GCStringIn predicate, int trials)
Blocking call that returns when the controller evaluates the predicate as true.
Definition: gclibo.c:304
G_OPEN_ERROR
#define G_OPEN_ERROR
Device could not be opened. E.G. Serial port or PCI device already open.
Definition: gclib_errors.h:34
GCommand
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.
G_UTIL_INFO
#define G_UTIL_INFO
GUtility(), get a connection info string.
Definition: gclib.h:63
GSetServer
GCLIB_DLL_EXPORTED GReturn GCALL GSetServer(GCStringIn server_name)
Uses GUtility(), G_UTIL_GCAPS_SET_SERVER to set the new active server.
Definition: gclibo.c:114
GCStringIn
const char * GCStringIn
C-string input to the library. Implies null-termination.
Definition: gclib.h:96
G_UTIL_GCAPS_IPREQUEST
#define G_UTIL_GCAPS_IPREQUEST
GUtility(), get a list of hardware requesting IPs from the gcaps server.
Definition: gclib.h:76
GInfo
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.
Definition: gclibo.c:49
G_BAD_ADDRESS
#define G_BAD_ADDRESS
Bad address.
Definition: gclib_errors.h:85
GProgramDownload
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownload(GCon g, GCStringIn program, GCStringIn preprocessor)
Downloads a program to the controller's program buffer.
GIpRequests
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...
Definition: gclibo.c:103
GServerStatus
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 ...
Definition: gclibo.c:135
GCALL
#define GCALL
Specify calling convention for Windows.
Definition: gclib.h:38
G_DATA_RECORD_ERROR
#define G_DATA_RECORD_ERROR
Data record error, e.g. DR attempted on serial connection.
Definition: gclib_errors.h:49
G_UTIL_GCAPS_ADDRESSES
#define G_UTIL_GCAPS_ADDRESSES
GUtility(), get a list of available connections from the gcaps server.
Definition: gclib.h:75
GPublishServer
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.
Definition: gclibo.c:175
G_CONNECTION_NOT_ESTABLISHED
#define G_CONNECTION_NOT_ESTABLISHED
Function was called with no connection.
Definition: gclib_errors.h:61
G_NO_ERROR
#define G_NO_ERROR
Return value if function succeeded.
Definition: gclib_errors.h:13
GSize
unsigned int GSize
Size of buffers, etc.
Definition: gclib.h:93
GTimeout
GCLIB_DLL_EXPORTED GReturn GCALL GTimeout(GCon g, short timeout_ms)
Uses GUtility() and G_UTIL_TIMEOUT_OVERRIDE to set the library timeout.
Definition: gclibo.c:65
GOption
int GOption
Option integer for various formatting, etc.
Definition: gclib.h:94
GCmdI
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.
Definition: gclibo.c:264
GAddresses
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...
Definition: gclibo.c:54
G_UTIL_GCAPS_PING
#define G_UTIL_GCAPS_PING
GUtility(), uses ICMP ping to determine if an IP address is reachable and assigned....
Definition: gclib.h:78
G_UTIL_GCAPS_VERSION
#define G_UTIL_GCAPS_VERSION
GUtility(), get the version of the gcaps server.
Definition: gclib.h:73
GCStringOut
char * GCStringOut
C-string output from the library. Implies null-termination.
Definition: gclib.h:95
GMotionComplete
GCLIB_DLL_EXPORTED GReturn GCALL GMotionComplete(GCon g, GCStringIn axes)
Blocking call that returns once all axes specified have completed their motion.
Definition: gclibo.c:286
G_UTIL_TIMEOUT_OVERRIDE
#define G_UTIL_TIMEOUT_OVERRIDE
GUtility(), read/write access to timeout override.
Definition: gclib.h:60
G_UTIL_PING
#define G_UTIL_PING
GUtility(), uses ICMP ping to determine if an IP address is reachable and assigned.
Definition: gclib.h:69
G_UNSUPPORTED_FUNCTION
#define G_UNSUPPORTED_FUNCTION
Function cannot be called on this bus. E.G. GInterrupt() on serial.
Definition: gclib_errors.h:52
G_GCAPS_OPEN_ERROR
#define G_GCAPS_OPEN_ERROR
gcaps connection couldn't open. Server is not running or is not reachable.
Definition: gclib_errors.h:91
G_UTIL_SLEEP
#define G_UTIL_SLEEP
GUtility(), specify an interval to sleep.
Definition: gclib.h:64
G_GCLIB_UTILITY_ERROR
#define G_GCLIB_UTILITY_ERROR
An invalid request value was specified to GUtility.
Definition: gclib_errors.h:19
G_UTIL_IPREQUEST
#define G_UTIL_IPREQUEST
GUtility(), get a list of hardware requesting IPs.
Definition: gclib.h:66
GSleep
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...
Definition: gclibo.c:24
G_LINE_BUFFER
#define G_LINE_BUFFER
For writes, via command interpreter, to the Galil.
Definition: gclib.h:89
G_SMALL_BUFFER
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
Definition: gclib.h:87
GRemoteConnections
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...
Definition: gclibo.c:203
G_INVALID_PREPROCESSOR_OPTIONS
#define G_INVALID_PREPROCESSOR_OPTIONS
GProgramDownload was called with a bad preprocessor directive.
Definition: gclib_errors.h:43
GCmdD
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.
Definition: gclibo.c:275
GCmd
GCLIB_DLL_EXPORTED GReturn GCALL GCmd(GCon g, GCStringIn command)
Wrapper around GCommand for use when the return value is not desired.
Definition: gclibo.c:223
GProgramUploadFile
GCLIB_DLL_EXPORTED GReturn GCALL GProgramUploadFile(GCon g, GCStringIn file_path)
Program upload to file.
Definition: gclibo.c:416
G_GCLIB_POLLING_FAILED
#define G_GCLIB_POLLING_FAILED
GWaitForBool out of polling trials.
Definition: gclib_errors.h:28
G_UTIL_GCAPS_ASSIGN
#define G_UTIL_GCAPS_ASSIGN
GUtility(), assign IP addresses via Boot-P reply from the gcaps server.
Definition: gclib.h:77
G_UTIL_GCAPS_REMOTE_CONNECTIONS
#define G_UTIL_GCAPS_REMOTE_CONNECTIONS
GUtility(), get a list of remote addresses connected to local server.
Definition: gclib.h:83
G_ILLEGAL_DATA_IN_PROGRAM
#define G_ILLEGAL_DATA_IN_PROGRAM
Data to download not valid, e.g. \ in data.
Definition: gclib_errors.h:64
G_UTIL_GCAPS_SET_SERVER
#define G_UTIL_GCAPS_SET_SERVER
GUtility(), set the new active gcaps server.
Definition: gclib.h:81
G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT
#define G_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT
Program preprocessor could not compress the program within the user's constraints.
Definition: gclib_errors.h:67
G_FIRMWARE_LOAD_NOT_SUPPORTED
#define G_FIRMWARE_LOAD_NOT_SUPPORTED
Firmware is not supported on this bus, e.g. Ethernet for the DMC-21x3 series.
Definition: gclib_errors.h:55
G_BAD_LOST_DATA
#define G_BAD_LOST_DATA
Lost data, e.g. GCommand() response buffer was too small for the controller's response.
Definition: gclib_errors.h:79
gclibo.h
GReturn
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:91
GProgramUpload
GCLIB_DLL_EXPORTED GReturn GCALL GProgramUpload(GCon g, GBufOut buffer, GSize buffer_len)
Uploads a program from the controller's program buffer.
GListServers
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...
Definition: gclibo.c:155
GAssign
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 ...
Definition: gclibo.c:70
GProgramDownloadFile
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownloadFile(GCon g, GCStringIn file_path, GCStringIn preprocessor)
Program download from file.
Definition: gclibo.c:373