示例#1
0
        private Boolean procPrint(string exp)
        {
            Boolean result = false;

            try
            {
                exp = exp.Replace("PRINT(", "").Replace(");", "");
                exp = trimDoubleQuotes(exp);
                string msg = null;
                if (exp.Contains("+"))
                {
                    string[] msgs = exp.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string foo in msgs)
                    {
                        string temp = trimDoubleQuotes(foo);
                        msg = (msg != null ? msg : "") + temp;
                    }
                }
                else
                {
                    msg = exp;
                }
                //info(msg);
                Marco.Print(msg);
                result = true;
            }
            catch (Exception e)
            {
                error(e.StackTrace + " " + e.Message);
                result = false;
            }
            return(result);
        }
示例#2
0
        public void cmdProcess(Socket handler, string msg)
        {
            try
            {
                replayer = handler;
                Dictionary <string, string> argMap = new Dictionary <string, string>();
                argMap.Add("msg", msg);
                #region  息解析
                string returnMsg = "";
                string orgMsg    = msg.Substring(6, msg.Length - 7);//去除前六碼, 與最後的;
                argMap.Add("orgMsg", orgMsg);

                //分解訊息
                string[] rcvMsgAry = msg.Substring(0, msg.Length - 1).Split('/');//去最後一碼;
                //取得命令
                string cmd = rcvMsgAry[0];
                argMap.Add("cmd", cmd);
                //取得引數
                string[] rcvArgs = new string[rcvMsgAry.Length - 1];//0 是命令,不是參數,所以長度少1
                Array.Copy(rcvMsgAry, 1, rcvArgs, 0, rcvArgs.Length);
                //分解命令: 取得 address
                string address = cmd.Substring(1, 1);
                argMap.Add("address", address);
                //分解命令: 取得 命令類別
                string cmd_type = cmd.Substring(2, 3);
                argMap.Add("cmd_type", cmd_type);
                //分解命令: 取得 功能名稱
                int    lastIdx   = cmd.LastIndexOf(":") > 5 ? cmd.LastIndexOf(":") : cmd.Length;
                string func_name = cmd.Substring(6, lastIdx - 6).Replace(";", "");// 前六碼為固定前修飾詞, 例如 $1CMD: $2MCR:
                //宣告回傳參數與錯誤原因
                string[] param  = null;
                string   factor = "";
                #endregion

                #region 處理INF 的 ACK
                if (cmd_type.Equals("ACK"))
                {
                    logger.Info("Receive:" + msg);
                    return;//收到前台ACK 暫時不做事情
                }
                #endregion

                #region 檢查指令格式與目前狀態是否能執行
                checkCmd(msg, ref factor, ref param);
                switch (factor)
                {
                case "MSG":
                    returnMsg = "$" + address + "NAK:MSG|" + orgMsg;
                    Send(handler, returnMsg + ";\r");
                    return;

                case "ACK":
                    returnMsg = "$" + address + "ACK:" + orgMsg;
                    Send(handler, returnMsg + ";\r");
                    break;

                case "CAN":
                default:
                    //returnMsg = "$" + address + "CAN:" + orgMsg + "|" + factor + "/Place";
                    returnMsg = "$" + address + "CAN:" + orgMsg + "|" + factor;
                    Send(handler, returnMsg + ";\r");
                    return;
                }
                #endregion

                #region 執行工作
                //Thread.Sleep(50);20191114 取消 SLEEP for IO REFRESH 效能
                returnMsg = "$" + address;
                switch (func_name)
                {
                    #region Robot 指令
                case "ROBOT_CARRY":
                    argMap.Add("@src", rcvArgs[0]);    //src : P101, SHELF1, ... 等等; 讓Marco 自行處理可辨識的名稱
                    argMap.Add("@dest", rcvArgs[1]);   //dest : P101, SHELF1, ... 等等; 讓Marco 自行處理可辨識的名稱
                    Marco.RunMarco(func_name, argMap);
                    break;

                case "ROBOT_PRESENCE":
                    argMap.Add("@position", rcvArgs[0]);    //position : ARM1,ARM2 ... 等等; 讓Marco 自行處理可辨識的名稱
                    Marco.RunMarco(func_name, argMap);
                    break;

                    #endregion
                default:    //不須特別做參數處理的 function, 傳入之參數會依序放在 @arg1...@argn
                    for (int i = 0; i < rcvArgs.Length; i++)
                    {
                        argMap.Add("@arg" + (i + 1), rcvArgs[i]);
                    }
                    Marco.RunMarco(func_name, argMap);
                    break;
                }
                #endregion
            }
            catch (Exception e)
            {
                logger.Error(e.Message + " " + e.StackTrace);
            }
        }