示例#1
0
        private static void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
//			Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
            if (null == status.CommandStatus)
            {
                status.CommandStatus              = new Schemas.CRCL.Status.CommandStatusType();
                status.CommandStatus.CommandID    = "1";
                status.CommandStatus.StatusID     = "1";
                status.CommandStatus.CommandState = Schemas.CRCL.Status.CommandStateEnumType.CRCL_Working;
            }
            int statId = 1;

            try {
                statId = Convert.ToInt32(status.CommandStatus.StatusID);
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            statId++;
            status.CommandStatus.StatusID = statId.ToString();
            if (cmdInstance.CRCLCommand != null &&
                !status.CommandStatus.CommandID.Equals(cmdInstance.CRCLCommand.CommandID))
            {
                status.CommandStatus.CommandID = cmdInstance.CRCLCommand.CommandID;
                Console.WriteLine("CommandID = " + cmdInstance.CRCLCommand.CommandID);
                if (typeof(Schemas.CRCL.CommandInstance.InitCanonType).IsAssignableFrom(cmdInstance.CRCLCommand.GetType()))
                {
                    Schemas.CRCL.CommandInstance.InitCanonType initCmd =
                        (Schemas.CRCL.CommandInstance.InitCanonType)cmdInstance.CRCLCommand;
                    Console.WriteLine("initCmd = " + initCmd);
                }
                else if (typeof(Schemas.CRCL.CommandInstance.EndCanonType).IsAssignableFrom(cmdInstance.CRCLCommand.GetType()))
                {
                    Schemas.CRCL.CommandInstance.EndCanonType endCmd =
                        (Schemas.CRCL.CommandInstance.EndCanonType)cmdInstance.CRCLCommand;
                    Console.WriteLine("endCmd = " + endCmd);
                }
                else if (typeof(Schemas.CRCL.CommandInstance.MoveToType).IsAssignableFrom(cmdInstance.CRCLCommand.GetType()))
                {
                    Schemas.CRCL.CommandInstance.MoveToType moveToCmd =
                        (Schemas.CRCL.CommandInstance.MoveToType)cmdInstance.CRCLCommand;
                    Console.WriteLine("moveToCmd = " + moveToCmd);
                    if (null != moveToCmd.EndPosition)
                    {
                        status.PoseStatus      = new Schemas.CRCL.Status.PoseStatusType();
                        status.PoseStatus.Pose = new Schemas.CRCL.Status.PoseType();
                        if (null != moveToCmd.EndPosition.Point)
                        {
                            Console.WriteLine("moveToCmd.EndPosition.Point = "
                                              + moveToCmd.EndPosition.Point.X + ","
                                              + moveToCmd.EndPosition.Point.Y + ","
                                              + moveToCmd.EndPosition.Point.Z
                                              );
                            status.PoseStatus.Pose.Point   = new Schemas.CRCL.Status.PointType();
                            status.PoseStatus.Pose.Point.X = moveToCmd.EndPosition.Point.X;
                            status.PoseStatus.Pose.Point.Y = moveToCmd.EndPosition.Point.Y;
                            status.PoseStatus.Pose.Point.Z = moveToCmd.EndPosition.Point.Z;
                        }
                        if (null != moveToCmd.EndPosition.XAxis)
                        {
                            Console.WriteLine("moveToCmd.EndPosition.XAxis = "
                                              + moveToCmd.EndPosition.XAxis.I + ","
                                              + moveToCmd.EndPosition.XAxis.J + ","
                                              + moveToCmd.EndPosition.XAxis.K
                                              );
                            status.PoseStatus.Pose.XAxis   = new Schemas.CRCL.Status.VectorType();
                            status.PoseStatus.Pose.XAxis.I = moveToCmd.EndPosition.XAxis.I;
                            status.PoseStatus.Pose.XAxis.J = moveToCmd.EndPosition.XAxis.J;
                            status.PoseStatus.Pose.XAxis.K = moveToCmd.EndPosition.XAxis.K;
                        }
                        if (null != moveToCmd.EndPosition.XAxis)
                        {
                            Console.WriteLine("moveToCmd.EndPosition.ZAxis = "
                                              + moveToCmd.EndPosition.ZAxis.I + ","
                                              + moveToCmd.EndPosition.ZAxis.J + ","
                                              + moveToCmd.EndPosition.ZAxis.K
                                              );
                            status.PoseStatus.Pose.ZAxis   = new Schemas.CRCL.Status.VectorType();
                            status.PoseStatus.Pose.ZAxis.I = moveToCmd.EndPosition.ZAxis.I;
                            status.PoseStatus.Pose.ZAxis.J = moveToCmd.EndPosition.ZAxis.J;
                            status.PoseStatus.Pose.ZAxis.K = moveToCmd.EndPosition.ZAxis.K;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Command " + cmdInstance.CRCLCommand + " unrecognized");
                }
            }
        }
        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;
                }
            }
        }
示例#3
0
		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;
				}
			}
		}