24import java.nio.charset.Charset;
27import com.sun.jna.Library;
28import com.sun.jna.Native;
29import com.sun.jna.Pointer;
30import com.sun.jna.ptr.PointerByReference;
31import com.sun.jna.ptr.IntByReference;
32import com.sun.jna.ptr.ByteByReference;
33import java.util.ArrayList;
39 Boolean connected =
false;
40 byte[] trafficBuffer =
new byte[524288];
73 interface Gclib extends Library {
75 Native.loadLibrary(
"gclib",
83 Native.synchronizedLibrary(INSTANCE);
85 int GArrayDownload(Pointer g, String arrayName,
int first,
int last, String buffer);
86 int GArrayUpload(Pointer g, String arrayName,
int first,
int last,
int delim,
byte[] response,
int len);
87 int GCommand(Pointer g, String command,
byte[] response,
int len, IntByReference bytesReturned);
89 int GFirmwareDownload(Pointer g, String filePath);
90 int GInterrupt(Pointer g, ByteByReference statusByte);
91 int GMessage(Pointer g,
byte[] response,
int len);
92 int GOpen(String address, PointerByReference g);
93 int GProgramDownload(Pointer g, String program, String preprocessor);
112 String buf =
new String();
113 buf = data.stream().map((d) -> d.toString() +
",").reduce(buf, String::concat);
115 ec(
Gclib.SYNC_INSTANCE.GArrayDownload(gclibHandle, arrayName, -1, -1,
116 buf.substring(0, buf.length() - 1)));
134 String buf =
new String();
135 buf = data.stream().map((d) -> d.toString() +
",").reduce(buf, String::concat);
137 ec(
Gclib.SYNC_INSTANCE.GArrayDownload(gclibHandle, arrayName, first, last,
138 buf.substring(0, buf.length() - 1)));
152 ec(
Gclib.SYNC_INSTANCE.GArrayUpload(gclibHandle, arrayName, -1, -1, 1, trafficBuffer, trafficBuffer.length));
153 String[] elements = cstringToString(trafficBuffer).split(
", ");
154 List<Double> doubleList =
new ArrayList();
155 for (String s : elements)
159 doubleList.add(Double.parseDouble(s));
161 catch (NumberFormatException e)
184 ec(
Gclib.SYNC_INSTANCE.GArrayUpload(gclibHandle, arrayName, first, last, 1, trafficBuffer, trafficBuffer.length));
185 String[] elements = cstringToString(trafficBuffer).split(
", ");
186 List<Double> doubleList =
new ArrayList();
187 for (String s : elements)
191 doubleList.add(Double.parseDouble(s));
193 catch (NumberFormatException e)
206 Gclib.SYNC_INSTANCE.GClose(gclibHandle);
222 IntByReference ptrInt =
new IntByReference();
223 ec(
Gclib.SYNC_INSTANCE.GCommand(gclibHandle, command, trafficBuffer, trafficBuffer.length, ptrInt));
224 String response = cstringToString(trafficBuffer);
226 int index = response.lastIndexOf(
"\r\n:");
228 response = response.substring(0, index);
245 ec(
Gclib.SYNC_INSTANCE.GFirmwareDownload(gclibHandle, filePath));
262 ByteByReference statusByte =
new ByteByReference();
263 ec(
Gclib.SYNC_INSTANCE.GInterrupt(gclibHandle, statusByte));
264 return statusByte.getValue();
290 ec(
Gclib.SYNC_INSTANCE.GMessage(gclibHandle, trafficBuffer, trafficBuffer.length));
291 return cstringToString(trafficBuffer);
306 PointerByReference ptrRef =
new PointerByReference();
307 ec(
Gclib.SYNC_INSTANCE.GOpen(address, ptrRef));
308 gclibHandle = ptrRef.getValue();
323 ec(
Gclib.SYNC_INSTANCE.GProgramDownload(gclibHandle, program, preprocessor));
346 ec(
Gclib.SYNC_INSTANCE.GProgramUpload(gclibHandle, trafficBuffer, trafficBuffer.length));
347 return cstringToString(trafficBuffer);
360 Native.loadLibrary(
"gclibo",
368 Native.synchronizedLibrary(INSTANCE);
371 int GArrayDownloadFile(Pointer g, String filePath);
372 int GArrayUploadFile(Pointer g, String filePath, String names);
373 int GAssign(String ip, String mac);
374 void GError(
int rc,
byte[] response,
int len);
375 int GInfo(Pointer g,
byte[] response,
int len);
377 int GProgramDownloadFile(Pointer g, String filePath, String preprocessor);
378 int GProgramUploadFile(Pointer g, String filePath);
379 void GSleep(
int timeout_ms);
380 int GTimeout(Pointer g,
short timeout_ms);
381 int GVersion(
byte[] response,
int len);
382 int GSetServer(String server_name);
385 int GPublishServer(String server_name,
int publish,
int save);
411 ec(
Gclibo.SYNC_INSTANCE.GAddresses(trafficBuffer, trafficBuffer.length));
412 return cstringToString(trafficBuffer);
425 ec(
Gclibo.SYNC_INSTANCE.GArrayDownloadFile(gclibHandle, filePath));
443 ec(
Gclibo.SYNC_INSTANCE.GArrayUploadFile(gclibHandle, filePath, names));
471 ec(
Gclibo.SYNC_INSTANCE.GAssign(ipAddress, macAddress));
484 ec(
Gclibo.SYNC_INSTANCE.GInfo(gclibHandle, trafficBuffer, trafficBuffer.length));
485 return cstringToString(trafficBuffer);
501 ec(
Gclibo.SYNC_INSTANCE.GIpRequests(trafficBuffer, trafficBuffer.length));
502 return cstringToString(trafficBuffer);
516 ec(
Gclibo.SYNC_INSTANCE.GProgramDownloadFile(gclibHandle, filePath, preprocessor));
541 ec(
Gclibo.SYNC_INSTANCE.GProgramUploadFile(gclibHandle, filePath));
554 Gclibo.SYNC_INSTANCE.GSleep(timeout_ms);
567 ec(
Gclibo.SYNC_INSTANCE.GTimeout(gclibHandle, timeout_ms));
581 ec(
Gclibo.SYNC_INSTANCE.GVersion(trafficBuffer, trafficBuffer.length));
582 return cstringToString(trafficBuffer);
594 ec(
Gclibo.SYNC_INSTANCE.GSetServer(server_name));
607 ec(
Gclibo.SYNC_INSTANCE.GServerStatus(trafficBuffer, trafficBuffer.length));
608 return cstringToString(trafficBuffer);
620 ec(
Gclibo.SYNC_INSTANCE.GListServers(trafficBuffer, trafficBuffer.length));
621 return cstringToString(trafficBuffer);
635 ec(
Gclibo.SYNC_INSTANCE.GPublishServer(server_name, publish, save));
647 ec(
Gclibo.SYNC_INSTANCE.GRemoteConnections(trafficBuffer, trafficBuffer.length));
648 return cstringToString(trafficBuffer);
656 String cstringToString(
byte[] cbuf)
658 Charset charset = Charset.forName(
"UTF-8");
660 for (i = 0; i < cbuf.length && cbuf[i] != 0; i++){}
661 return new String(cbuf, 0, i, charset);
665 void ec(
int returnCode)
throws GclibJavaException
670 Gclibo.SYNC_INSTANCE.GError(returnCode, trafficBuffer, trafficBuffer.length);
671 throw new GclibJavaException(returnCode, cstringToString(trafficBuffer));
GclibJava()
Constructor adds gclib to JNA's path.
void finalize()
The last line of defense to close connection.
String GAddresses()
Uses GUtility(), G_UTIL_GCAPS_ADDRESSES or G_UTIL_ADDRESSES to provide a listing of all available con...
String GInfo()
Uses GUtility() and G_UTIL_INFO to provide a useful connection string.
void GAssign(String ipAddress, String macAddress)
Uses GUtility(), G_UTIL_GCAPS_ASSIGN or G_UTIL_ASSIGN to assign an IP address over the Ethernet to a ...
void GTimeout(short timeout_ms)
Uses GUtility() and G_UTIL_TIMEOUT_OVERRIDE to set the library timeout.
void GOpen(String address)
Open a connection to a Galil Controller.
void GClose()
Closes a connection to a Galil Controller.
String GIpRequests()
Uses GUtility(), G_UTIL_GCAPS_IPREQUEST or G_UTIL_IPREQUEST to provide a list of all Galil controller...
String GCommand(String command)
Performs a command-and-response transaction on the connection.
List< Double > GArrayUpload(String arrayName)
Uploads array data from the controller's array table.
void GProgramUploadFile(String filePath)
Program upload to file.
void GArrayDownload(String arrayName, List< Double > data, int first, int last)
Downloads array data to a pre-dimensioned array in the controller's array table.
void GArrayUploadFile(String filePath)
Overload of GArrayUploadFile to upload all arrays.
void GArrayUploadFile(String filePath, String names)
Array upload to file.
void GProgramDownloadFile(String filePath, String preprocessor)
Program download from file.
void GProgramDownload(String program)
Downloads a program using default preprocessor options.
List< Double > GArrayUpload(String arrayName, int first, int last)
Uploads array data from the controller's array table.
void GProgramDownloadFile(String filePath)
Overload of GProgramDownloadFile to use default preprocessor options.
void GArrayDownloadFile(String filePath)
Array download from file.
void GFirmwareDownload(String filePath)
Upgrade firmware.
String GProgramUpload()
Uploads a program from the controller's program buffer.
void GProgramDownload(String program, String preprocessor)
Downloads a program to the controller's program buffer.
void GArrayDownload(String arrayName, List< Double > data)
Downloads array data to a pre-dimensioned array in the controller's array table.
void GSetServer(String server_name)
Connects gclib to a new gcaps server.
void GPublishServer(String server_name, int publish, int save)
Publishes or removes local gcaps server from the network.
String GServerStatus()
Retrieves the name of your local gcaps server and whether or not it is currently published Retrieves ...
String GRemoteConnections()
Returns a list of IP Addresses that currently have an open connection to your hardware.
String GListServers()
Retrieves a list of gcaps servers that are advertising themselves on the local network.
byte GInterrupt()
Provides access to PCI and UDP interrupts from the controller.
String GMessage()
Provides access to unsolicited messages from the controller.
String GVersion()
Uses GUtility(), G_UTIL_VERSION and G_UTIL_GCAPS_VERSION to provide the library and gcaps version num...
void GSleep(int timeout_ms)
Uses GUtility() and G_UTIL_SLEEP to provide a blocking sleep call which can be useful for timing-base...
The JNA interface to the gclib library.
The JNA interface to the open source, gclibo library.