8 using System.Collections.Generic;
9 using System.ComponentModel;
14 using System.Threading.Tasks;
15 using System.Windows.Forms;
30 InitializeComponent();
34 private void MainForm_Load(
object sender, EventArgs
e)
36 PrintOutput(
"Enter a FULL GOpen() address above and click Go", PrintStyle.Instruction);
37 PrintOutput(
"NOTE: This demo will attempt to move Axis A", PrintStyle.Instruction);
41 private void HelpLabel_Click(
object sender, EventArgs
e)
44 System.Diagnostics.Process.Start(
"http://www.galil.com/sw/pub/all/doc/gclib/html/gclib_8h_aef4aec8a85630eed029b7a46aea7db54.html#aef4aec8a85630eed029b7a46aea7db54");
48 private void GoButton_Click(
object sender, EventArgs
e)
50 if (AddressTextBox.Text.Length == 0)
52 PrintOutput(
"Enter a FULL GOpen() address above and click Go", PrintStyle.Instruction);
55 RunDemo(AddressTextBox.Text);
59 private enum PrintStyle
74 private void PrintOutput(
string Message, PrintStyle Style = PrintStyle.Normal,
bool SuppressCrLf =
false)
76 if (Output.InvokeRequired)
78 Output.Invoke(
new Printer(PrintOutput),
new object[] { Message, Style, SuppressCrLf });
86 case PrintStyle.Instruction:
89 case PrintStyle.GalilData:
92 case PrintStyle.Normal:
98 case PrintStyle.GclibData:
99 color = Color.Magenta;
106 Output.SelectionStart = Output.Text.Length;
107 Output.SelectionColor = color;
108 Output.AppendText(Message);
111 Output.AppendText(
"\r\n");
126 private delegate
void Printer(
string Message, PrintStyle Style,
bool SuppressCrLf);
133 private void RunDemo(
string address)
135 MainToolStrip.Enabled =
false;
137 GclibBackgroundWorker.RunWorkerAsync(address);
144 private void GclibBackgroundWorker_DoWork(
object sender, DoWorkEventArgs
e)
146 PrintOutput(
"Running Demo with address " +
e.Argument, PrintStyle.Normal);
147 TheDemo((
string)
e.Argument);
153 private void GclibBackgroundWorker_RunWorkerCompleted(
object sender, RunWorkerCompletedEventArgs
e)
155 PrintOutput(
"Demo thread done.", PrintStyle.Normal);
156 MainToolStrip.Enabled =
true;
163 private void TheDemo(
string address)
170 PrintOutput(
"gclib version: ", PrintStyle.Normal,
true);
184 PrintOutput(
"Available connections:");
186 if (addrs.Length == 0)
192 foreach (
string a
in addrs)
194 PrintOutput(a, PrintStyle.GclibData);
198 PrintOutput(
"Opening connection to \"" + address +
"\"... ", PrintStyle.Normal,
true);
200 PrintOutput(
"Connected.", PrintStyle.Normal);
201 PrintOutput(
gclib.
GInfo(), PrintStyle.GalilData);
205 PrintOutput(
"Sending \"MG TIME\"", PrintStyle.Normal);
206 PrintOutput(
gclib.
GCommand(
"MG TIME",
false), PrintStyle.GalilData);
208 PrintOutput(
"Downloading Program... ", PrintStyle.Normal,
true);
211 PrintOutput(
"Uploading Program");
214 PrintOutput(
"Blocking GMessage call");
216 System.Threading.Thread.Sleep(200);
221 PrintOutput(
"Downloading Program... ", PrintStyle.Normal,
true);
225 PrintOutput(
"Uploading Program");
228 PrintOutput(
"Non-blocking GMessage call", PrintStyle.Normal,
true);
233 while ((
string.IsNullOrEmpty(msg)))
236 PrintOutput(
".", PrintStyle.Normal,
true);
237 System.Threading.Thread.Sleep(20);
240 PrintOutput(
"Message: ", PrintStyle.Normal,
true);
241 PrintOutput(msg.Trim(), PrintStyle.GalilData);
246 PrintOutput(
"Downloading Program... ", PrintStyle.Normal,
true);
250 PrintOutput(
"Uploading Program");
253 PrintOutput(
"Non-blocking GInterrupt call", PrintStyle.Normal,
true);
261 PrintOutput(
".", PrintStyle.Normal,
true);
262 System.Threading.Thread.Sleep(20);
265 PrintOutput(
"Byte: ", PrintStyle.Normal,
true);
266 PrintOutput(b.ToString(
"X02"), PrintStyle.GalilData);
270 PrintOutput(
"Getting some synchronous data records");
272 for (
int i = 0; i <= 10; i++)
275 PrintOutput(DataRecord.sample_number +
" ", PrintStyle.GalilData,
true);
277 System.Threading.Thread.Sleep(10);
281 PrintOutput(
"Getting some asynchronous data records");
284 for (
int i = 0; i <= 10; i++)
287 PrintOutput(DataRecord.sample_number +
" ", PrintStyle.GalilData,
true);
294 PrintOutput(
"Downloading an array... ", PrintStyle.Normal,
true);
295 List<double> array =
new List<double>();
296 for (
double i = 0; i <= 9; i++)
304 PrintOutput(
"Ok. Uploading array");
306 foreach (
double d
in array)
308 PrintOutput(d.ToString(
"F4") +
" ", PrintStyle.GalilData,
true);
312 PrintOutput(
"Performing a write... ", PrintStyle.Normal,
true);
315 PrintOutput(
"Ok. Reading binary data... ", PrintStyle.Normal,
true);
317 PrintOutput(
"Ok. Read " + data.Length +
" bytes.");
319 PrintOutput(
"Preparing A axis. This could cause errors if the axis is not initialized...", PrintStyle.Normal,
true);
325 PrintOutput(
"Profiling a move on axis A... ", PrintStyle.Normal,
true);
327 PrintOutput(
"Waiting for motion to complete... ", PrintStyle.Normal,
true);
330 PrintOutput(
"Going back... ", PrintStyle.Normal,
true);
338 PrintOutput(
"Error: " + ex.Message, PrintStyle.Err);
Demonstrates using gclib in a Windows Form, including using a second thread to free the GUI.
string GProgramUpload()
Allows uploading of a DMC program to a string.
string GVersion()
Used to get the gclib version.
void GOpen(string address)
Used to open a connection to Galil hardware.
void GWrite(string buffer)
Performs a write on the connection.
string GCommand(string Command, bool Trim=true)
Used for command-and-response transactions.
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.
string GInfo()
Provides a useful connection string.
void GProgramDownload(string program, string preprocessor="")
Allows downloading of a DMC program from a string buffer.
string[] GAddresses()
Return a string array of available connection addresses.
byte GInterrupt()
Provides access to PCI and UDP interrupts from the controller.
string GMessage()
Provides access to unsolicited messages.
byte[] GRead()
Performs a read on the connection.
void GMotionComplete(string axes)
Blocking call that returns once all axes specified have completed their motion.
void GTimeout(Int16 timeout_ms)
Set the timeout of communication transactions. Use -1 to set the original timeout from GOpen().
List< double > GArrayUpload(string array_name, Int16 first=-1, Int16 last=-1)
Uploads array data from the controller's array table.
void GClose()
Used to close a connection to Galil hardware.
void GRecordRate(double period_ms)
Sets the asynchronous data record to a user-specified period via DR.
Provides a class that binds to gclib's unmanaged dll. Wraps each call and provides a more user-friend...
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Data record struct for DMC-4000 controllers, including 4000, 4200, 4103, and 500x0.