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);
91 int GMessage(Pointer g,
byte[] response,
int len);
92 int GOpen(String address, PointerByReference g);
112 String buf =
new String();
113 buf = data.stream().map((d) -> d.toString() +
",").reduce(buf, String::concat);
116 buf.substring(0, buf.length() - 1)));
134 String buf =
new String();
135 buf = data.stream().map((d) -> d.toString() +
",").reduce(buf, String::concat);
138 buf.substring(0, buf.length() - 1)));
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)
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)
222 IntByReference ptrInt =
new IntByReference();
224 String response = cstringToString(trafficBuffer);
226 int index = response.lastIndexOf(
"\r\n:");
228 response = response.substring(0, index);
262 ByteByReference statusByte =
new ByteByReference();
264 return statusByte.getValue();
291 return cstringToString(trafficBuffer);
306 PointerByReference ptrRef =
new PointerByReference();
308 gclibHandle = ptrRef.getValue();
347 return cstringToString(trafficBuffer);
360 Native.loadLibrary(
"gclibo",
368 Native.synchronizedLibrary(
INSTANCE);
374 void GError(
int rc,
byte[] response,
int len);
375 int GInfo(Pointer g,
byte[] response,
int len);
412 return cstringToString(trafficBuffer);
485 return cstringToString(trafficBuffer);
502 return cstringToString(trafficBuffer);
582 return cstringToString(trafficBuffer);
608 return cstringToString(trafficBuffer);
621 return cstringToString(trafficBuffer);
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
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.
int GProgramDownload(Pointer g, String program, String preprocessor)
int GArrayDownload(Pointer g, String arrayName, int first, int last, String buffer)
int GMessage(Pointer g, byte[] response, int len)
int GCommand(Pointer g, String command, byte[] response, int len, IntByReference bytesReturned)
int GOpen(String address, PointerByReference g)
int GInterrupt(Pointer g, ByteByReference statusByte)
int GFirmwareDownload(Pointer g, String filePath)
int GArrayUpload(Pointer g, String arrayName, int first, int last, int delim, byte[] response, int len)
int GProgramUpload(Pointer g, byte[] response, int len)
The JNA interface to the open source, gclibo library.
int GServerStatus(byte[] response, int len)
void GError(int rc, byte[] response, int len)
int GIpRequests(byte[] response, int len)
int GArrayUploadFile(Pointer g, String filePath, String names)
int GInfo(Pointer g, byte[] response, int len)
int GArrayDownloadFile(Pointer g, String filePath)
int GSetServer(String server_name)
int GProgramUploadFile(Pointer g, String filePath)
int GListServers(byte[] response, int len)
int GRemoteConnections(byte[] response, int len)
int GTimeout(Pointer g, short timeout_ms)
int GAddresses(byte[] response, int len)
int GAssign(String ip, String mac)
void GSleep(int timeout_ms)
int GPublishServer(String server_name, int publish, int save)
int GProgramDownloadFile(Pointer g, String filePath, String preprocessor)
int GVersion(byte[] response, int len)