コード例 #1
0
        /// <summary>
        /// 向工站发送一条指令(包含 开始/停止/暂停/恢复/结批 和用户自定义指令)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSendCmd_Click(object sender, EventArgs e)
        {
            int selIndex = cbCmds.SelectedIndex;

            if (selIndex < 0)
            {
                JFTipsDelayClose.Show("请选择需要发送的指令", 2);//MessageBox.Show("请选择需要发送的指令");
                return;
            }
            JFWorkCmdResult cmdRet = JFWorkCmdResult.UnknownError;

            if (AllowedStartStopCmd)
            {
                if (selIndex < 5) //开始/暂停/恢复/结批/停止
                {
                    switch (selIndex)
                    {
                    case 0: cmdRet = _station.Start(); break;

                    case 1: cmdRet = _station.Pause(1000); break;

                    case 2: cmdRet = _station.Resume(1000); break;

                    case 3: cmdRet = _station.EndBatch(1000); break;

                    case 4: cmdRet = _station.Stop(1000); break;
                    }
                }
                else
                {
                    int cmdIndex = selIndex - 5;
                    cmdRet = _station.SendCmd(_station.AllCmds[cmdIndex], 1000);
                }
            }
            else
            {
                if (selIndex < 2) //暂停/恢复
                {
                    switch (selIndex)
                    {
                    case 0: cmdRet = _station.Pause(1000); break;

                    case 1: cmdRet = _station.Resume(1000); break;
                    }
                }
                else
                {
                    int cmdIndex = selIndex - 2;
                    cmdRet = _station.SendCmd(_station.AllCmds[cmdIndex], 1000);
                }
            }
            string errInfo = "";

            switch (cmdRet)
            {
            case JFWorkCmdResult.UnknownError:    // = -1, //发生未定义的错误
                errInfo = "未知错误";
                break;

            case JFWorkCmdResult.Success:    // = 0, //指令执行成功
                errInfo = "指令执行成功";
                break;

            case JFWorkCmdResult.IllegalCmd:    //,//不支持的非法指令
                errInfo = "不支持的非法指令";
                break;

            case JFWorkCmdResult.StatusError:    //, //工作状态(包括用户自定义状态)不支持当前指令 ,(向未运行的线程发送Resume指令)
                errInfo = "当前状态不支持该指令";
                break;

            case JFWorkCmdResult.ActionError:    //, //指令执行失败
                errInfo = "执行失败";
                break;

            case JFWorkCmdResult.Timeout:    //,//线程超时未响应
                errInfo = "指令执行超时";
                break;
            }

            if (cmdRet != JFWorkCmdResult.Success)
            {
                JFTipsDelayClose.Show("指令:" + cbCmds.Text + " 发送失败:" + errInfo, 3);
            }
            else
            {
                ShowTips("指令:" + cbCmds.Text + "发送完成");
            }
        }