20 import java.nio.charset.Charset;
23 import com.sun.jna.Library;
24 import com.sun.jna.Native;
25 import com.sun.jna.Pointer;
26 import com.sun.jna.ptr.PointerByReference;
27 import com.sun.jna.ptr.IntByReference;
28 import com.sun.jna.ptr.ByteByReference;
29 import java.util.ArrayList;
30 import java.util.List;
39 Boolean connected =
false;
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);
86 int GArrayDownload(Pointer g, String arrayName,
int first,
int last, String buffer);
87 int GArrayUpload(Pointer g, String arrayName,
int first,
int last,
int delim,
byte[] response,
int len);
88 int GCommand(Pointer g, String command,
byte[] response,
int len, IntByReference bytesReturned);
91 int GInterrupt(Pointer g, ByteByReference statusByte);
92 int GMessage(Pointer g,
byte[] response,
int len);
93 int GOpen(String address, PointerByReference g);
113 String buf =
new String();
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(
", ");
133 List<Double> doubleList =
new ArrayList();
134 for (String s : elements)
138 doubleList.add(Double.parseDouble(s));
140 catch (NumberFormatException
e)
153 Gclib.SYNC_INSTANCE.GClose(gclibHandle);
169 IntByReference ptrInt =
new IntByReference();
170 ec(Gclib.SYNC_INSTANCE.GCommand(gclibHandle, command, trafficBuffer, trafficBuffer.length, ptrInt));
171 String response = cstringToString(trafficBuffer);
173 int index = response.lastIndexOf(
"\r\n:");
175 response = response.substring(0, index);
192 ec(Gclib.SYNC_INSTANCE.GFirmwareDownload(gclibHandle, filePath));
209 ByteByReference statusByte =
new ByteByReference();
210 ec(Gclib.SYNC_INSTANCE.GInterrupt(gclibHandle, statusByte));
211 return statusByte.getValue();
237 ec(Gclib.SYNC_INSTANCE.GMessage(gclibHandle, trafficBuffer, trafficBuffer.length));
238 return cstringToString(trafficBuffer);
255 PointerByReference ptrRef =
new PointerByReference();
256 ec(Gclib.SYNC_INSTANCE.GOpen(address, ptrRef));
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);
323 int GAssign(String ip, String mac);
324 void GError(
int rc,
byte[] response,
int len);
325 int GInfo(Pointer g,
byte[] response,
int len);
329 void GSleep(
int timeout_ms);
330 int GTimeout(Pointer g,
short timeout_ms);
331 int GVersion(
byte[] response,
int len);
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));
421 ec(Gclibo.SYNC_INSTANCE.GAssign(ipAddress, macAddress));
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);
544 ec(Gclibo.SYNC_INSTANCE.GSetServer(server_name));
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);
585 ec(Gclibo.SYNC_INSTANCE.GPublishServer(server_name, publish, save));
597 ec(Gclibo.SYNC_INSTANCE.GRemoteConnections(trafficBuffer, trafficBuffer.length));
598 return cstringToString(trafficBuffer);
606 String cstringToString(
byte[] cbuf)
608 Charset charset = Charset.forName(
"UTF-8");
610 for (i = 0; i < cbuf.length && cbuf[i] != 0; i++){}
611 return new String(cbuf, 0, i, charset);
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)
List< Double > GArrayUpload(String arrayName)
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)
void GAssign(String ipAddress, String macAddress)
void GArrayUploadFile(String filePath, String names)
GCLIB_DLL_EXPORTED void GCALL GError(GReturn rc, GCStringOut error, GSize error_len)
Provides a human-readable description string for return codes.
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.