gclib  2.0.8
Communications API for Galil controllers and PLCs
Remote_Client.cs
Go to the documentation of this file.
1 
10 using System;
11 
12 namespace examples
13 {
14  public static partial class Examples
15  {
32 
33  public static int Remote_Client()
34  {
35  gclib gclib = new gclib();
36 
37  bool loop = true;
38  string[] servers_list = Array.Empty<string>();
39 
40  Console.WriteLine("<s> List available servers on the network\n" +
41  "<h> List available hardware on currently connected server\n" +
42  "<0-9> Enter numbers 0-9 to connect to a server by index\n" +
43  "<l> Set active server back to local server\n" +
44  "<q> Quit");
45 
46  while (loop)
47  {
48  char input = Console.ReadKey(true).KeyChar;
49 
50  if(input == 'q')
51  {
52  loop = false;
53  }
54  else if(input == 's')
55  {
56  Console.WriteLine("Available Servers:");
57  servers_list = gclib.GListServers();
58  Print_Servers_List(servers_list);
59  }
60  else if(input >= '0' && input <= '9')
61  {
62  int index = input - '0';
63  if(servers_list.Length > 0 && index < servers_list.Length)
64  {
65  gclib.GSetServer(servers_list[index]);
66  Console.WriteLine("Server set to: " + servers_list[index]);
67  }
68  }
69  else if(input == 'l')
70  {
71  gclib.GSetServer("Local");
72  Console.WriteLine("Server set to: Local");
73  }
74  else if(input == 'h')
75  {
76  string[] addresses = gclib.GAddresses();
77 
78  foreach(string address in addresses)
79  {
80  Console.WriteLine(address);
81  }
82  }
83  }
84 
85  return GALIL_EXAMPLE_OK;
86  }
87 
88  private static void Print_Servers_List(string[] servers_list)
89  {
90  if(servers_list.Length == 0)
91  {
92  Console.WriteLine("none");
93  }
94  else
95  {
96  for(int i = 0; i < servers_list.Length; i++)
97  {
98  Console.WriteLine("<" + i + "> " + servers_list[i]);
99  }
100  }
101  }
103  }
104 }
const int GALIL_EXAMPLE_OK
Examples success code.
Definition: examples.cs:29
string[] GAddresses()
Return a string array of available connection addresses.
Definition: gclib.cs:102
void GSetServer(string server_name)
Connects gclib to a new gcaps server
Definition: gclib.cs:686
string[] GListServers()
Retrieves a list of gcaps servers that are advertising themselves on the local network
Definition: gclib.cs:716
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 Remote_Client()
Accepts user input to publish to list and connect to available servers.
partial Module Examples
Definition: Commands.vb:4