| gclib 2.0.7 Communications API for Galil controllers and PLCs |

x_arrays.cpp
Go to the documentation of this file.
1
7 #include "x_examples.h"
8
9 int x_arrays(GCon g)
10 {
11 cout << "\n************************************************************************\n";
12 cout << "Example GArrayDownload(), GArrayUploadFile()\n";
13 cout << "GArrayDownloadFile(), and GArrayUpload usage\n";
14 cout << "************************************************************************\n";
15
16 char buf[1024]; //traffic buffer
17
18 //-------------------------------------------------------------------------
19 //Preparing the array table
20 x_e(GCmd(g, "DA *[]")); //deallocate all arrays
21 x_e(GCmd(g, "DM A[10]")); //allocate A[] array
22
23 //-------------------------------------------------------------------------
24 //download full array
25 x_e(GArrayDownload(g, "A", G_BOUNDS, G_BOUNDS, "2,4,6,8,10,12,14,16,18,20"));
26
27 //-------------------------------------------------------------------------
28 //upload full array
29 x_e(GArrayUpload(g, "A", G_BOUNDS, G_BOUNDS, G_COMMA, buf, sizeof(buf)));
30 cout << buf << "\n\n";
31
32 //-------------------------------------------------------------------------
33 //download subset
34 x_e(GArrayDownload(g, "A", 1, 3, "1,3,5"));
35
36 //-------------------------------------------------------------------------
37 //upload full array
38 x_e(GArrayUpload(g, "A", G_BOUNDS, G_BOUNDS, G_COMMA, buf, sizeof(buf)));
39 cout << buf << "\n\n";
40
41 //-------------------------------------------------------------------------
42 //upload subset
43 x_e(GArrayUpload(g, "A", 2, 4, G_COMMA, buf, sizeof(buf)));
44 cout << buf << '\n';
45
46 //-------------------------------------------------------------------------
47 //upload to file
48 x_e(GArrayUploadFile(g, "array.csv", 0));
49
50 //-------------------------------------------------------------------------
51 //Download from file
52 x_e(GArrayDownloadFile(g, "array.csv"));
53
54 //-------------------------------------------------------------------------
55 //upload full array
56 x_e(GArrayUpload(g, "A", G_BOUNDS, G_BOUNDS, G_COMMA, buf, sizeof(buf)));
57 cout << buf << "\n\n";
58
59 return GALIL_EXAMPLE_OK;
60 }
GArrayDownloadFile
GCLIB_DLL_EXPORTED GReturn GCALL GArrayDownloadFile(GCon g, GCStringIn file_path)
Array download from file.
Definition: arrays.c:380
GArrayUploadFile
GCLIB_DLL_EXPORTED GReturn GCALL GArrayUploadFile(GCon g, GCStringIn file_path, GCStringIn names)
Array upload to file.
Definition: arrays.c:408
GArrayDownload
GCLIB_DLL_EXPORTED GReturn GCALL GArrayDownload(GCon g, const GCStringIn array_name, GOption first, GOption last, GCStringIn buffer)
Downloads array data to a pre-dimensioned array in the controller's array table.
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:237
GArrayUpload
GCLIB_DLL_EXPORTED GReturn GCALL GArrayUpload(GCon g, const GCStringIn array_name, GOption first, GOption last, GOption delim, GBufOut buffer, GSize buffer_len)
Uploads array data from the controller's array table.
G_COMMA
#define G_COMMA
For GArrayUpload(), use this value in the delim field to delimit with commas.
Definition: gclib.h:54
G_BOUNDS
#define G_BOUNDS
For functions that take range options, e.g. GArrayUpload(), use this value for full range.
Definition: gclib.h:52
GCon
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:94
x_arrays
int x_arrays(GCon g)
Example GArrayDownload() and GArrayUpload() usage.
Definition: x_arrays.cpp:9
x_e
void x_e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: x_examples.h:30
x_examples.h