17 throw string(
"1010 TIMEOUT ERROR. Galil::command() took longer than timeout to return\n");
21 throw string(
"5002 OPEN ERROR. Galil::Galil() failed to open device\n");
25 throw string(
"7020 INVALID COMMAND ERROR. DL, ED, and QD are not allowed from Galil::command()\n");
29 throw string(
"6150 WRONG BUS ERROR. Galil::record(\"DR\") not supported on RS-232. Use Ethernet or Galil::record(\"QR\")\n");
33 throw string(
"6130 WRONG BUS ERROR. Galil::firmwareDownloadFile() isn't allowed via Ethernet. Use RS-232\n");
37 throw string(
"7060 INVALID CHARACTER ERROR. Galil::programDownload() can't download program with backslash \\ character. Use {^92} in MG commands\n");
41 throw string(
"7061 INVALID LENGTH ERROR. Galil::programDownload() can't compress\n");
45 throw string(
"2010 COMMAND ERROR. Galil::command() got ? instead of : response.\n");
49 throw string(
"4000 FILE ERROR. Galil::Galil() failed to open file\n");
53 throw string(
"6000 WRONG BUG ERROR. Function isn't allowed on this bus\n");
72 GError(rc, buf,
sizeof(buf));
73 throw (to_string(rc) +
" GCLIB ERROR. " +
string(buf) +
'\n');
82 if (gcl_address.size() == 0)
83 throw string(
"5005 OPEN ERROR. Null string specified in Galil::Galil()\n");
85 if (gcl_address.find(
"OFFLINE") != string::npos)
86 throw string(
"5001 OPEN ERROR. OFFLINE specified to Galil::Galil()\n");
91 for (i = 0; i < gcl_address.size(); i++)
93 if (gcl_address[i] ==
' ')
96 args.push_back(gcl_address.substr(start, i - start));
102 args.push_back(gcl_address.substr(start, i - start));
109 for (i = 0; i < args.size() - 1; i++)
111 if (args[i] ==
"-p1") address.append(
"--p1 " + args[++i] +
" ");
112 else if (args[i] ==
"-p2") address.append(
"--p2 " + args[++i] +
" ");
113 else if (args[i] ==
"-udp") address.append(
"--command UDP ");
114 else if ((args[i] ==
"-ei") && (args[++i] ==
"0")) ei =
false;
115 else if ((args[i] ==
"-mg") && (args[++i] ==
"0")) mg =
false;
116 else if ((args[i] ==
"-dr") && (args[++i] ==
"0")) dr =
false;
117 else if (args[i] ==
"-t") address.append(
"-t " + args[++i] +
" ");
118 else if (args[i] ==
"-s")
120 address.append(
"-s NONE ");
125 else if (args[i] ==
"-d") ++i;
126 else if (args[i] ==
"-l") ++i;
127 else if (args[i].find(
"COM") != string::npos)
129 address.append(args[i] +
" --baud " + args[i + 1] +
" ");
132 else address.append(args[i] +
" ");
135 if (ei) address.append(
"-s EI ");
136 if (mg) address.append(
"-s MG ");
137 if (dr) address.append(
"-s DR ");
139 address.append(
"-d ");
144 string Galil::libraryVersion()
148 return "Galil2.dll wrapper, gclib " + string(buf);
151 vector<string> Galil::addresses()
153 vector<string> addresses;
160 size_t len = strlen(buf);
161 for (
size_t i = 0; i < len; i++)
165 addresses.push_back(address);
180 address.push_back(buf[i]);
186 Galil::Galil(std::string address)
192 d->InitializeDataRecord();
201 string Galil::connection()
203 ec(
GInfo(d->g, d->tbuf,
sizeof(d->tbuf)));
204 return string(d->tbuf);
207 string Galil::command(
const std::string& command,
const std::string& terminator,
const std::string& ack,
bool trim)
214 ec(
GTimeout(d->g, (
short)timeout_ms));
218 ec(
GCmdT(d->g, command.c_str(), d->tbuf,
sizeof(d->tbuf), &response));
221 ec(
GCommand(d->g, command.c_str(), d->tbuf,
sizeof(d->tbuf), &bytes_read));
226 return string(response);
229 double Galil::commandValue(
const std::string& command)
232 ec(
GTimeout(d->g, (
short)timeout_ms));
233 ec(
GCmdD(d->g, command.c_str(), &value));
238 string Galil::message(
int timeout_ms)
248 t = (short) timeout_ms;
254 rc =
GMessage(d->g, d->tbuf,
sizeof(d->tbuf));
255 }
while(timeout_ms == -1 && rc ==
G_TIMEOUT);
263 return string(d->tbuf);
267 int Galil::interrupt(
int timeout_ms)
269 ec(
GTimeout(d->g, (
short)timeout_ms));
277 string Galil::programUpload()
279 ec(
GTimeout(d->g, (
short)timeout_ms));
282 return string(d->tbuf);
285 void Galil::programDownload(
const std::string& program)
287 ec(
GTimeout(d->g, (
short)timeout_ms));
292 void Galil::programUploadFile(
const std::string& file)
294 ec(
GTimeout(d->g, (
short)timeout_ms));
299 void Galil::programDownloadFile(
const std::string& file)
301 ec(
GTimeout(d->g, (
short)timeout_ms));
306 vector<double> Galil::arrayUpload(
const std::string& name)
308 ec(
GTimeout(d->g, (
short)timeout_ms));
313 int len = strlen(d->tbuf);
314 char* start = d->tbuf;
315 for (
int i = 0; i < len; i++)
317 if (d->tbuf[i] ==
'\r')
319 vals.push_back(atof(start));
323 vals.push_back(atof(start));
327 void Galil::arrayDownload(
const std::vector<double>& array,
const std::string& name)
331 for (
size_t i = 0; i < array.size(); i++)
333 sprintf(d->tbuf,
"%0.4f\r", array[i]);
334 array_str.append(d->tbuf);
336 ec(
GTimeout(d->g, (
short)timeout_ms));
339 string command =
"DA " + name +
"[]";
340 ec(
GCmd(d->g, command.c_str()));
341 command =
"DM " + name +
"[" + to_string(array.size()) +
"]";
342 ec(
GCmd(d->g, command.c_str()));
348 void Galil::arrayUploadFile(
const std::string& file,
const std::string& names)
350 ec(
GTimeout(d->g, (
short)timeout_ms));
355 void Galil::arrayDownloadFile(
const std::string& file)
357 ec(
GTimeout(d->g, (
short)timeout_ms));
362 void Galil::firmwareDownloadFile(
const std::string& file)
364 ec(
GTimeout(d->g, (
short)timeout_ms));
369 int Galil::write(
const std::string& bytes)
371 ec(
GTimeout(d->g, (
short)timeout_ms));
372 ec(
GWrite(d->g, bytes.data(), bytes.length()));
374 return bytes.length();
379 ec(
GTimeout(d->g, (
short)timeout_ms));
381 ec(
GRead(d->g, d->tbuf,
sizeof(d->tbuf), &bytes_read));
383 return string(d->tbuf, bytes_read);
string AddressConvert(const string &gcl_address)
Takes a GCL address string and returns the equivalent gclib address string.
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 GArrayDownloadFile(GCon g, GCStringIn file_path)
Array download from file.
GCLIB_DLL_EXPORTED GReturn GCALL GFirmwareDownload(GCon g, GCStringIn filepath)
Upgrade firmware.
GCLIB_DLL_EXPORTED GReturn GCALL GArrayUploadFile(GCon g, GCStringIn file_path, GCStringIn names)
Array upload to file.
GCLIB_DLL_EXPORTED GReturn GCALL GClose(GCon g)
Closes a connection to a Galil Controller.
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownloadFile(GCon g, GCStringIn file_path, GCStringIn preprocessor)
Program download from file.
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 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 GInterrupt(GCon g, GStatus *status_byte)
Provides access to PCI and UDP interrupts from the controller.
GCLIB_DLL_EXPORTED GReturn GCALL GWrite(GCon g, GBufIn buffer, GSize buffer_len)
Performs a write on the connection.
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.
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 GMessage(GCon g, GCStringOut buffer, GSize buffer_len)
Provides access to unsolicited messages from the controller.
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 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 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 GRead(GCon g, GBufOut buffer, GSize buffer_len, GSize *bytes_read)
Performs a read on the connection.
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...
GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon *g)
Open a connection to a Galil Controller.
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.
#define G_BAD_RESPONSE_QUESTION_MARK
Operation received a ?, indicating controller has a TC error.
#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.
#define G_CR
For GArrayUpload(), use this value in the delim field to delimit with carriage returns.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
unsigned char GStatus
Interrupt status byte.
#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_BOUNDS
For functions that take range options, e.g. GArrayUpload(), use this value for full range.
unsigned int GSize
Size of buffers, etc.
#define G_FIRMWARE_LOAD_NOT_SUPPORTED
Firmware is not supported on this bus, e.g. Ethernet for the DMC-21x3 series.
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
#define G_UNSUPPORTED_FUNCTION
Function cannot be called on this bus. E.G. GInterrupt() on serial.
#define G_BAD_FILE
Bad file path, bad file contents, or bad write.
#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_UNABLE_TO_COMPRESS_PROGRAM_TO_FIT
Program preprocessor could not compress the program within the user's constraints.
#define G_TIMEOUT
Operation timed out. Timeout is set by the –timeout option in GOpen() and can be overriden by GSettin...
#define G_ILLEGAL_DATA_IN_PROGRAM
Data to download not valid, e.g. \ in data.