| gclib 1.35.5 Communications API for Galil controllers and PLCs |

position_tracking_example.cs
Go to the documentation of this file.
1
10 using System;
11 using System.Linq;
12
13 namespace examples
14 {
25
26 class Position_Tracking_Example
27 {
36 public static int Main(string[] args)
37 {
38 int rc = Examples.GALIL_EXAMPLE_OK;
39 gclib gclib = new gclib();
40
41 try
42 {
43 int speed = 0;
44
45 if(args.Count() == 1)
46 {
47 speed = 5000;
48 }
49 else if(args.Count() == 2)
50 {
51 bool ok = int.TryParse(args[1], out speed);
52
53 if(!ok)
54 {
55 Console.WriteLine("An invalid speed was entered. " +
56 "Please enter a valid integer for speed.");
57 Console.WriteLine("Usage: position_tracking_example.exe <ADDRESS> <SPEED=5000>");
58
59 Console.Write("\nPress any key to close the example");
60 Console.ReadKey();
61 return Examples.GALIL_EXAMPLE_ERROR;
62 }
63 }
64 else
65 {
66 Console.WriteLine("Incorrect number of arguments provided");
67 Console.WriteLine("Usage: position_tracking_example.exe <ADDRESS> <SPEED=5000>");
68
69 Console.Write("\nPress any key to close the example");
70 Console.ReadKey();
71 return Examples.GALIL_EXAMPLE_ERROR;
72 }
73
74 string address = args[0]; //Retrieve address from command line
75 gclib.GOpen(address); // Open a connection at the provided address
76
77 rc = Examples.Position_Tracking(gclib, speed); // Begin position tracking mode
78 }
79 catch(Exception ex)
80 {
81 Examples.PrintError(gclib, ex);
82 rc = Examples.GALIL_EXAMPLE_ERROR;
83 }
84 finally
85 {
86 gclib.GClose();
87 }
88
89 Console.Write("\nPress any key to close the example");
90 Console.ReadKey();
91
92 return rc;
93 }
94 }
96 }
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.Position_Tracking_Example.Main
static int Main(string[] args)
Main function for the position tracking example.
Definition: position_tracking_example.cs:36
examples.Position_Tracking_Example
Places controller into position tracking mode. Accepts user-defined positional values at the command ...
Definition: position_tracking_example.cs:27
examples.Examples.Position_Tracking
static int Position_Tracking(gclib gclib, int speed)
Puts controller into Position Tracking Mode and accepts user-entered positions.
Definition: position_tracking.cs:28
examples
Definition: commands.cs:14