Example #1
0
        /// <summary>
        /// 检测轴在指定延迟时间内是否完成动作
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="milliseconds"></param>
        /// <returns></returns>
        public bool WaitForAxisMoveDone(ushort axis, int milliseconds)
        {
            if (axis < 0 || axis >= m_axisCount)
            {
                return(false);
            }

            short state = 0;

            while (true)
            {
                if (milliseconds-- == 0)
                {
                    return(false);                    //动作超时
                }
                lock (globalLock)
                {
                    state = LTDMC.dmc_check_done(m_cardNo, axis);
                    if (state == 1)
                    {
                        return(true);
                    }
                }

                Thread.Sleep(1);
            }
        }
        private void Axis_GOCommandExecute(object obj)
        {
            if (System.Windows.Forms.MessageBox.Show($"是否运动到点{int.Parse(obj.ToString()) + 1}?", "确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                if (LTDMC.dmc_check_done(_CardID, 0) == 1 && LTDMC.dmc_check_done(_CardID, 1) == 1 && LTDMC.dmc_check_done(_CardID, 2) == 1)
                {
                    Task.Run(() => {
                        DMC5400ASVN[0] = true; DMC5400ASVN[1] = true; DMC5400ASVN[2] = true;
                        Res            = LTDMC.dmc_write_sevon_pin(_CardID, 0, 0); //励磁
                        Res            = LTDMC.dmc_write_sevon_pin(_CardID, 1, 0); //励磁
                        Res            = LTDMC.dmc_write_sevon_pin(_CardID, 2, 0); //励磁

                        Res = LTDMC.dmc_set_profile(_CardID, 0, 200, 2000, 0.1, 0.1, 1000);
                        Res = LTDMC.dmc_set_profile(_CardID, 1, 200, 2000, 0.1, 0.1, 1000);
                        Res = LTDMC.dmc_set_profile(_CardID, 2, 200, 2000, 0.1, 0.1, 1000);

                        Res = LTDMC.dmc_pmove(_CardID, 0, (int)(PrefilePos[int.Parse(obj.ToString())].X * 100), 1);
                        Res = LTDMC.dmc_pmove(_CardID, 1, (int)(PrefilePos[int.Parse(obj.ToString())].Y * 100), 1);
                        Res = LTDMC.dmc_pmove(_CardID, 2, (int)(PrefilePos[int.Parse(obj.ToString())].Z * 100), 1);

                        while (LTDMC.dmc_check_done(_CardID, 0) == 0 || LTDMC.dmc_check_done(_CardID, 1) == 0 || LTDMC.dmc_check_done(_CardID, 2) == 0)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                    });
                }
                else
                {
                    AddMessage("错误:轴Busy");
                }
            }
        }
Example #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // ushort axis = GetAxis(); //轴号
            double dcurrent_speedX = 0, dcurrent_speedY = 0, dcurrent_speedZ = 0, dcurrent_speedW = 0; //速度值
            //  double dunitPosX, dunitPosY, dunitPosZ, dunitPosW; //脉冲当量转换后指令值
            int PosX, PosY, PosZ, PosW;                                                                //脉冲值

            LTDMC.dmc_read_current_speed_unit(_CardID, 0, ref dcurrent_speedX);                        // 读取轴当前速度
            LTDMC.dmc_read_current_speed_unit(_CardID, 1, ref dcurrent_speedY);
            LTDMC.dmc_read_current_speed_unit(_CardID, 2, ref dcurrent_speedZ);
            LTDMC.dmc_read_current_speed_unit(_CardID, 3, ref dcurrent_speedW);
            txtCurrentSpeedX.Text = dcurrent_speedX.ToString();
            txtCurrentSpeedY.Text = dcurrent_speedY.ToString();
            txtCurrentSpeedZ.Text = dcurrent_speedZ.ToString();
            txtCurrentSpeedW.Text = dcurrent_speedW.ToString();
            //LTDMC.dmc_get_position_unit(_CardID, 0, ref dunitPosX); //读取指定轴指令位置值
            //txtFinalPosY.Text = dunitPosX.ToString();
            PosX = LTDMC.dmc_get_position(_CardID, 0);//读取指定轴的脉冲值
            PosY = LTDMC.dmc_get_position(_CardID, 1);
            PosZ = LTDMC.dmc_get_position(_CardID, 2);
            PosW = LTDMC.dmc_get_position(_CardID, 3);
            txtCurrentPosX.Text = PosX.ToString();
            txtCurrentPosY.Text = PosY.ToString();
            txtCurrentPosZ.Text = PosZ.ToString();
            txtCurrentPosW.Text = PosW.ToString();
            if (LTDMC.dmc_check_done(_CardID, 0) == 0) // 读取指定轴运动状态
            {
                txtStateX.Text = "运行中";
            }
            else
            {
                txtStateX.Text = "停止中";
            }
            if (LTDMC.dmc_check_done(_CardID, 1) == 0) // 读取指定轴运动状态
            {
                txtStateY.Text = "运行中";
            }
            else
            {
                txtStateY.Text = "停止中";
            }
            if (LTDMC.dmc_check_done(_CardID, 2) == 0) // 读取指定轴运动状态
            {
                txtStateZ.Text = "运行中";
            }
            else
            {
                txtStateZ.Text = "停止中";
            }
            if (LTDMC.dmc_check_done(_CardID, 3) == 0) // 读取指定轴运动状态
            {
                txtStateW.Text = "运行中";
            }
            else
            {
                txtStateW.Text = "停止中";
            }
        }
Example #4
0
 // 封装dmc运动函数:卡号, 轴号, 脉冲数, 运动方向, 运动模式
 public void DMC3400_Move(ushort nCardNo, ushort nAxisIndex, int nPulse, int nDirection, ushort nMoveMode)
 {
     if (LTDMC.dmc_check_done(m_cardNo, nAxisIndex) == 0) //已经在运动中
     {
         return;
     }
     //点动(位置模式)
     LTDMC.dmc_pmove(m_cardNo, nAxisIndex, nPulse * nDirection, nMoveMode);  //最后的0表示相对运动
 }
Example #5
0
        public bool Check_done()
        {
            short run;

            //
            run = LTDMC.dmc_check_done(_CardID, axis);

            return(Run = run == 1 ? false : true);
        }
        public void DoState()
        {
            uint rdy = 0;
            uint alm = 0;
            uint plt = 0;
            uint nlt = 0;
            uint org = 0;

            for (int axis = 0; axis < define_motion.wd_axis_count; axis++)
            {
                //位置
                mAxisPlace[axis] = LTDMC.dmc_get_position(pAxis[axis].AxisCard, pAxis[axis].AxisCode);

                //当前状态
                uint mask = pAxis[axis].AxisMask;
                if (LTDMC.dmc_check_done(pAxis[axis].AxisCard, pAxis[axis].AxisCode) != 0)
                {
                    rdy |= mask;                                                                        //轴已经停止。检测指定轴的运动状态,返回值: 0 指定轴正在运行, 1 指定轴已停止
                }
                //轴运动状态
                uint st = LTDMC.dmc_axis_io_status(pAxis[axis].AxisCard, pAxis[axis].AxisCode);//读取指定轴有关运动信号的状态

                if ((st & LTDMC.state_axis.state_org) > 0)
                {
                    org |= mask;
                }
                if ((st & LTDMC.state_axis.alarm_eln) > 0)
                {
                    nlt |= mask;
                }
                if ((st & LTDMC.state_axis.alarm_elp) > 0)
                {
                    plt |= mask;
                }
                if ((st & LTDMC.state_axis.state_alm) > 0)
                {
                    alm |= mask;
                }

                list.Add(new AxisStatus()
                {
                    IoReady = rdy,
                    IoAlarm = alm,
                    IoOrgin = org,
                    IoNegLt = nlt,
                    IoPosLt = plt
                });
            }
        }
        private void Axis_Jog_P_MouseDown_CommandExecute(object obj)
        {
            ushort axis = ushort.Parse(obj.ToString());

            if (LTDMC.dmc_check_done(_CardID, axis) == 1)
            {
                DMC5400ASVN[axis] = true;
                Res = LTDMC.dmc_write_sevon_pin(_CardID, axis, 0);//励磁
                Res = LTDMC.dmc_set_profile(_CardID, axis, 200, 2000, 0.1, 0.1, 1000);
                Res = LTDMC.dmc_vmove(_CardID, axis, 1);
            }
            else
            {
                AddMessage("错误:轴Busy");
            }
        }
Example #8
0
        /// <summary>
        /// 获取轴状态信息
        /// </summary>
        /// <param name="card"></param>
        /// <param name="axis"></param>
        /// <param name="axisStatus">获取的轴状态</param>
        /// <returns>返回0与非0   0代表轴停止, 非0轴在运动中</returns>
        public short _SR_GetAxisStatus(short card, short axis, out int axisStatus)
        {
            short shrResult = 0;

            short staus = (short)LTDMC.dmc_check_done((ushort)tag_cardids[card], (ushort)axis);

            if (staus == 1)
            {
                axisStatus = 0;
            }
            else

            {
                axisStatus = 1;
            }


            return(shrResult);
        }
Example #9
0
        void Home_alone(ushort Cardno, ushort Axis, ushort home_mode, double Low_Vel, double High_Vel)
        {
            // LTDMC.nmc_set_axis_enable(0, 0);  //使能
            ///Thread.Sleep(1000);
            PublicClass.AxisHome(Cardno, Axis, home_mode, Low_Vel, High_Vel);
            ushort homerres = 99;

            while ((LTDMC.dmc_check_done(Cardno, Axis) == 0) || (homerres != 1))    //判断是否回零完
            {
                LTDMC.dmc_get_home_result(Cardno, Axis, ref homerres);
                Application.DoEvents();

                if (VarClass.ReadIN[4])  //jiting
                {
                    return;
                }
                Thread.Sleep(10);
            }
        }
Example #10
0
 private void OrderByAxis(ushort axis)
 {
     AxisBackHome(axis);
     Thread.Sleep(100);
     while (true)
     {
         GetAxisLimitedSensor(axis, ref homeSensor0, ref posLimited0, ref negLimited0);
         if (homeSensor0)
         {
             LTDMC.dmc_stop(0, axis, 1);
         }
         short state = LTDMC.dmc_check_done(0, axis);
         if (state == 1)
         {
             if (axis != 0)
             {
                 StartHome(axis - 1);
             }
             break;
         }
     }
 }
Example #11
0
        private bool WaitAxisMotionDone(int axis, int uMilliSeconds)
        {
            short status   = 0;
            int   nMillSec = uMilliSeconds;

            while (true)
            {
                if (nMillSec-- == 0)
                {
                    return(false);
                }
                lock (globalLock)
                {
                    status = LTDMC.dmc_check_done(0, (ushort)axis);
                    if (status == 1)
                    {
                        return(true);
                    }
                }
                Thread.Sleep(1);
            }
        }
Example #12
0
        private bool MonitorDMCCard()
        {
            short state = 0;

            lock (globalLock)
            {
                for (ushort i = 0; i < m_axisCount; i++)
                {
                    m_axisPrfPos[i] = LTDMC.dmc_get_position(m_cardNo, i);
                    m_axisEncPos[i] = LTDMC.dmc_get_encoder(m_cardNo, i);

                    state = LTDMC.dmc_check_done(m_cardNo, i);

                    //轴状态
                    AnalyseMotionStatus(i, state);

                    //IO状态
                    AnalyseMotionIOStatus(i);
                }
            }

            return(true);
        }
        public void HomeMove()
        {
            HomeStep = 1;
            while (HomeStep != 0)
            {
                switch (HomeStep)
                {
                case 1:
                {
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("3个Z轴归零中", Color.Black);
                        });
Home1:
                    PublicClass.AxisHome(0, 0, 7, VarClass.Low_Wel[0], VarClass.High_Wel[0]);         //大Z轴归零
                    PublicClass.AxisHome(0, 1, 7, VarClass.Low_Wel[1], VarClass.High_Wel[1]);         //小Z轴归零
                    PublicClass.AxisHome(0, 2, 7, VarClass.Low_Wel[2], VarClass.High_Wel[2]);         //扫码轴归零

                    ushort BigZstate   = 99;
                    ushort SmallZstate = 99;
                    ushort ScanZstate  = 99;
                    Thread.Sleep(500);
                    while ((LTDMC.dmc_check_done(0, 0) == 0) || (BigZstate != 1) || (LTDMC.dmc_check_done(0, 1) == 0) || (SmallZstate != 1) || (LTDMC.dmc_check_done(0, 2) == 0) || (ScanZstate != 1))            //判断是否回零完
                    {
                        LTDMC.dmc_get_home_result(0, 0, ref BigZstate);
                        LTDMC.dmc_get_home_result(0, 1, ref SmallZstate);
                        LTDMC.dmc_get_home_result(0, 2, ref ScanZstate);


                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 0, 0);          //大Z轴停止
                            PublicClass.AxisStop(0, 1, 0);          //小Z轴停止
                            PublicClass.AxisStop(0, 2, 0);          //大Z轴停止
                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Home1;
                            }
                        }
                    }
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("3个Z轴归零完成,下一步小Z轴归零", Color.Black);
                        });
                    HomeStep = 3;
                    break;
                }



                case 3:
                {
Home3:
                    PublicClass.AxisMove(1, VarClass.AutoSpeed[1], VarClass.SmallZ_Location[1]);           //小Z轴跑低位
                    while ((LTDMC.dmc_check_done(0, 1) == 0) || (VarClass.SmallZ_Location[1] != VarClass.Pulse_Current[1]))
                    {
                        Thread.Sleep(5);

                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 1, 0);           //小Z轴停止

                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Home3;
                            }
                        }
                    }
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("小Z轴到达低位,下一步左右气缸出", Color.Black);
                        });
                    //PublicClass.WriteOUT(0, 12, 0);//左气缸出
                    //PublicClass.WriteOUT(0, 13, 1);
                    PublicClass.WriteOUT(0, 6, 0);                       //左右气缸出
                    PublicClass.WriteOUT(0, 7, 1);
                    while (!VarClass.ReadIN[13] || !VarClass.ReadIN[16]) //左,右气缸出限
                    {
                        Thread.Sleep(5);

                        while (VarClass.Pause_Flag)
                        {
                            Thread.Sleep(5);
                        }
                    }
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("左右气缸出完,下一步小Z轴跑位,扫码Z轴去扫码位", Color.Black);
                        });
                    HomeStep = 4;
                    break;
                }

                case 4:
                {
Home4:
                    Thread.Sleep(500);
                    PublicClass.AxisMove(1, VarClass.AutoSpeed[1], VarClass.SmallZ_Location[0]);           //小 Z轴跑高位
                                                                                                           //  PublicClass.AxisMove(2, VarClass.AutoSpeed[2], VarClass.ScanZ_Location[1]);   //扫码Z轴到扫描位
                    while ((LTDMC.dmc_check_done(0, 1) == 0) || (VarClass.SmallZ_Location[0] != VarClass.Pulse_Current[1]))
                    {
                        Thread.Sleep(5);

                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 1, 0);           //小Z轴停止


                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Home4;
                            }
                        }
                    }
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("小Z轴到达高位;XY轴归零", Color.Black);
                        });
                    HomeStep = 5;
                    break;
                }

                case 5:
                {
Home5:
                    Thread.Sleep(500);
                    PublicClass.AxisHome(0, 3, 13, VarClass.Low_Wel[3], VarClass.High_Wel[3]);         //X轴归零
                    PublicClass.AxisHome(0, 4, 13, VarClass.Low_Wel[4], VarClass.High_Wel[4]);         //Y轴归零

                    ushort XAixsState = 99;
                    ushort YAixsState = 99;
                    Thread.Sleep(500);
                    while ((LTDMC.dmc_check_done(0, 3) == 0) || (XAixsState != 1) || (LTDMC.dmc_check_done(0, 4) == 0) || (YAixsState != 1))            //判断是否回零完
                    {
                        LTDMC.dmc_get_home_result(0, 3, ref XAixsState);
                        LTDMC.dmc_get_home_result(0, 4, ref YAixsState);

                        Thread.Sleep(10);

                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 3, 0);          //X轴停止
                            PublicClass.AxisStop(0, 4, 0);          //Y轴停止
                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Home5;
                            }
                        }
                    }
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("归零完成", Color.Black);
                        });
                    VarClass.Homeing    = false;       //归零标志
                    VarClass.HomeFinish = true;

                    HomeStep = 0;
                    break;
                }
                }
            }
        }
Example #14
0
 public bool IsAxisStop(int index, int axis)
 {
     return(LTDMC.dmc_check_done((ushort)Id, (ushort)axis) == 1);
 }
        private void Axis_Home_CommandExecute(object obj)
        {
            ushort axis = ushort.Parse(obj.ToString());

            if (System.Windows.Forms.MessageBox.Show("是否回原点?", "确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                if (LTDMC.dmc_check_done(_CardID, axis) == 1)
                {
                    Task.Run(() =>
                    {
                        DMC5400ASVN[axis] = true;
                        Res = LTDMC.dmc_write_sevon_pin(_CardID, axis, 0);//励磁

                        Res = LTDMC.dmc_set_profile(_CardID, axis, 200, 2000, 0.1, 0.1, 1000);

                        switch (axis)
                        {
                        case 0:
                        case 1:
                            Res = LTDMC.dmc_pmove(_CardID, axis, -99999, 0);
                            while (!DMC5400ALimN[axis])
                            {
                                System.Threading.Thread.Sleep(10);
                            }
                            Res = LTDMC.dmc_stop(_CardID, axis, 0);
                            System.Threading.Thread.Sleep(100);
                            Res = LTDMC.dmc_set_homemode(_CardID, axis, 1, 0, 1, 0);    //设置回零模式
                            break;

                        case 2:
                            Res = LTDMC.dmc_pmove(_CardID, axis, 99999, 0);
                            while (!DMC5400ALimP[axis])
                            {
                                System.Threading.Thread.Sleep(10);
                            }
                            Res = LTDMC.dmc_stop(_CardID, axis, 0);
                            System.Threading.Thread.Sleep(100);
                            Res = LTDMC.dmc_set_homemode(_CardID, axis, 0, 0, 1, 0);    //设置回零模式
                            break;

                        default:
                            break;
                        }

                        Res = LTDMC.dmc_home_move(_CardID, axis);
                        while (LTDMC.dmc_check_done(_CardID, axis) == 0)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                        System.Threading.Thread.Sleep(500);
                        Res         = LTDMC.dmc_set_position(_CardID, axis, 0);
                        Res         = LTDMC.dmc_set_encoder(_CardID, axis, 0);
                        homed[axis] = true;
                    });
                }
                else
                {
                    AddMessage("错误:轴Busy");
                }
            }
        }
Example #16
0
 public bool AxisIsStop(int index, int axis)
 {
     return(LTDMC.dmc_check_done((ushort)DevIndex, (ushort)axis) == 1);
 }
        private async void Run()
        {
            bool DMC5400ADi_0 = false;
            bool presurefirst = false; double _value1 = 0;

            while (true)
            {
                try
                {
                    #region IO
                    var portno0 = LTDMC.dmc_read_inport(_CardID, 0);
                    for (int i = 0; i < 16; i++)
                    {
                        DMC5400ADi[i] = (portno0 & 0x1 << i) == 0;
                    }
                    for (int i = 0; i < 4; i++)
                    {
                        DMC5400ALimP[i] = (portno0 & 0x10000 << i) != 0;
                        DMC5400ALimN[i] = (portno0 & 0x1000000 << i) != 0;
                    }
                    var portno1 = LTDMC.dmc_read_inport(_CardID, 1);
                    for (int i = 0; i < 4; i++)
                    {
                        DMC5400AHome[i]  = (portno1 & 0x1 << i) == 0;
                        DMC5400AAlarm[i] = (portno1 & 0x100 << i) != 0;
                        DMC5400AReady[i] = (portno1 & 0x10000 << i) == 0;
                    }
                    #endregion
                    #region 轴状态
                    GPos.X = (double)(LTDMC.dmc_get_position(_CardID, 0)) / 100;
                    GPos.Y = (double)(LTDMC.dmc_get_position(_CardID, 1)) / 100;
                    GPos.Z = (double)(LTDMC.dmc_get_position(_CardID, 2)) / 100;

                    CPos.X = (double)(LTDMC.dmc_get_encoder(_CardID, 0)) / 100;
                    CPos.Y = (double)(LTDMC.dmc_get_encoder(_CardID, 1)) / 100;
                    CPos.Z = (double)(LTDMC.dmc_get_encoder(_CardID, 2)) / 100;

                    #endregion
                    #region 模拟量
                    double _value = 0;
                    LTDMC.nmc_get_ad_input(_CardID, 1, 0, ref _value);
                    if (!presurefirst)
                    {
                        _value1      = _value;
                        presurefirst = true;
                    }
                    WeightValue = (_value - _value1) / 16 * 1000;
                    #endregion
                    #region 运行函数
                    if (runflag && DMC5400ASVN[0] && DMC5400ASVN[1] && DMC5400ASVN[2] && homed[0] && homed[1] && homed[2])
                    {
                        switch (stepnum)
                        {
                        case 0:
                            //Res = LTDMC.dmc_set_profile(_CardID, 0, 200, 50000, 0.1, 0.1, 1000);
                            //Res = LTDMC.dmc_set_profile(_CardID, 1, 200, 50000, 0.1, 0.1, 1000);
                            Res = LTDMC.dmc_set_profile(_CardID, 2, 200, 10000, 0.01, 0.01, 1000);

                            //Res = LTDMC.dmc_pmove(_CardID, 0, (int)(PrefilePos[0].X * 100), 1);
                            //Res = LTDMC.dmc_pmove(_CardID, 1, (int)(PrefilePos[0].Y * 100), 1);
                            Res = LTDMC.dmc_pmove(_CardID, 2, (int)(PrefilePos[0].Z * 100), 1);

                            stepnum = 1;
                            break;

                        case 1:
                            //if (LTDMC.dmc_check_done(_CardID, 0) == 1 && LTDMC.dmc_check_done(_CardID, 1) == 1 && LTDMC.dmc_check_done(_CardID, 2) == 1)
                            if (LTDMC.dmc_check_done(_CardID, 2) == 1)
                            {
                                stepnum = 2;
                            }
                            break;

                        case 2:
                            await Task.Delay(1000);

                            stepnum = 3;
                            break;

                        case 3:
                            //Res = LTDMC.dmc_set_profile(_CardID, 0, 200, 50000, 0.1, 0.1, 1000);
                            //Res = LTDMC.dmc_set_profile(_CardID, 1, 200, 50000, 0.1, 0.1, 1000);
                            Res = LTDMC.dmc_set_profile(_CardID, 2, 200, 10000, 0.01, 0.01, 1000);

                            //Res = LTDMC.dmc_pmove(_CardID, 0, (int)(PrefilePos[1].X * 100), 1);
                            //Res = LTDMC.dmc_pmove(_CardID, 1, (int)(PrefilePos[1].Y * 100), 1);
                            Res = LTDMC.dmc_pmove(_CardID, 2, (int)(PrefilePos[1].Z * 100), 1);

                            stepnum = 4;
                            break;

                        case 4:
                            //if (LTDMC.dmc_check_done(_CardID, 0) == 1 && LTDMC.dmc_check_done(_CardID, 1) == 1 && LTDMC.dmc_check_done(_CardID, 2) == 1)
                            if (LTDMC.dmc_check_done(_CardID, 2) == 1)
                            {
                                stepnum = 5;
                            }
                            break;

                        case 5:
                            await Task.Delay(1000);

                            stepnum = 0;
                            break;

                        case 6:
                            //Res = LTDMC.dmc_set_profile(_CardID, 0, 200, 50000, 0.1, 0.1, 1000);
                            //Res = LTDMC.dmc_set_profile(_CardID, 1, 200, 50000, 0.1, 0.1, 1000);
                            Res = LTDMC.dmc_set_profile(_CardID, 2, 200, 50000, 0.1, 0.1, 1000);

                            //Res = LTDMC.dmc_pmove(_CardID, 0, (int)(PrefilePos[2].X * 100), 1);
                            //Res = LTDMC.dmc_pmove(_CardID, 1, (int)(PrefilePos[2].Y * 100), 1);
                            Res = LTDMC.dmc_pmove(_CardID, 2, (int)(PrefilePos[2].Z * 100), 1);

                            stepnum = 7;
                            break;

                        case 7:
                            //if (LTDMC.dmc_check_done(_CardID, 0) == 1 && LTDMC.dmc_check_done(_CardID, 1) == 1 && LTDMC.dmc_check_done(_CardID, 2) == 1)
                            if (LTDMC.dmc_check_done(_CardID, 2) == 1)
                            {
                                stepnum = 8;
                            }
                            break;

                        case 8:
                            await Task.Delay(1000);

                            stepnum = 0;
                            break;

                        default:
                            break;
                        }
                    }
                    if (DMC5400ADi_0 != DMC5400ADi[0])
                    {
                        DMC5400ADi_0 = DMC5400ADi[0];
                        if (DMC5400ADi[0])
                        {
                            runflag        = false;
                            Res            = LTDMC.dmc_stop(_CardID, 0, 0);
                            Res            = LTDMC.dmc_stop(_CardID, 1, 0);
                            Res            = LTDMC.dmc_stop(_CardID, 2, 0);
                            stepnum        = -1;
                            DMC5400ASVN[0] = false;
                            DMC5400ASVN[1] = false;
                            DMC5400ASVN[2] = false;
                            Res            = LTDMC.dmc_write_sevon_pin(_CardID, 0, 1);
                            Res            = LTDMC.dmc_write_sevon_pin(_CardID, 1, 1);
                            Res            = LTDMC.dmc_write_sevon_pin(_CardID, 2, 1);
                            AddMessage("急停按钮 按下");
                        }
                    }
                    #endregion
                }
                catch { }

                await Task.Delay(10);
            }
        }
Example #18
0
        /// <summary>
        /// 读取轴状态
        /// </summary>
        public void DoState()
        {
            bool rdy = false;
            bool alm = false;
            bool plt = false;
            bool nlt = false;
            bool org = false;

            //int place = 0;
            AxisStateList.Clear();
            for (int axis = 0; axis < define_AxisNum.wd_axis_count; axis++)
            {
                //位置
                AxisPlace[axis] = LTDMC.dmc_get_position(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode);

                //当前状态
                //轴已经停止。检测指定轴的运动状态,返回值: 0 指定轴正在运行, 1 指定轴已停止
                if (LTDMC.dmc_check_done(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode) == 0)
                {
                    rdy = true;
                }
                else
                {
                    rdy = false;
                }

                //轴运动状态
                uint st = LTDMC.dmc_axis_io_status(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode);//读取指定轴有关运动信号的状态

                if ((st & LTDMC.state_axis.state_org) > 0)
                {
                    org = true;
                }
                else
                {
                    org = false;
                }
                if ((st & LTDMC.state_axis.alarm_eln) > 0)
                {
                    nlt = true;
                }
                else
                {
                    nlt = false;
                }
                if ((st & LTDMC.state_axis.alarm_elp) > 0)
                {
                    plt = true;
                }
                else
                {
                    plt = false;
                }
                if ((st & LTDMC.state_axis.state_alm) > 0)
                {
                    alm = true;
                }
                else
                {
                    alm = false;
                }

                AxisStateList.Add(new define_AxisState()
                {
                    isReady = rdy,
                    isAlarm = alm,
                    isOrgin = org,
                    isNegLt = nlt,
                    isPosLt = plt,
                });
            }
        }
        public void AutoMove()
        {
            AutoStep = 1;



            while (AutoStep != 0)
            {
                switch (AutoStep)
                {
                case 1:
                {
Auto1:
                    AxisMove(3, VarClass.AutoSpeed[3], VarClass.XAxis_Location[0]);           //X轴到换料位
                    AxisMove(4, VarClass.AutoSpeed[4], VarClass.YAxis_Location[0]);           //Y轴到换料位
                    //读取下标为3.4轴的运动状态
                    while ((LTDMC.dmc_check_done(0, 3) == 0) || (VarClass.XAxis_Location[0] != VarClass.Pulse_Current[3]) ||
                           (LTDMC.dmc_check_done(0, 4) == 0) || (VarClass.YAxis_Location[0] != VarClass.Pulse_Current[4]))
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 3, 0);           //XAxis停止
                            PublicClass.AxisStop(0, 4, 0);           //YAxis轴停止

                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Auto1;
                            }
                        }
                    }
                    if (VarClass.StopState == "outing")
                    {
                        VarClass.StopState = "outed";
                        myFrMain.Invoke((MethodInvoker) delegate
                            {
                                myFrMain.addLog("XY轴到换料位,下步点击进入按钮", Color.Black);
                            });
                    }
                    else
                    {
                        myFrMain.Invoke((MethodInvoker) delegate
                            {
                                myFrMain.addLog("XY轴到换料位,选择测试", Color.Black);
                            });
                    }
                    ///saoma
                    AutoStep = 2;
                    break;
                }

                case 2:
                {
                    while ((VarClass.TestNumber == 0) || (VarClass.StopState != ""))         //开始测试
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            Thread.Sleep(5);
                        }
                    }

                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("选择测试完成,下步双手启动", Color.Black);
                        });
                    while (!VarClass.ReadIN[0] || !VarClass.ReadIN[1])           //双手启动
                    {
                        VarClass.HandsStart = true;
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            Thread.Sleep(5);
                        }
                    }
                    VarClass.HandsStart = false;
                    while (!VarClass.ReadIN[5])           //接近感应器
                    {
                        MessageBox.Show("接近没有感应到");
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            Thread.Sleep(5);
                        }
                    }
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("接近感应到,下步XY轴去扫码位", Color.Black);
                        });
Auto2:
                    AxisMove(3, VarClass.AutoSpeed[3], VarClass.XAxis_Location[1]);           //X轴到扫码位
                    AxisMove(4, VarClass.AutoSpeed[4], VarClass.YAxis_Location[1]);           //Y轴到扫码位
                    while ((LTDMC.dmc_check_done(0, 3) == 0) || (VarClass.XAxis_Location[1] != VarClass.Pulse_Current[3]) || (LTDMC.dmc_check_done(0, 4) == 0) || (VarClass.YAxis_Location[1] != VarClass.Pulse_Current[4]))
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 3, 0);           //XAxis停止
                            PublicClass.AxisStop(0, 4, 0);           //YAxis轴停止

                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Auto2;
                            }
                        }
                    }
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("下步XY轴到扫码位,下步扫码Z轴去扫码位", Color.Black);
                        });
                    Auto50 : PublicClass.AxisMove(2, VarClass.AutoSpeed[2], VarClass.ScanZ_Location[1]);      //扫码Z轴到扫描位
                    while ((LTDMC.dmc_check_done(0, 2) == 0) || (VarClass.ScanZ_Location[1] != VarClass.Pulse_Current[2]))
                    {
                        Thread.Sleep(5);

                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 2, 0);           //扫码Z轴停止

                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Auto50;
                            }
                        }
                    }



                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("扫码Z轴到扫码位,下步扫码", Color.Black);
                        });



                    while (!VarClass.IsScanOK)
                    {
                        VarClass.ClientString[1] = "";
                        // Scan.ClientSend1("T");
                        Scan.ClientSend3("T");

                        // Scan.ClientSend3("T");
                        Thread.Sleep(2000);
                        if ((VarClass.ClientString[2] != "NG") && (VarClass.ClientString[2] != ""))
                        {
                            string ScanString = HttpVar.barcode = VarClass.ClientString[2];


                            VarClass.IsScanOK = true;
                            myFrMain.Invoke((MethodInvoker) delegate
                                {
                                    myFrMain.addLog("扫码成功:" + HttpVar.barcode + ",下步XY去测料位", Color.Black);
                                });
                        }
                        else
                        {
                            MessageBox.Show("扫码失败");
                            myFrMain.Invoke((MethodInvoker) delegate
                                {
                                    myFrMain.addLog("扫码失败", Color.Black);
                                });
                        }
                    }
                    VarClass.IsScanOK = false;
                    AutoStep          = 3;
                    break;
                }

                case 3:
                {
Auto3:
                    AxisMove(3, VarClass.AutoSpeed[3], VarClass.XAxis_Location[2]);           //X轴到测料位
                    AxisMove(4, VarClass.AutoSpeed[4], VarClass.YAxis_Location[2]);           //Y轴到测料位
                    while ((LTDMC.dmc_check_done(0, 3) == 0) || (VarClass.XAxis_Location[2] != VarClass.Pulse_Current[3]) || (LTDMC.dmc_check_done(0, 3) == 0) || (VarClass.YAxis_Location[2] != VarClass.Pulse_Current[4]))
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 3, 0);           //XAxis停止
                            PublicClass.AxisStop(0, 4, 0);           //YAxis轴停止

                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Auto3;
                            }
                        }
                    }
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("XY轴到测料位,下步大轴下", Color.Black);
                        });
                    AutoStep = 4;
                    break;
                }

                case 4:
                {
Auto4:
                    PublicClass.AxisJogMove(0, VarClass.AutoSpeed[0], 0); //大轴下,速度,方向

                    while (!VarClass.ReadIN[10])                          //对射光纤
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 0, 0);           //XAxis停止


                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Auto4;
                            }
                        }
                    }
                    PublicClass.AxisStop(0, 0, 0);           //XAxis停止

                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("大轴到位,下步左右气缸回", Color.Black);
                        });

                    //PublicClass.WriteOUT(0, 12, 1);//左气缸回
                    //PublicClass.WriteOUT(0, 13, 0);

                    AutoStep = 5;
                    break;
                }

                case 5:
                {
                    PublicClass.WriteOUT(0, 6, 1);                       //左右气缸回
                    PublicClass.WriteOUT(0, 7, 0);
                    while (!VarClass.ReadIN[14] || !VarClass.ReadIN[17]) //左,右气缸回限
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            Thread.Sleep(5);
                        }
                    }
                    Thread.Sleep(500);
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("左,右气缸到回限,下步小Z轴下", Color.Black);
                        });
Auto5:
                    AxisMove(1, VarClass.AutoSpeed[1], VarClass.SmallZ_Location[1]);           //小Z轴下

                    while ((LTDMC.dmc_check_done(0, 1) == 0) || (VarClass.SmallZ_Location[1] != VarClass.Pulse_Current[1]))
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 1, 0);           //XAxis停止


                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Auto5;
                            }
                        }
                    }
                    VarClass.ImpactCurrentNum[VarClass.TestNumber - 1] = VarClass.ImpactCurrentNum[VarClass.TestNumber - 1] + 1;
                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("小轴到位,下步左右气缸出", Color.Black);
                        });
                    AutoStep = 10;
                    break;
                }

                case 10:
                {
                    //PublicClass.WriteOUT(0, 12, 0);//左气缸出
                    //PublicClass.WriteOUT(0, 13, 1);
                    PublicClass.WriteOUT(0, 6, 0);                       //左右气缸出
                    PublicClass.WriteOUT(0, 7, 1);
                    while (!VarClass.ReadIN[13] || !VarClass.ReadIN[16]) //左,右气缸出限
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            Thread.Sleep(5);
                        }
                    }

                    if ((VarClass.ImpactCurrentNum[VarClass.TestNumber - 1] < Convert.ToInt32(VarClass.Excel_specificationsNum[VarClass.TestNumber - 1])) && VarClass.StopState != "outing")
                    {
                        myFrMain.Invoke((MethodInvoker) delegate
                            {
                                myFrMain.addLog("左,右气缸到出限,下步小Z轴上", Color.Black);
                            });
Auto10:
                        AxisMove(1, VarClass.AutoSpeed[1], VarClass.SmallZ_Location[0]);           //小Z轴到上位
                        while ((LTDMC.dmc_check_done(0, 1) == 0) || (VarClass.SmallZ_Location[0] != VarClass.Pulse_Current[1]))
                        {
                            while (VarClass.Pause_Flag)
                            {
                                PublicClass.AxisStop(0, 1, 0);           //XIAOZ轴轴停止

                                Thread.Sleep(5);
                                if (!VarClass.Pause_Flag)
                                {
                                    goto Auto10;
                                }
                            }
                        }

                        AutoStep = 5;
                        break;
                    }
                    else
                    {
                        myFrMain.Invoke((MethodInvoker) delegate
                            {
                                myFrMain.addLog("左,右气缸到出限,下步大小Z轴上", Color.Black);
                            });
                        //  VarClass.ImpactCurrentNum[VarClass.TestNum-1] = 0;
                        AutoStep = 6;
                        break;
                    }
                }

                case 6:
                {
Auto6:
                    AxisMove(0, VarClass.AutoSpeed[0], VarClass.BigZ_Location[0]);           //大Z轴到上位
                    AxisMove(1, VarClass.AutoSpeed[1], VarClass.SmallZ_Location[0]);         //小Z轴到上位
                    while ((LTDMC.dmc_check_done(0, 0) == 0) || (VarClass.BigZ_Location[0] != VarClass.Pulse_Current[0]) || (LTDMC.dmc_check_done(0, 1) == 0) || (VarClass.SmallZ_Location[0] != VarClass.Pulse_Current[1]))
                    {
                        Thread.Sleep(5);
                        while (VarClass.Pause_Flag)
                        {
                            PublicClass.AxisStop(0, 0, 0);           //大Z轴停止
                            PublicClass.AxisStop(0, 1, 0);           //大Z轴轴停止

                            Thread.Sleep(5);
                            if (!VarClass.Pause_Flag)
                            {
                                goto Auto6;
                            }
                        }
                    }

                    if (VarClass.StopState == "outing")
                    {
                    }
                    else

                    {
                        HttpVar.end_time[VarClass.TestNumber - 1] = (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).ToString();
                        VarClass.TestEnd[VarClass.TestNumber - 1] = true;        //测试完成
                        VarClass.Testing = false;
                    }


                    myFrMain.Invoke((MethodInvoker) delegate
                        {
                            myFrMain.addLog("大小轴到位,下步XY轴到换料位", Color.Black);
                        });
                    AutoStep = 1;
                    break;
                }
                }
            }
        }