Example #1
0
 // 更新脉冲数
 private void UpdateDMC3400Pulse()
 {
     stageXPulseEdit.Text = Convert.ToString(LTDMC.dmc_get_position(m_dmc3400ACard.m_cardNo, 0));
     stageYPulseEdit.Text = Convert.ToString(LTDMC.dmc_get_position(m_dmc3400ACard.m_cardNo, 1));
     CCDXPulseEdit.Text   = Convert.ToString(LTDMC.dmc_get_position(m_dmc3400ACard.m_cardNo, 2));
     CCDZPulseEdit.Text   = Convert.ToString(LTDMC.dmc_get_position(m_dmc3400ACard.m_cardNo, 3));
 }
Example #2
0
        public ushort GetErrorCode()
        {
            ushort errcode = 0;

            LTDMC.nmc_get_errcode(CarNum, 2, ref errcode);
            return(errcode);
        }
Example #3
0
        public bool   resetCar()     // 重启运动控制卡      报警
        {
            LTDMC.dmc_soft_reset(CarNum);
            LTDMC.dmc_board_reset();
            LTDMC.dmc_board_close();

            for (int i = 0; i < 15; i++)//总线卡软件复位耗时15s左右
            {
                Thread.Sleep(1000);
                Global.frmMain.PushMess(i + "/15....");
            }
            var a = LTDMC.dmc_board_init();

            Global.frmMain.PushMess("Card Number: " + a + "");
            if (a > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
            // Axis.nmc_get_errcode(MyGlobal._CarId, 2, ref errcode);
            //  mess_textBox.AppendText("总线卡软件复位完成,请确认总线状态" + errcode.ToString());
        }
Example #4
0
        /// <summary>
        /// 获取单卡 正极限输入状态
        /// </summary>
        /// <param name="card"></param>
        /// <param name="pValue"></param>
        /// <returns></returns>
        public short _SR_GetLimitPInput(short card, short axisNum, out bool pValue)
        {
            pValue = false;
            if (tag_CardCount < 1 || card >= tag_CardCount)
            {
                return(-1);
            }
            uint status = LTDMC.dmc_axis_io_status((ushort)tag_cardids[card], (ushort)axisNum);

            if (card == 0 && axisNum == 0)
            {
            }

            int bit = (int)Math.Pow(2, 1);

            if ((status & bit) == bit)
            {
                pValue = true;
            }
            else
            {
                pValue = false;
            }
            return(0);
        }
Example #5
0
        //1.板卡设置功能--
        #region                  //检查控制卡数量      返回卡号
        public bool CarInitial() //检查控制卡数量      返回卡号
        {
            int carNub = 0;

            try
            {
                short num = LTDMC.dmc_board_init();//获取卡数量
                if (num <= 0 || num > 8)
                {
                    //MessageBox.Show("初始卡失败!", "出错");
                    CarErrCode = 1;
                    return(false);
                }
                ushort   _num      = 0;
                ushort[] cardids   = new ushort[8];
                uint[]   cardtypes = new uint[8];
                short    res       = LTDMC.dmc_get_CardInfList(ref _num, cardtypes, cardids);
                if (res != 0)
                {
                    CarErrCode = 2;
                    // MessageBox.Show("获取卡信息失败!");
                    return(false);
                }
                CarNum = cardids[0];
                return(true);
            }
            catch (Exception ex)
            {
                //   MessageBox.Show(ex.Message);
                CarErrCode = 3;
                return(false);
            }
        }
Example #6
0
        /// <summary>
        /// 单轴绝对运动
        /// </summary>
        /// <param name="card"></param>
        /// <param name="axis"></param>
        /// <param name="postion">目标点位</param>
        /// <param name="speed">速度</param>
        /// <returns></returns>
        public short _SR_AbsoluteMove(AxisConfig axisC, PointModule point)
        {
            short shrResult = 0;

            if (point.dblPonitSpeed == 0.0)
            {
                MessageBoxLog.Show(axisC.AxisName + "速度设置位0,急停请设置");
                return(-1);
            }

            if (tag_CardCount < 1 || axisC.CardNum >= tag_CardCount)
            {
                return(-1);
            }
            LTDMC.dmc_set_s_profile((ushort)tag_cardids[axisC.CardNum], (ushort)axisC.AxisNum, 0, point.db_S_Time);                                                                          //设置S段时间(0-0.05s)
            LTDMC.dmc_set_profile((ushort)tag_cardids[axisC.CardNum], (ushort)axisC.AxisNum, axisC.StartSpeed, point.dblPonitSpeed, point.db_StopSpeed, point.dblAccTime, point.dblDecTime); //设置起始速度、运行速度、停止速度、加速时间、减速时间
            shrResult = LTDMC.dmc_pmove((ushort)tag_cardids[axisC.CardNum], (ushort)axisC.AxisNum, (int)(point.dblPonitValue * axisC.Eucf), 1);                                              //定长运动


            if (shrResult != shrGtsSuccess)
            {
                CommandResult("_SR_RelativeMove", shrResult);
                return(shrFail);
            }
            return(shrResult);
        }
        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");
                }
            }
        }
 public static void AxisStop(ushort CardNo, ushort Axis, ushort Stop_mode)
 {
     lock (Lock2)
     {
         LTDMC.dmc_stop(CardNo, Axis, Stop_mode);
     }
 }
        //控制卡的输入端
        public uint DoInput()
        {
            uint vio1 = LTDMC.dmc_read_inport(0, 0);//读0卡IO输入

            IoInput = ~((vio1 & 0xffff));
            return(IoInput);
        }
Example #10
0
        public ushort Check_Enable()
        {
            ushort Axis_State_machine = 0;

            LTDMC.nmc_get_axis_state_machine(_CardID, axis, ref Axis_State_machine);
            return(Axis_State_machine);
        }
 public static void WriteOUT(ushort CardNum, ushort Bitno, ushort On_Off)
 {
     lock (Lock0)
     {
         LTDMC.dmc_write_outbit(CardNum, (ushort)(Bitno + 8), On_Off);//0打开,1关闭
     }
 }
Example #12
0
 /// <summary>
 /// 连续运动
 /// </summary>
 /// <param name="axis"></param>
 /// <param name="start"></param>
 /// <param name="speed"></param>
 /// <param name="stop"></param>
 /// <param name="acc"></param>
 /// <param name="dec"></param>
 /// <param name="Direct"></param>
 public void ContinuationMove(ushort axis, double start, double speed, double stop, double acc, double dec, ushort Direct)
 {
     LTDMC.dmc_set_pulse_outmode(_CardID, axis, 0);                      //设置脉冲模式
     LTDMC.dmc_set_s_profile(_CardID, axis, 0, 0.01);                    //设置S段时间(0-0.05s)
     LTDMC.dmc_set_profile(_CardID, axis, start, speed, acc, dec, stop); //设置起始速度、运行速度、停止速度、加速时间、减速时间
     LTDMC.dmc_vmove(_CardID, axis, Direct);                             //连续运动
 }
Example #13
0
        private void label_Click(object sender, EventArgs e)
        {
            int index = -1;

            foreach (Label label in groupBox2.Controls)
            {
                if (label == sender)
                {
                    index = Convert.ToInt32(label.Text);
                    break;
                }
            }
            if (index > -1)
            {
                short state = LTDMC.dmc_read_outbit(m_cardID, (ushort)index);
                if (state == 0)
                {
                    LTDMC.dmc_write_outbit(m_cardID, (ushort)index, 1);
                }
                else
                {
                    LTDMC.dmc_write_outbit(m_cardID, (ushort)index, 0);
                }
            }
        }
Example #14
0
        /// <summary>
        /// 初始化运动控制卡,仅初始化一次
        /// </summary>
        /// <param name="cardNum">控制卡号</param>
        /// <param name="isRun">是否初始化</param>
        /// <returns>是否初始化成功</returns>
        public static bool InitMotionCard(ref short cardNum, bool isRun)
        {
            IsRun = isRun;
            if (IsRun)
            {
                return(true);
            }

            try
            {
                cardNum = LTDMC.dmc_board_init();
                if (cardNum <= 0 || cardNum > 8)
                {
                    MessageBox.Show("初始化控制卡失败!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    return(false);
                }

                ushort   _num      = 0;
                ushort[] cardids   = new ushort[8];
                uint[]   cardtypes = new uint[8];
                short    res       = LTDMC.dmc_get_CardInfList(ref _num, cardtypes, cardids);
                if (res != 0)
                {
                    MessageBox.Show("获取卡信息失败!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                CardId = cardids[0];
            }
            catch (Exception ex)
            {
                m_logFile.AppendText("运动控制卡初始化异常:" + ex.Message);
                return(false);
            }
            return(true);
        }
        private void FrMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            LTDMC.dmc_emg_stop(0);  //停轴


            LTDMC.nmc_set_axis_disable(0, 0);
            LTDMC.nmc_set_axis_disable(0, 1);
            LTDMC.nmc_set_axis_disable(0, 2);
            LTDMC.nmc_set_axis_disable(0, 3);
            LTDMC.nmc_set_axis_disable(0, 4);
            LTDMC.dmc_board_close();
            if (VarClass.Homeing)   //归零中
            {
                myPublicClass.myHomeThread.Abort();
            }
            if (VarClass.Autoing)   //自动中
            {
                myPublicClass.myAutoThread.Abort();
            }
            myCycleThread.Abort();
            try
            {
                Environment.Exit(0);
            }
            catch (Exception ex)
            { }
        }
Example #16
0
        static void LSConnectDetail()
        {
            short i = LTDMC.dmc_board_init();

            if (i <= 0 || i > 8)
            {
                throw new Exception($"雷赛卡初始化错误,返回值:{i}");
            }
            else
            {
                ushort   _num      = 0;
                ushort[] cardIDs   = new ushort[8];
                uint[]   cardTypes = new uint[8];
                short    res       = LTDMC.dmc_get_CardInfList(ref _num, cardTypes, cardIDs);

                if (res != 0)
                {
                    throw new Exception($"雷赛卡无法获取卡信息,错误代码:{res}");
                }

                foreach (ControllerListSource cls in
                         IODataCollection.controllerNameList.Where(c => c.name.StartsWith(_name + '-')))
                {
                    string s = string.Join(",", cardIDs).TrimEnd(',');
                    if ((Array.IndexOf(cardIDs, ushort.Parse(cls.IP)) == -1) ||
                        ((int.Parse(cls.IP) == 0) && (cardIDs[0] != 0)))
                    {
                        throw new Exception($"雷赛卡卡号不存在:{cls.IP},卡号列表:{s}");
                    }
                    LSu.Connect(cls.name, int.Parse(cls.IP));
                }
            }
        }
Example #17
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);
            }
        }
Example #18
0
        public bool AxisHMV(int motionDevIndex, int axis)
        {
            ushort state = 0;
            var    ret   = LTDMC.dmc_get_home_result((ushort)DevIndex, (ushort)axis, ref state);

            return(state == 1);
        }
Example #19
0
        public bool IsAxisHmv(int index, int axis)
        {
            ushort state = 0;
            var    ret   = LTDMC.dmc_get_home_result((ushort)Id, (ushort)axis, ref state);

            return(state != 1);
        }
Example #20
0
        public bool InitDMC3400ACard()
        {
            short num = LTDMC.dmc_board_init();//获取卡数量

            if (num <= 0 || num > 8)
            {
                MessageBox.Show("初始卡失败!", "出错");
                return(false);
            }
            ushort _num = 0;

            ushort[] cardids   = new ushort[8];
            uint[]   cardtypes = new uint[8];
            short    res       = LTDMC.dmc_get_CardInfList(ref _num, cardtypes, cardids);

            if (res != 0)
            {
                MessageBox.Show("获取卡信息失败!");
                return(false);
            }
            m_cardNo = cardids[0];

            for (ushort i = 0; i < m_axisCount; i++)
            {
                // 设定脉冲模式及逻辑方向
                LTDMC.dmc_set_pulse_outmode(m_cardNo, i, 4);
                // 设置 EL 限位信号
                LTDMC.dmc_set_el_mode(m_cardNo, i, 1, 1, 0);
                // 设置编码器的计数方式
                LTDMC.dmc_set_counter_inmode(m_cardNo, i, 0);
                //设置指定轴的 EZ 信号
                //LTDMC.dmc_set_ez_mode(m_cardNo, i, 0);
            }
            return(true);
        }
Example #21
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            GetAxisLimitedSensor(0, ref homeSensor0, ref posLimited0, ref negLimited0);
            GetAxisLimitedSensor(1, ref homeSensor1, ref posLimited1, ref negLimited1);
            GetAxisLimitedSensor(2, ref homeSensor2, ref posLimited2, ref negLimited2);
            GetAxisLimitedSensor(3, ref homeSensor3, ref posLimited3, ref negLimited3);
            SetCondition();
            //输入口
            uint n = LTDMC.dmc_read_inport(m_cardID, 0);

            for (int i = 0; i < 16; i++)
            {
                Label lable = GetINLabel(i);
                if (label1 != null)
                {
                    SetIOStateColor(lable, (n & 1) == 1);
                }
                n = n >> 1;//n右移一位
            }

            //输出口
            n = LTDMC.dmc_read_outport(m_cardID, 0);
            for (int i = 0; i < 16; i++)
            {
                Label label = GetOUTLabel(i);
                if (label1 != null)
                {
                    SetIOStateColor(label, (n & 1) == 1);
                }
                n = n >> 1;
            }
        }
Example #22
0
        //获取对应感应器信号
        public void Getsing(ref bool[] sing)
        {
            uint IoState = LTDMC.dmc_axis_io_status(_CardID, axis);

            if ((IoState & 2) == 2)//检测正限位信号
            {
                sing[0] = true;
            }
            else
            {
                sing[0] = false;
            }
            if ((IoState & 4) == 4)//检测负限位信号
            {
                sing[1] = true;
            }
            else
            {
                sing[1] = false;
            }
            if ((IoState & 16) == 16)//检测原点信号
            {
                sing[2] = true;
            }
            else
            {
                sing[2] = false;
            }
        }
Example #23
0
        public ushort GetAxisStatus()
        {
            ushort Axis_State_machine2 = 0;

            LTDMC.nmc_get_axis_state_machine(_CardID, 2, ref Axis_State_machine2);
            return(Axis_State_machine2);
        }
        public static void AxisInitialize()
        {
            short Cardnum = 0;


            Cardnum = LTDMC.dmc_board_init();
            if (Cardnum > 0 && Cardnum < 8)
            {
                //  MessageBox.Show("找到控制卡!" + Cardnum);
            }
            else
            {
                MessageBox.Show("未找到控制卡!");
                return;
            }


            Thread.Sleep(500);
            ushort err = 0;
            short  res = LTDMC.dmc_soft_reset(0);

            if (res != 0)
            {
                MessageBox.Show("复位错误" + res.ToString());
            }
            Thread.Sleep(3000);
            LTDMC.nmc_set_axis_enable(0, 0);
            LTDMC.nmc_set_axis_enable(0, 1);
            LTDMC.nmc_set_axis_enable(0, 2);
            LTDMC.nmc_set_axis_enable(0, 3);
            LTDMC.nmc_set_axis_enable(0, 4);
        }
 /// <summary>
 /// 界面初始化
 /// </summary>
 public 打孔器机械臂界面()
 {
     #region 设置listview
     this.listView1.Font          = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
     this.listView1.FullRowSelect = true;
     this.listView1.HideSelection = false;
     this.listView1.GridLines     = true;
     this.listView1.Location      = new System.Drawing.Point(5, 41);
     this.listView1.Name          = "listView1";
     this.listView1.Size          = new System.Drawing.Size(425, 206);
     this.listView1.TabIndex      = 20;
     this.listView1.UseCompatibleStateImageBehavior = false;
     this.listView1.View = System.Windows.Forms.View.Details;
     listView1.Visible   = false;//使listview1不可见
     listView1.Clear();
     listView1.Columns.Add("步数", 65, System.Windows.Forms.HorizontalAlignment.Left);
     listView1.Columns.Add("x位置", 60, System.Windows.Forms.HorizontalAlignment.Left);
     listView1.Columns.Add("y位置", 60, System.Windows.Forms.HorizontalAlignment.Left);
     listView1.Columns.Add("z位置", 60, System.Windows.Forms.HorizontalAlignment.Left);
     listView1.Columns.Add("a位置", 60, System.Windows.Forms.HorizontalAlignment.Left);
     listView1.Columns.Add("b位置", 60, System.Windows.Forms.HorizontalAlignment.Left);
     listView1.Columns.Add("c位置", 60, System.Windows.Forms.HorizontalAlignment.Left);
     this.Controls.Add(listView1);
     #endregion
     checkstep.OntempChange += new EventCheckChange.tempChange(event_stepchange);
     InitializeComponent();
     button_cycle_start.Enabled = false;
     short num = LTDMC.dmc_board_init();//获取卡数量
     board_num = num;
     if (num <= 0 || num > 6)
     {
         MessageBox.Show("初始卡失败!", "出错");
     }
     ushort   _num      = 0;
     ushort[] cardids   = new ushort[6];
     uint[]   cardtypes = new uint[6];
     short    res       = LTDMC.dmc_get_CardInfList(ref _num, cardtypes, cardids);
     if (res != 0)
     {
         MessageBox.Show("获取卡信息失败!");
     }
     _cardid = cardids[0];
     InitializationCalculate();//初始化matlab
     //InitializationPlot();//
     robot1   = new HoleRobot(_cardid);
     m_thread = new Thread(Display);
     m_thread.Start();
     robot1.PlotRobot = true;//开启图像仿真
     timer1.Start();
     timer_Hole.Start();
     robot1.PropertyChanged    += PropertyChangedManage;
     button6.Enabled            = true;
     button2.Enabled            = true;
     button_cycle_start.Enabled = false;
     button3.Enabled            = false;
     userControl11.Enabled      = false;
     //  double[] q0 = new double[6] { PI / 2, PI / 2, 0, 0, 0, 0 };
     //PaintRobot(q0);
 }
Example #26
0
        public double GetAxisEncodePos(ushort axis)
        {
            double curPos = 0;

            curPos = LTDMC.dmc_get_encoder(m_cardNo, axis);

            return(curPos);// * m_axisRes[axis];
        }
Example #27
0
        public double GetAxisPulsePos(ushort axis)
        {
            double curPos = 0;

            curPos = LTDMC.dmc_get_position(m_cardNo, axis);

            return(curPos); // * m_axisRes[axis];
        }
Example #28
0
 private void SetPara(ushort axis, double dist)
 {
     LTDMC.dmc_set_equiv(FormMain.CardId, axis, FormMain.PulseEquiv);
     LTDMC.dmc_set_profile_unit(FormMain.CardId, axis, FormMain.StartSpeed, FormMain.MoveSpeed, FormMain.AccTime, FormMain.DecTime, FormMain.StopSpeed);
     LTDMC.dmc_set_s_profile(FormMain.CardId, axis, 0, FormMain.SParamSpeed);
     LTDMC.dmc_set_dec_stop_time(FormMain.CardId, axis, FormMain.DecStopTime);
     LTDMC.dmc_pmove_unit(m_cardID, 0, dist, 0);
 }
Example #29
0
        private void btnAxisW_Click(object sender, EventArgs e)
        {
            double dDist;//目标位置

            dDist = Convert.ToDouble(txtFinalPosW.Text);
            setPara(3);
            LTDMC.dmc_pmove_unit(_CardID, 3, dDist, 1);//定长运动
        }
Example #30
0
 public void SetMotionParam(ushort nAxisIndex, AxisParam axisParam)
 {
     // 设置单轴运动速度曲线
     LTDMC.dmc_set_profile(m_cardNo, nAxisIndex, axisParam.nStartSpeed, axisParam.nRunSpeed,
                           axisParam.nAccelerateTime, axisParam.nDecelerateTime, axisParam.nEndSpeed);
     //设定S段时间
     LTDMC.dmc_set_s_profile(m_cardNo, nAxisIndex, 0, axisParam.nSDecelerateTime); //S 段时间,单位:s;范围:0~0.5 s
 }