20import java.nio.charset.Charset;
23import com.sun.jna.Library;
24import com.sun.jna.Native;
25import com.sun.jna.Pointer;
26import com.sun.jna.ptr.PointerByReference;
27import com.sun.jna.ptr.IntByReference;
28import com.sun.jna.ptr.ByteByReference;
29import java.util.ArrayList;
40 byte[] trafficBuffer =
new byte[524288];
47 System.setProperty(
"jna.library.path",
"C:\\Program Files (x86)\\Galil\\gclib\\dll\\x64");
74 interface Gclib
extends Library {
75 Gclib INSTANCE = (Gclib)
76 Native.loadLibrary(
"gclib",
83 Gclib SYNC_INSTANCE = (Gclib)
84 Native.synchronizedLibrary(INSTANCE);
114 buf = data.stream().map((d) -> d.toString() +
",").reduce(
buf, String::concat);
116 ec(Gclib.SYNC_INSTANCE.GArrayDownload(gclibHandle,
arrayName, -1, -1,
117 buf.substring(0,
buf.length() - 1)));
131 ec(Gclib.SYNC_INSTANCE.GArrayUpload(gclibHandle,
arrayName, -1, -1, 1, trafficBuffer, trafficBuffer.length));
132 String[] elements = cstringToString(trafficBuffer).split(
", ");
153 Gclib.SYNC_INSTANCE.GClose(gclibHandle);
170 ec(Gclib.SYNC_INSTANCE.GCommand(gclibHandle, command, trafficBuffer, trafficBuffer.length,
ptrInt));
173 int index =
response.lastIndexOf(
"\r\n:");
192 ec(Gclib.SYNC_INSTANCE.GFirmwareDownload(gclibHandle,
filePath));
210 ec(Gclib.SYNC_INSTANCE.GInterrupt(gclibHandle,
statusByte));
237 ec(Gclib.SYNC_INSTANCE.GMessage(gclibHandle, trafficBuffer, trafficBuffer.length));
238 return cstringToString(trafficBuffer);
257 gclibHandle =
ptrRef.getValue();
272 ec(Gclib.SYNC_INSTANCE.GProgramDownload(gclibHandle,
program, preprocessor));
296 ec(Gclib.SYNC_INSTANCE.GProgramUpload(gclibHandle, trafficBuffer, trafficBuffer.length));
297 return cstringToString(trafficBuffer);
308 interface Gclibo
extends Library {
309 Gclibo INSTANCE = (Gclibo)
310 Native.loadLibrary(
"gclibo",
317 Gclibo SYNC_INSTANCE = (Gclibo)
318 Native.synchronizedLibrary(INSTANCE);
329 void GSleep(
int timeout_ms);
361 ec(Gclibo.SYNC_INSTANCE.GAddresses(trafficBuffer, trafficBuffer.length));
362 return cstringToString(trafficBuffer);
375 ec(Gclibo.SYNC_INSTANCE.GArrayDownloadFile(gclibHandle,
filePath));
393 ec(Gclibo.SYNC_INSTANCE.GArrayUploadFile(gclibHandle,
filePath,
names));
434 ec(Gclibo.SYNC_INSTANCE.GInfo(gclibHandle, trafficBuffer, trafficBuffer.length));
435 return cstringToString(trafficBuffer);
451 ec(Gclibo.SYNC_INSTANCE.GIpRequests(trafficBuffer, trafficBuffer.length));
452 return cstringToString(trafficBuffer);
466 ec(Gclibo.SYNC_INSTANCE.GProgramDownloadFile(gclibHandle,
filePath, preprocessor));
491 ec(Gclibo.SYNC_INSTANCE.GProgramUploadFile(gclibHandle,
filePath));
504 Gclibo.SYNC_INSTANCE.GSleep(timeout_ms);
517 ec(Gclibo.SYNC_INSTANCE.GTimeout(gclibHandle, timeout_ms));
531 ec(Gclibo.SYNC_INSTANCE.GVersion(trafficBuffer, trafficBuffer.length));
532 return cstringToString(trafficBuffer);
557 ec(Gclibo.SYNC_INSTANCE.GServerStatus(trafficBuffer, trafficBuffer.length));
558 return cstringToString(trafficBuffer);
570 ec(Gclibo.SYNC_INSTANCE.GListServers(trafficBuffer, trafficBuffer.length));
571 return cstringToString(trafficBuffer);
597 ec(Gclibo.SYNC_INSTANCE.GRemoteConnections(trafficBuffer, trafficBuffer.length));
598 return cstringToString(trafficBuffer);
615 void ec(
int returnCode)
throws GclibJavaException
620 Gclibo.SYNC_INSTANCE.GError(
returnCode, trafficBuffer, trafficBuffer.length);
621 throw new GclibJavaException(
returnCode, cstringToString(trafficBuffer));
void GSetServer(String server_name)
void GProgramDownloadFile(String filePath, String preprocessor)
void GProgramUploadFile(String filePath)
void GPublishServer(String server_name, int publish, int save)
void GProgramDownload(String program, String preprocessor)
String GCommand(String command)
void GProgramDownload(String program)
void GSleep(int timeout_ms)
String GRemoteConnections()
void GProgramDownloadFile(String filePath)
void GArrayDownload(String arrayName, List< Double > data)
void GOpen(String address)
void GFirmwareDownload(String filePath)
void GArrayUploadFile(String filePath)
void GArrayDownloadFile(String filePath)
void GTimeout(short timeout_ms)
List< Double > GArrayUpload(String arrayName)
void GAssign(String ipAddress, String macAddress)
void GArrayUploadFile(String filePath, String names)
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 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 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 GArrayUploadFile(GCon g, GCStringIn file_path, GCStringIn names)
Array upload to file.
GCLIB_DLL_EXPORTED GReturn GCALL GProgramDownloadFile(GCon g, GCStringIn file_path, GCStringIn preprocessor)
Program download from file.
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 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 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 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 GProgramDownload(GCon g, GCStringIn program, GCStringIn preprocessor)
Downloads a program to the controller's program buffer.
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 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.
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
GReturn vector(GCon g, char *file)
Puts controller into Vector Mode and accepts a file defining vector points.