public static void Main (string[] args) { AsynchronousClient ac = null; try { int port = Schemas.CRCL.Defaults.PORT; String host = "127.0.0.1"; bool debug = false; for (int i = 0; i < args.Length - 1; i++) { if (args [i].Equals ("-p")) { port = Convert.ToInt32 (args [i + 1]); i++; } else if (args [i].Equals ("-h")) { host = args [i + 1]; i++; } else if (args [i].Equals ("-d")) { debug = true; } } if(args.Length > 0 && args[args.Length-1].Equals("-d")) { debug = true; } ac = new AsynchronousClient (host, port, new AsynchronousClient.UpdateStatusDelegate (updateStatus), debug); ac.StartClient (); Console.WriteLine ("Starting C# ConsoleClient connected to " + host + " on port " + port + "."); Console.WriteLine ("Use -p [port] to change port."); Console.WriteLine ("Use -h [host] to change host."); Console.WriteLine ("Use -d to set debug flag."); String l = null; int cid = 1; while (!"quit".Equals(l = Console.ReadLine ())) { if(l == null) { Console.WriteLine("Console.ReadLine() returned null. (Bad Terminal ??)"); break; } if (l.Length == 0) { getStatusCmdInstance.CRCLCommand = getStatusCmd; getStatusCmd.CommandID = cid.ToString (); String statusRequestXml = Schemas.CRCL.Utils.ToXML (getStatusCmdInstance); ac.Send (statusRequestXml); ac.sendDoneWaitOne (); } else if(l.StartsWith("init")) { Schemas.CRCL.CommandInstance.InitCanonType initCmd = new Schemas.CRCL.CommandInstance.InitCanonType(); cmdInstance.CRCLCommand = initCmd; initCmd.CommandID = cid.ToString(); String cmdXml = Schemas.CRCL.Utils.ToXML (cmdInstance); ac.Send (cmdXml); ac.sendDoneWaitOne(); } else if(l.StartsWith("end")) { Schemas.CRCL.CommandInstance.EndCanonType endCmd = new Schemas.CRCL.CommandInstance.EndCanonType(); cmdInstance.CRCLCommand = endCmd; endCmd.CommandID = cid.ToString(); String cmdXml = Schemas.CRCL.Utils.ToXML (cmdInstance); ac.Send (cmdXml); ac.sendDoneWaitOne(); } else if(l.StartsWith("move")) { Schemas.CRCL.CommandInstance.MoveToType moveCmd = new Schemas.CRCL.CommandInstance.MoveToType(); cmdInstance.CRCLCommand = moveCmd; string[] fields = l.Split(" ".ToCharArray(),10); moveCmd.EndPosition = new Schemas.CRCL.CommandInstance.PoseType(); moveCmd.EndPosition.Point = new Schemas.CRCL.CommandInstance.PointType(); moveCmd.EndPosition.Point.X = fields.Length > 1 ? decimal.Parse(fields[1]) : 0; moveCmd.EndPosition.Point.Y = fields.Length > 2 ? decimal.Parse(fields[2]) : 0; moveCmd.EndPosition.Point.Z = fields.Length > 3 ? decimal.Parse(fields[3]) : 0; moveCmd.EndPosition.XAxis = new Schemas.CRCL.CommandInstance.VectorType(); moveCmd.EndPosition.XAxis.I = fields.Length > 4 ? decimal.Parse(fields[4]) : 0; moveCmd.EndPosition.XAxis.J = fields.Length > 5 ? decimal.Parse(fields[5]) : 0; moveCmd.EndPosition.XAxis.K = fields.Length > 6 ? decimal.Parse(fields[6]) : 0; moveCmd.EndPosition.ZAxis = new Schemas.CRCL.CommandInstance.VectorType(); moveCmd.EndPosition.ZAxis.I = fields.Length > 7 ? decimal.Parse(fields[7]) : 0; moveCmd.EndPosition.ZAxis.J = fields.Length > 8 ? decimal.Parse(fields[8]) : 0; moveCmd.EndPosition.ZAxis.K = fields.Length > 9 ? decimal.Parse(fields[9]) : 0; moveCmd.CommandID = cid.ToString(); String cmdXml = Schemas.CRCL.Utils.ToXML (cmdInstance); ac.Send (cmdXml); ac.sendDoneWaitOne(); } else { Console.WriteLine("Command not recognized: "+l); Console.WriteLine("Commands include:"); Console.WriteLine("init"); Console.WriteLine("end"); Console.WriteLine("quit"); Console.WriteLine("move [x] [y] [z] [x.i] [x.j] [x.z] [z.i] [z.j] [z.k]"); Console.WriteLine(""); Console.WriteLine("Press enter on empty line to see status."); } if(debug) { Console.WriteLine("cid = "+cid); } cid++; } } catch (Exception e) { Console.WriteLine (e.ToString ()); } finally { if (null != ac) { ac.Close (); ac = null; } } }
public static void Main(string[] args) { AsynchronousClient ac = null; try { int port = Schemas.CRCL.Defaults.PORT; String host = "127.0.0.1"; bool debug = false; for (int i = 0; i < args.Length - 1; i++) { if (args [i].Equals("-p")) { port = Convert.ToInt32(args [i + 1]); i++; } else if (args [i].Equals("-h")) { host = args [i + 1]; i++; } else if (args [i].Equals("-d")) { debug = true; } } if (args.Length > 0 && args[args.Length - 1].Equals("-d")) { debug = true; } ac = new AsynchronousClient(host, port, new AsynchronousClient.UpdateStatusDelegate(updateStatus), debug); ac.StartClient(); Console.WriteLine("Starting C# ConsoleClient connected to " + host + " on port " + port + "."); Console.WriteLine("Use -p [port] to change port."); Console.WriteLine("Use -h [host] to change host."); Console.WriteLine("Use -d to set debug flag."); String l = null; int cid = 1; while (!"quit".Equals(l = Console.ReadLine())) { if (l == null) { Console.WriteLine("Console.ReadLine() returned null. (Bad Terminal ??)"); break; } if (l.Length == 0) { getStatusCmdInstance.CRCLCommand = getStatusCmd; getStatusCmd.CommandID = cid.ToString(); String statusRequestXml = Schemas.CRCL.Utils.ToXML(getStatusCmdInstance); ac.Send(statusRequestXml); ac.sendDoneWaitOne(); } else if (l.StartsWith("init")) { Schemas.CRCL.CommandInstance.InitCanonType initCmd = new Schemas.CRCL.CommandInstance.InitCanonType(); cmdInstance.CRCLCommand = initCmd; initCmd.CommandID = cid.ToString(); String cmdXml = Schemas.CRCL.Utils.ToXML(cmdInstance); ac.Send(cmdXml); ac.sendDoneWaitOne(); } else if (l.StartsWith("end")) { Schemas.CRCL.CommandInstance.EndCanonType endCmd = new Schemas.CRCL.CommandInstance.EndCanonType(); cmdInstance.CRCLCommand = endCmd; endCmd.CommandID = cid.ToString(); String cmdXml = Schemas.CRCL.Utils.ToXML(cmdInstance); ac.Send(cmdXml); ac.sendDoneWaitOne(); } else if (l.StartsWith("move")) { Schemas.CRCL.CommandInstance.MoveToType moveCmd = new Schemas.CRCL.CommandInstance.MoveToType(); cmdInstance.CRCLCommand = moveCmd; string[] fields = l.Split(" ".ToCharArray(), 10); moveCmd.EndPosition = new Schemas.CRCL.CommandInstance.PoseType(); moveCmd.EndPosition.Point = new Schemas.CRCL.CommandInstance.PointType(); moveCmd.EndPosition.Point.X = fields.Length > 1 ? decimal.Parse(fields[1]) : 0; moveCmd.EndPosition.Point.Y = fields.Length > 2 ? decimal.Parse(fields[2]) : 0; moveCmd.EndPosition.Point.Z = fields.Length > 3 ? decimal.Parse(fields[3]) : 0; moveCmd.EndPosition.XAxis = new Schemas.CRCL.CommandInstance.VectorType(); moveCmd.EndPosition.XAxis.I = fields.Length > 4 ? decimal.Parse(fields[4]) : 0; moveCmd.EndPosition.XAxis.J = fields.Length > 5 ? decimal.Parse(fields[5]) : 0; moveCmd.EndPosition.XAxis.K = fields.Length > 6 ? decimal.Parse(fields[6]) : 0; moveCmd.EndPosition.ZAxis = new Schemas.CRCL.CommandInstance.VectorType(); moveCmd.EndPosition.ZAxis.I = fields.Length > 7 ? decimal.Parse(fields[7]) : 0; moveCmd.EndPosition.ZAxis.J = fields.Length > 8 ? decimal.Parse(fields[8]) : 0; moveCmd.EndPosition.ZAxis.K = fields.Length > 9 ? decimal.Parse(fields[9]) : 0; moveCmd.CommandID = cid.ToString(); String cmdXml = Schemas.CRCL.Utils.ToXML(cmdInstance); ac.Send(cmdXml); ac.sendDoneWaitOne(); } else { Console.WriteLine("Command not recognized: " + l); Console.WriteLine("Commands include:"); Console.WriteLine("init"); Console.WriteLine("end"); Console.WriteLine("quit"); Console.WriteLine("move [x] [y] [z] [x.i] [x.j] [x.z] [z.i] [z.j] [z.k]"); Console.WriteLine(""); Console.WriteLine("Press enter on empty line to see status."); } if (debug) { Console.WriteLine("cid = " + cid); } cid++; } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { if (null != ac) { ac.Close(); ac = null; } } }
static void Main(string[] args) { AsynchronousClient.StartClient(); }