示例#1
0
        private void btnStartPns0102_Click(object sender, EventArgs e)
        {
            if (this.task != null)
            {
                return;
            }

            this.task = MvaTask.RunLoop(() =>
            {
                //大迴圈, 來回一次
                try
                {
                    robotHandler.SgsVerifyStartPns0102(ri =>
                    {
                        this.Invoke(new Action(() =>
                        {
                            tbPoseX.Text = ri.x + "";
                            tbPoseY.Text = ri.y + "";
                            tbPoseZ.Text = ri.z + "";
                            tbPoseW.Text = ri.w + "";
                            tbPoseP.Text = ri.p + "";
                            tbPoseR.Text = ri.r + "";
                        }));
                    });
                    return(true);
                }
                catch (Exception ex)
                {
                    this.LogWrite(ex.Message);
                    return(false);
                }
            }, 1000);
        }
示例#2
0
        protected virtual void WriteAsyn(MvaLoggerEventArgs ea)
        {
            this.queue.Enqueue(ea);
            if (!Monitor.TryEnter(this, 1000))
            {
                return;
            }
            try
            {
                //若還沒結束執行, 先return
                if (this.task != null && !this.task.IsEnd())
                {
                    return;
                }
                this.CloseTask();

                this.task = MvaTask.RunLoop(() =>
                {
                    MvaLoggerEventArgs myea;
                    lock (this)
                    {
                        if (!this.queue.TryDequeue(out myea))
                        {
                            return(true);                                 //取不出來就下次再取
                        }
                    }
                    this.WriteSyn(myea);

                    //若Count等於零, 這個task會結束, IsEnd() = true
                    return(this.queue.Count > 0);
                });
            }
            finally { Monitor.Exit(this); }
        }
示例#3
0
        public int StartAsyn()
        {
            this.m_keepConnection = MvaTask.RunLoop(() =>
            {
                this.Write(EnumMacHalPlcVariable.PC_TO_PLC_CheckClock, false);
                if (!SpinWait.SpinUntil(() => !this.Read <bool>(EnumMacHalPlcVariable.PC_TO_PLC_CheckClock_Reply), 2500))
                {
                    this.LockAssign(ref this.m_isConnected, false);
                    return(false);
                }
                this.LockAssign(ref this.m_isConnected, true);

                this.Write(EnumMacHalPlcVariable.PC_TO_PLC_CheckClock, true);
                if (!SpinWait.SpinUntil(() => this.Read <bool>(EnumMacHalPlcVariable.PC_TO_PLC_CheckClock_Reply), 2500))
                {
                    this.LockAssign(ref this.m_isConnected, false);
                    //throw new MvException("PLC connection T1 timeout");
                    return(false);
                }
                else
                {
                    this.LockAssign(ref this.m_isConnected, true);
                }

                return(true);
            }, 1000);



            return(0);
        }
示例#4
0
        private void Button4_Click(object sender, EventArgs e)
        {
            if (this.task != null)
            {
                return;
            }
            if (this.task != null && !this.task.IsEnd())
            {
                return;
            }

            this.task = MvaTask.RunLoop(() =>
            {
                //大迴圈, 來回一次
                try
                {
                    robotHandler.SgsVerifyStartPns0102(ri =>
                    {
                        this.Invoke(new Action(() =>
                        {
                            X_VALUE.Text  = ri.x + "";
                            Y_VALUE.Text  = ri.y + "";
                            Z_VALUE.Text  = ri.z + "";
                            W_VALUE.Text  = ri.w + "";
                            P_VALUE.Text  = ri.p + "";
                            R_VALUE.Text  = ri.r + "";
                            E1_VALUE.Text = ri.e1 + "";
                        }));
                    });
                    return(true);
                }
                catch (Exception ex)
                {
                    this.LogWrite(ex.Message);
                    return(false);
                }
            }, 1000);
        }