gclib 2.0.9
Communications API for Galil controllers and PLCs
 
Loading...
Searching...
No Matches
GclibTest.java
Go to the documentation of this file.
1
3package gclibtest;
4
5import gclibjava.GclibJava; //the java gclib wrapper
6import gclibjava.GclibJavaException; //the Galil exception class
7import java.util.ArrayList;
8import java.util.List;
9
13public class GclibTest {
14
18 public static void main(String[] args) {
19
20 System.out.println("Java gclib Test");
21 test();
22 System.out.println("Done");
23
24 }
25
26 static void test()
27 {
28 GclibJava gclib = new GclibJava(); //our instance of the GclibJava class
29
30 try
31 {
32 System.out.println("gclib version " + gclib.GVersion());
33
34 /*
35 System.out.println("Hardware Requesting IP Addresses:");
36 System.out.print(gclib.GIpRequests());
37 System.out.println();
38 */
39
40 /*
41 System.out.println("Available addresses:");
42 System.out.print(gclib.GAddresses());
43 System.out.println();
44 */
45
46 /*
47 System.out.println("Assigning IP Address");
48 gclib.GAssign("192.168.0.42", "00-50-4C-20-01-23");
49 */
50
51 System.out.println("Connecting");
52 gclib.GOpen("192.168.0.42 -s ALL"); //connect to hardware, through gcaps
53 //see http://galil.com/sw/pub/all/doc/gclib/html/gcaps.html
54
55 System.out.println(gclib.GInfo());
56
57 System.out.println("MG TIME: " + gclib.GCommand("MG TIME"));
58
59 System.out.println("Downloading program");
60 gclib.GProgramDownload("#A\rWT100\rMG\"Hello from program!\",TIME\rEN");
61 //gclib.GProgramDownloadFile("c:\\temp\\test.dmc");
62
63 System.out.println("Program now on hardware\n********************");
64 System.out.print(gclib.GProgramUpload());
65 //gclib.GProgramUploadFile("c:\\temp\\uploaded.dmc");
66 System.out.println("\n********************");
67
68 /*
69 gclib.GTimeout((short) 10000); //adjust timeout for long command
70 gclib.GCommand("BP"); //burn program
71 gclib.GTimeout((short) -1); //use initial GOpen() timeout (--timeout)
72 */
73
74 System.out.println("Executing program");
75 gclib.GCommand("XQ"); //execute program that was just downloaded
76
77 System.out.println("Reading for a message");
78 System.out.println(gclib.GMessage()); //print the message the program generated
79
80 System.out.println("Downloading array data");
82 for (double i = 0; i < 10.0; ++i)
83 {
84 doubleList.add(i);
85 }
86 gclib.GCommand("DA*[]"); //deallocate all array data
87 gclib.GCommand("DM array[10]"); //dimension the array
89 //gclib.GArrayDownloadFile("c:\\temp\\arrays.csv");
90
91 System.out.println("Uploading array data");
92 List<Double> arrayUpload = gclib.GArrayUpload("array");
93 //gclib.GArrayUploadFile("c:\\temp\\upload_arrays.csv", "array");
94 for (Double d : arrayUpload)
95 {
96 System.out.println(d.toString());
97 }
98
99 /*
100 gclib.GCommand("UI 1"); //should evoke $F1 from products that
101 //support interrupts. Look for the existance of UI in the hardware
102 //command reference.
103
104 System.out.println("Interrupt status byte: " +
105 String.format("%02X", gclib.GInterrupt()));
106 */
107
108 /*
109 //loading firmware
110 System.out.println("Firmware loader test");
111 System.out.println("Currently loaded firmware: " + gclib.GCommand("\u0012\u0016")); //^R^V
112 gclib.GFirmwareDownload("c:\\temp\\dmc-4000-r12h-cer.hex");
113 System.out.println("Currently loaded firmware: " + gclib.GCommand("\u0012\u0016")); //^R^V
114 gclib.GFirmwareDownload("c:\\temp\\dmc-4000-r12h.hex");
115 System.out.println("Currently loaded firmware: " + gclib.GCommand("\u0012\u0016")); //^R^V
116 */
117
118 }
119 catch (GclibJavaException e)
120 {
121 System.out.println(Integer.toString(e.getErrorCode()) + " " + e.getMessage()); //print the message
122 }
123 finally
124 {
125 gclib.GClose(); //must call close
126 }
127
128 }//test()
129
130}
131
string GProgramUpload()
Allows uploading of a DMC program to a string.
Definition gclib.cs:499
string GVersion()
Used to get the gclib version.
Definition gclib.cs:614
void GOpen(string address)
Used to open a connection to Galil hardware.
Definition gclib.cs:445
List< double > GArrayUpload(string array_name, Int16 first=-1, Int16 last=-1)
Uploads array data from the controller's array table.
Definition gclib.cs:173
string GCommand(string Command, bool Trim=true)
Used for command-and-response transactions.
Definition gclib.cs:257
void GArrayDownload(string array_name, ref List< double > data, Int16 first=-1, Int16 last=-1)
Downloads array data to a pre-dimensioned array in the controller's array table.
Definition gclib.cs:126
string GInfo()
Provides a useful connection string.
Definition gclib.cs:344
void GProgramDownload(string program, string preprocessor="")
Allows downloading of a DMC program from a string buffer.
Definition gclib.cs:465
string GMessage()
Provides access to unsolicited messages.
Definition gclib.cs:407
void GClose()
Used to close a connection to Galil hardware.
Definition gclib.cs:239
Provides a class that binds to gclib's unmanaged dll. Wraps each call and provides a more user-friend...
Definition gclib.cs:68
static void main(String[] args)
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition examples.h:33
GReturn vector(GCon g, char *file)
Puts controller into Vector Mode and accepts a file defining vector points.
Definition vector.cpp:36