gclib  2.0.8
Communications API for Galil controllers and PLCs
message_example.cs
Go to the documentation of this file.
1 
10 using System;
11 using System.Linq;
12 
13 namespace examples
14 {
22 
24  {
31  public static int Main(string[] args)
32  {
33  int rc = Examples.GALIL_EXAMPLE_OK;
34  gclib gclib = new gclib();
35 
36  try
37  {
38  if (args.Count() != 1)
39  {
40  Console.WriteLine("Incorrect number of arguments provided");
41  Console.WriteLine("Usage: message_example.exe <ADDRESS>");
42 
43  Console.Write("\nPress any key to close the example");
44  Console.ReadKey();
46  }
47 
48  string address = args[0]; //Retrieve address from command line
49 
50  // Opens a connection at the provided address
51  // The --subscribe MG addition is needed to subscribe to
52  // controller messages
53  gclib.GOpen(address + " --subscribe MG");
54 
55  rc = Examples.Message(gclib);
56  }
57  catch(Exception ex)
58  {
61  }
62  finally
63  {
64  gclib.GClose();
65  }
66 
67 
68  Console.Write("\nPress any key to close the example");
69  Console.ReadKey();
70  return rc;
71  }
72  }
74 }
static void PrintError(gclib gclib, Exception ex)
Prints the exception to the console and queries the controller for the most recent error message.
Definition: examples.cs:39
Provides a class of shared constants and methods for gclib's example projects.
Definition: commands.cs:16
const int GALIL_EXAMPLE_OK
Examples success code.
Definition: examples.cs:29
const int GALIL_EXAMPLE_ERROR
Examples error code.
Definition: examples.cs:30
static int Main(string[] args)
Main function for the message example.
Demonstrates how to handle and interpret messages from the controller.
void GOpen(string address)
Used to open a connection to Galil hardware.
Definition: gclib.cs:445
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 int Message(gclib gclib)
Demonstrates how to receive messages from the controller and detect differences in Trace and crashed ...
Definition: message.cs:27