示例#1
0
        public bool GetCustCmd(string method)
        {
            ShowCustomActions(method);
            ALS.BLL.customactions bllCust = new ALS.BLL.customactions();
            m_lstCust = bllCust.GetModelList("methodName='" + method + "'");

            if (m_lstCust.Count > 0)
            {
                m_queueCustSendCmd = new Queue <Cls.Model_CustomCMD>();
                ALS.BLL.actions bllact = new ALS.BLL.actions();
                for (int i = 0; i < m_lstCust.Count; i++)
                {
                    //重新计算时间点
                    if (i > 0)
                    {
                        m_lstCust[i].timeCount = m_lstCust[i - 1].timeCount + m_lstCust[i - 1].timeSpan;
                    }
                    //读取步骤下相应的动作列表
                    int customID = (int)m_lstCust[i].ID;
                    List <ALS.Model.actions> lstModAct  = bllact.GetModelList("customID='" + customID + "'");
                    List <Cls.Model_SendCMD> lstActions = new List <Cls.Model_SendCMD>();
                    if (lstModAct.Count > 0)
                    {
                        lstActions = GetlstActions(lstModAct);
                    }
                    Cls.Model_CustomCMD modCustCmd = new Cls.Model_CustomCMD();
                    modCustCmd._TimesCount  = (int)m_lstCust[i].timeCount;
                    modCustCmd._LstSendCMDs = lstActions;
                    modCustCmd._LastTime    = (int)m_lstCust[i].timeSpan;
                    modCustCmd._ActionName  = m_lstCust[i].actionName;
                    modCustCmd._Index       = m_queueCustSendCmd.Count;
                    //将该动作列表加入步骤里
                    m_queueCustSendCmd.Enqueue(modCustCmd);
                }
                //最后一项提取总时间
                int timefull = (int)(m_lstCust[m_lstCust.Count - 1].timeCount + m_lstCust[m_lstCust.Count - 1].timeSpan);// (int)modCust.timeCount + (int)modCust.timeSpan;
                this.lblFullTime.Text = Cls.utils.SecondsToTime(timefull);
                return(true);
            }
            else
            {
                this.lblFullTime.Text = "00:00:00";
                return(false);
            }
        }
示例#2
0
        private void RunFlush(object o)
        {
            Queue <Cls.Model_CustomCMD> queueCustcmd = o as Queue <Cls.Model_CustomCMD>;

            //int nTime = lstccmd[lstccmd.Count-1]._TimesCount + lstccmd[lstccmd.Count - 1]._LastTime;
            M_int_FlushCount = 0;
            int fullTimeCount = int.MaxValue;

            //当前步骤
            Cls.Model_CustomCMD currentStep = new Cls.Model_CustomCMD();

            while (m_isFlush)
            {
                Thread.Sleep(1000);
                if (!M_pauseFlush)
                {
                    BeginInvoke(new Action(() =>
                    {
                        //显示已用时间
                        this.lblTime.Text = Cls.utils.SecondsToTime(M_int_FlushCount);
                        this.lblTime.Invalidate();
                    }));
                    //获取步骤
                    if (queueCustcmd.Count > 0)
                    {
                        currentStep = queueCustcmd.Peek();
                    }
                    //判断当前时间是否为步骤的执行时间点
                    if (M_int_FlushCount == currentStep._TimesCount)
                    {
                        //如果只剩一项时,则获取最后这项的时间点+持续时间,计算结束时间点
                        if (queueCustcmd.Count == 1)
                        {
                            fullTimeCount = currentStep._LastTime + currentStep._TimesCount;
                        }
                        string itemname = currentStep._ActionName;
                        int    index    = currentStep._Index;
                        BeginInvoke(new Action(() =>
                        {
                            //步骤的背景色
                            this.dgvStep.Rows[index].Selected = true;
                            //this.dgvStep.Rows[index].Cells["selAdd"].Value = 1;
                        }));
                        List <Cls.Model_SendCMD> lstscmd = new List <Cls.Model_SendCMD>();
                        lstscmd.AddRange(currentStep._LstSendCMDs);

                        //更新泵及夹管阀状态
                        UpdatePumpState(lstscmd);

                        //创建发送命令子任务
                        m_taskActions = new Task(RunActions, lstscmd, TaskCreationOptions.LongRunning);
                        m_taskActions.Start();
                        //执行任务后,移除队列的顶部
                        queueCustcmd.Dequeue();
                    }
                    M_int_FlushCount++;
                    //判断预冲结束条件
                    if (M_int_FlushCount == fullTimeCount)
                    {
                        BeginInvoke(new Action(() =>
                        {
                            //结束预冲,停止泵
                            m_isFlush = false;
                            //M_int_FlushCount = 0;
                            btnFinish.Enabled   = true;
                            btnStart.Enabled    = true;
                            btnContinue.Enabled = false;
                            btnContinue.Text    = "暂停";
                            //泵停止
                            Cls.utils.SendOrder(_port_Pump, Cls.Comm_PeristalticPump.Command(0x1F, 0, false, true));
                            Cls.utils.SendOrder(_port_Main, Cls.Comm_Main.CmdAlarm.OpenVoice2);
                            if (DialogResult.OK == MessageBox.Show("预冲完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information))
                            {
                                Cls.utils.SendOrder(_port_Main, Cls.Comm_Main.CmdAlarm.AllVoiceClose);
                                FinishFlush();
                            }
                        }));
                    }
                }
                else
                {
                    _spanPause = DateTime.Now - _timePause;
                }
            }
        }