/// <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); }
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); }
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()); }
//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); } }
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)); } } }
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); }
/// <summary> /// 卡初始化 /// </summary> /// <param name="card"></param>4 /// <param name="axisCount"></param> /// <param name="configFileName"></param> /// <returns></returns> public short _SR_InitCard() { ushort _num = 0; if (tag_isInit == 0) { short returnValue = LTDMC.dmc_board_init(); //获取卡数量 tag_isInit = 1; tag_CardCount = returnValue; if (returnValue <= 0 || returnValue > 8) { string str = "DMC3" + tag_AxisCount + "00控制卡初始化失败!"; if (returnValue == 0) { str = str + "\r\n没有安装雷赛卡"; } if (returnValue == -1) { str = str + "没有安装端口驱动程序!"; } if (returnValue == -2) { str = str + "PCI桥故障!"; } MessageBoxLog.Show(str); return(-1); } } short res = LTDMC.dmc_get_CardInfList(ref _num, tag_cardtypes, tag_cardids); if (res != 0) { MessageBoxLog.Show("获取卡信息失败!"); } short i = 0; short retCount = 0; while (i < _num) { short j = 0; uint TotalAxis = 0; LTDMC.dmc_get_total_axes(tag_cardids[i], ref TotalAxis); if (TotalAxis == tag_AxisCount) { retCount++; } while (j < TotalAxis) { _SR_SetEncPos(i, j, 0); j++; } i++; } return(retCount); }
public int IPrimInit() { var ret = LTDMC.dmc_board_init(); if (ret == 0) { throw new Exception("not found leisai card"); } //csLTDMC.LTDMC.dmc_soft_reset((ushort)DevIndex); return(0); }
private void AppLoadedEventCommandExecute() { short num = LTDMC.dmc_board_init();//获取卡数量 if (num <= 0 || num > 8) { AddMessage("初始卡失败!"); } else { ushort _num = 0; ushort[] cardids = new ushort[8]; uint[] cardtypes = new uint[8]; Res = LTDMC.dmc_get_CardInfList(ref _num, cardtypes, cardids); if (Res != 0) { AddMessage("获取卡信息失败!"); } else { _CardID = cardids[0]; Res = LTDMC.dmc_download_configfile(_CardID, "Motion.ini"); if (Res == 0) { Res = LTDMC.nmc_set_connect_state(_CardID, 1, 1, 0); if (Res != 0) { AddMessage("CANOpen异常"); } else { ushort NodeNum = 0, _state = 0; LTDMC.nmc_get_connect_state(_CardID, ref NodeNum, ref _state); if (_state != 1) { AddMessage("CANOpen异常"); } else { LTDMC.nmc_set_ad_mode(_CardID, 1, 0, 1, 0); AddMessage("软件加载完成"); Run(); } } } } } }
/// <summary> /// 初始化控制卡 /// </summary> /// <returns></returns> public bool InitMotionCard() { short num = LTDMC.dmc_board_init();//获取卡数量 if (num <= 0 || num > 8) { 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("获取卡信息失败!"); } _CardID = cardids[0]; return(true); }
/// <summary> /// 初始化轴 /// </summary> /// <returns></returns> public bool DoOpen() { short mCardCount = LTDMC.dmc_board_init();//获取卡数量 isOnline = (mCardCount > 0); if (isOnline) { for (int axis = 0; axis < define_AxisNum.wd_axis_count; axis++) { //设置脉冲方式 LTDMC.dmc_set_pulse_outmode(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode, 1); //设置减速停止时间ms LTDMC.dmc_set_dstp_time(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode, 50); if (AxisInfoList[axis].isLimit) { //设置 EL 限位信号。目前设置正负限位允许,正负限位低电平有效,正负限位立即停止 LTDMC.dmc_set_el_mode(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode, 1, 0, 0); //设置轴原点信号,低有效 LTDMC.dmc_set_home_pin_logic(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode, 0, 0); } if (AxisInfoList[axis].isServo) { LTDMC.dmc_set_alm_mode(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode, 0, 0, 0); LTDMC.dmc_write_sevon_pin(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode, 0); } else { LTDMC.dmc_set_alm_mode(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode, 1, 0, 0); LTDMC.dmc_write_sevon_pin(AxisInfoList[axis].AxisCard, AxisInfoList[axis].AxisCode, 1); } DoSoftLimit(axis, false); } } return(isOnline); }
//控制卡初始化程序 public bool DoOpen() //控制卡初始化函数 { short mCardCount = LTDMC.dmc_board_init(); //获取卡数量 isOnline = (mCardCount > 0); if (isOnline) { for (int axis = 0; axis < 8; axis++) { //设置脉冲方式 LTDMC.dmc_set_pulse_outmode(pAxis[axis].AxisCard, pAxis[axis].AxisCode, 1); //设置减速停止时间ms LTDMC.dmc_set_dstp_time(pAxis[axis].AxisCard, pAxis[axis].AxisCode, 50); if (pAxis[axis].isLimit) { //设置 EL 限位信号。目前设置正负限位允许,正负限位低电平有效,正负限位立即停止 LTDMC.dmc_set_el_mode(pAxis[axis].AxisCard, pAxis[axis].AxisCode, 1, 0, 0); //设置轴原点信号,低有效 LTDMC.dmc_set_home_pin_logic(pAxis[axis].AxisCard, pAxis[axis].AxisCode, 0, 0); } if (pAxis[axis].isServo) { LTDMC.dmc_set_alm_mode(pAxis[axis].AxisCard, pAxis[axis].AxisCode, 0, 0, 0); } else { LTDMC.dmc_set_alm_mode(pAxis[axis].AxisCard, pAxis[axis].AxisCode, 1, 0, 0); } DoSoftLimit(axis, false); } } return(isOnline); }
public bool Initialize() { LTDMC.dmc_board_init(); return(true); }
/// <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.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(); 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 Robot(_cardid); //查询主机上存在的串口 comboBox_port.Items.AddRange(SerialPort.GetPortNames()); if (comboBox_port.Items.Count > 0) { comboBox_port.SelectedIndex = 0; } else { comboBox_port.Text = "未检测到串口"; } comboBox_bitrate.SelectedIndex = 0; m_thread = new Thread(Display); m_thread.Start(); robot1.PlotRobot = true;//开启图像仿真 timer1.Start(); // double[] q0 = new double[6] { PI / 2, PI / 2, 0, 0, 0, 0 }; //PaintRobot(q0); }
/// <summary> /// 初始化板卡。 /// 如有主次卡之分,请先初始化主卡。关闭则相反,先关从卡再关主卡。 /// </summary> /// <param name="id">卡ID</param> /// <param name="maincard_id">主卡ID</param> /// <param name="ip">卡IP</param> /// <param name="filename">配置文件路径</param> /// <returns></returns> public EM_RES Init(int card_id = -1, int maincard_id = -1, string ip = "", string filename = "") { if (isReady) { return(EM_RES.OK); } int ret = 0; EM_RES res = EM_RES.OK; //update id if (card_id >= 0) { this.card_id = card_id; } else { card_id = this.card_id; } //update ip if (ip.Length > 7) { this.ip = ip; } else { ip = this.ip; } //update maincard_id if (maincard_id >= 0) { this.maincard_id = maincard_id; } else { maincard_id = this.maincard_id; } #if LEADSHINE if (brand == BRAND.LEADSHINE) { if (type == TYPE.MOTION) { //init card ret = LTDMC.dmc_board_init(); if (ret < 0) { VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("{0}ID有重复,请检查确认!0x{1:X8}", disc, ret)); return(EM_RES.ERR); } //get card list ushort cardnum = 0; ushort[] cardid = new ushort[64]; uint[] cardtype = new uint[64]; ret = LTDMC.dmc_get_CardInfList(ref cardnum, cardtype, cardid); if (ret != 0) { VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("获取{0}列表错误,0x{1:X8}", disc, ret)); return(EM_RES.ERR); } //search card list bool bfound = false; for (int n = 0; n < cardnum; n++) { if (card_id == cardid[n]) { bfound = true; break; } } if (!bfound) { isInit = false; VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("{0}列表找不到ID为{1}的板卡!", disc, card_id)); return(EM_RES.ERR); } //download config res = DownLoadFile(filename); if (res != EM_RES.OK) { return(res); } isInit = true; handle = (IntPtr)1; VAR.msg.AddMsg(Msg.EM_MSGTYPE.SYS, string.Format("{0}初始化成功!", disc)); return(EM_RES.OK); } else if (type == TYPE.CAN_IO) { //连接IO卡 ret = LTDMC.dmc_set_can_state((ushort)maincard_id, (ushort)card_id, 1, 0); if (ret != 0) { VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("{0}连接失败,Err:0x{1:X8},重新连接...", disc, ret)); ret = LTDMC.dmc_set_can_state((ushort)maincard_id, (ushort)card_id, 1, 0); if (ret != 0) { VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("{0}重新连接失败,请确认卡连接是否正确!Err:0x{1:X8}", disc, ret)); return(EM_RES.ERR); } } isInit = true; handle = (IntPtr)1; VAR.msg.AddMsg(Msg.EM_MSGTYPE.SYS, string.Format("{0}初始化成功!", disc)); return(EM_RES.OK); } #if LEADSHINE_IO else if (type == TYPE.IO) { ret = IOC0640.ioc_board_init(); if (ret > 0) { isInit = true; handle = (IntPtr)1; VAR.msg.AddMsg(Msg.EM_MSGTYPE.SYS, string.Format("{0}初始化成功!", disc)); return(EM_RES.OK); } else { IOC0640.ioc_board_close(); isInit = false; handle = (IntPtr)0; VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("{0}初始化失败!Err:0x{1:X8}", disc, ret)); return(EM_RES.ERR); } } #endif } #endif #if ZMOTION if (brand == BRAND.ZMOTION) { //check ip if (ip.Length < 7) { isInit = false; handle = (IntPtr)0; VAR.msg.AddMsg(Msg.EM_MSGTYPE.SYS, string.Format("{0} IP异常,{1}", disc, ip)); return(EM_RES.CAM_PARA_ERR); } VAR.msg.AddMsg(Msg.EM_MSGTYPE.SYS, string.Format("{0} 连接...", disc)); ////search and open,多网卡时,搜索异常 //for (int n = 0; n < 10; n++) //{ // ret = zmcaux.ZAux_SearchEth(ip, 100); // if (ret == 0) break; // Application.DoEvents(); //} ret = 0; if (ret == 0) { ret = zmcaux.ZAux_OpenEth(ip, out handle); if (ret != 0) { isInit = false; handle = (IntPtr)0; VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("{0}初始化失败,IP={1},Err:{2}", disc, ip, ret)); return(EM_RES.ERR); } else { //check param int ftemp = 0; bool bdownload = false; foreach (AXIS ax in AxList) { zmcaux.ZAux_Direct_GetMaxSpeed(handle, ax.num, ref ftemp); if (Math.Abs((ax.max_spd * ax.pul_per_mm) - ftemp) > 100) { bdownload = true; break; } } //download config if (bdownload) { res = DownLoadFile(filename); if (res != EM_RES.OK) { return(res); } } isInit = true; VAR.msg.AddMsg(Msg.EM_MSGTYPE.SYS, string.Format("{0}初始化成功!", disc)); foreach (AXIS ax in AxList) { ax.Init(); } return(EM_RES.OK); } } else { isInit = false; handle = (IntPtr)0; VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("{0}找不到,IP={1}", disc, ip)); return(EM_RES.ERR); } } #endif #if ADVANTTECH if (brand == BRAND.ADVANTTECH) { isInit = false; VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, "研华库未添加!"); return(EM_RES.ERR); } #endif #if ORIENTALMOTOR if (brand == BRAND.ORIENTALMOTOR) { //get config if (filename.Length < 3) { filename = Path.GetFullPath("..") + "\\syscfg\\ORIENTALMOTOR.ini"; } if (File.Exists(filename)) { IniFile inf = new IniFile(filename); int temp = inf.ReadInteger("COM", "PORT", -1); if (temp >= 0 && temp < 100) { PortName = string.Format("COM{0}", temp); } temp = inf.ReadInteger("COM", "BAUD", -1); if (temp > 0) { Baudrate = temp; } } if (0 == AZD.Motor.InitRs485(PortName, Baudrate)) { isInit = true; handle = (IntPtr)1; VAR.msg.AddMsg(Msg.EM_MSGTYPE.SYS, string.Format("{0}初始化成功!", disc)); foreach (AXIS ax in AxList) { ax.Init(); } return(EM_RES.OK); } else { VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("InitRs485异常,BRAND={0},TYPE={1},Port={2}/{3}", brand, type, PortName, Baudrate)); return(EM_RES.ERR); } } #endif VAR.msg.AddMsg(Msg.EM_MSGTYPE.ERR, string.Format("未定义异常,BRAND={0},TYPE={1}", brand, type)); return(EM_RES.ERR); }
private void Form1_Load(object sender, EventArgs e) { LTDMC.dmc_board_init(); }