| gclib 1.34.15 Communications API for Galil controllers and PLCs |

ip_assigner_example.cs
Go to the documentation of this file.
1
10 using System;
11 using System.Linq;
12
13 namespace examples
14 {
24
25 class IP_Assigner_Example
26 {
35 public static int Main(string[] args)
36 {
37 gclib gclib = new gclib();
38 int rc = Examples.GALIL_EXAMPLE_OK;
39
40 try
41 {
42 if(args.Count() != 2)
43 {
44 Console.WriteLine("Incorrect number of arguments provided");
45 Console.WriteLine("Usage: ip_assigner_example.exe <SERIAL #> <1 Byte Address>");
46
47 Console.Write("\nPress any key to close the example");
48 Console.ReadKey();
49 return Examples.GALIL_EXAMPLE_ERROR;
50 }
51
52 string serial_num = args[0];
53 bool ok = Byte.TryParse(args[1], out byte address);
54
55 if(!ok || address < 0 || address > 255)
56 {
57 Console.WriteLine("Please enter a number between 0 and 255 for the address.\n" +
58 " This will be used as the last number in the IP Address\n" +
59 "Usage: ip_assigner_example.exe <SERIAL #> <1 Byte Address>");
60
61 Console.Write("\nPress any key to close the example");
62 Console.ReadKey();
63
64 return Examples.GALIL_EXAMPLE_ERROR;
65 }
66
67 rc = Examples.IP_Assigner(gclib, serial_num, address);
68 }
69 catch(Exception ex)
70 {
71 Examples.PrintError(gclib, ex);
72 rc = Examples.GALIL_EXAMPLE_ERROR;
73 }
74 finally
75 {
76 gclib.GClose();
77 }
78
79 Console.Write("\nPress any key to close the example");
80 Console.ReadKey();
81
82 return rc;
83 }
84 }
86 }
examples.Examples.PrintError
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
examples.Examples
Provides a class of shared constants and methods for gclib's example projects.
Definition: commands.cs:16
examples.Examples.GALIL_EXAMPLE_OK
const int GALIL_EXAMPLE_OK
Examples success code.
Definition: examples.cs:29
examples.Examples.GALIL_EXAMPLE_ERROR
const int GALIL_EXAMPLE_ERROR
Examples error code.
Definition: examples.cs:30
examples.IP_Assigner_Example.Main
static int Main(string[] args)
Main function for the IP Assigner example.
Definition: ip_assigner_example.cs:35
examples.IP_Assigner_Example
Assigns controller an IP Adress given a serial number and a 1 byte address.
Definition: ip_assigner_example.cs:26
examples.Examples.IP_Assigner
static int IP_Assigner(gclib gclib, string serial_num, byte address)
Assigns controller an IP Adress given a serial number and a 1 byte address.
Definition: ip_assigner.cs:36
examples
Definition: commands.cs:14