コード例 #1
0
        public void UpdateChannelsInfo(string devID, int moduleIndex)
        {
            lstTbTrigIDs.Clear();
            pnTrigs.Controls.Clear();
            JFDevCellNameManeger  mgr = JFHubCenter.Instance.MDCellNameMgr;
            IJFModule_CmprTrigger md  = null;
            IJFDevice_MotionDaq   dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq;

            if (dev != null && dev.CompareTriggerCount > moduleIndex)
            {
                md = dev.GetCompareTrigger(moduleIndex);
            }
            int trigChannCount = mgr.GetCmpTrigCount(devID, moduleIndex);

            for (int i = 0; i < trigChannCount; i++)
            {
                Label lb = new Label();
                lb.Location = new Point(2, 2 + 5 + 33 * i);
                lb.Text     = "序号:" + i.ToString("D2") + "名称:";
                pnTrigs.Controls.Add(lb);
                TextBox tbID = new TextBox();
                tbID.Location  = new Point(lb.Right, 2 + 33 * i);
                tbID.Text      = mgr.GetCmpTrigName(devID, moduleIndex, i);
                tbID.BackColor = SystemColors.Control;
                tbID.ReadOnly  = true;
                tbID.Width     = 200;
                pnTrigs.Controls.Add(tbID);
                lstTbTrigIDs.Add(tbID);
                UcCmprTrgChn ucTrig = new UcCmprTrgChn();
                ucTrig.Location = new Point(tbID.Right, 2 + 33 * i);
                ucTrig.SetModuleChn(md, i, "", null);
                pnTrigs.Controls.Add(ucTrig);
            }
        }
コード例 #2
0
 public void SetDevice(IJFDevice_MotionDaq dev, string id)
 {
     _dev = dev;
     _id  = id;
     if (_isFormLoaded)
     {
         AdjustUI();
     }
 }
コード例 #3
0
        public void SetAxisName(string axisName)
        {
            _axisName       = axisName;
            gbAxisName.Text = axisName;
            JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(axisName);

            if (null == ci)
            {
                gbAxisName.Text += " 无通道信息";
                ucAxisTest.SetAxis(null, 0);
                cbMode.Enabled = false;
                btCfg.Enabled  = false;
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;

            if (null == dev)
            {
                gbAxisName.Text += " 无设备:" + ci.DeviceID;
                ucAxisTest.SetAxis(null, 0);
                cbMode.Enabled = false;
                btCfg.Enabled  = false;
                return;
            }
            if (!dev.IsDeviceOpen)
            {
                gbAxisName.Text += " 设备未打开";
                ucAxisTest.SetAxis(null, 0);
                cbMode.Enabled = false;
                btCfg.Enabled  = false;
                return;
            }

            if (dev.McCount <= ci.ModuleIndex)
            {
                gbAxisName.Text += " 模块Idx = :" + ci.ModuleIndex + " 超限";
                ucAxisTest.SetAxis(null, 0);
                cbMode.Enabled = false;
                btCfg.Enabled  = false;
                return;
            }
            IJFModule_Motion md = dev.GetMc(ci.ModuleIndex);

            if (ci.ChannelIndex >= md.AxisCount)
            {
                gbAxisName.Text += " 轴Idx = :" + ci.ChannelIndex + " 超限";
                ucAxisTest.SetAxis(null, 0);
                cbMode.Enabled = false;
                btCfg.Enabled  = false;
                return;
            }
            ucAxisTest.SetAxis(md, ci.ChannelIndex);
            cbMode.Enabled = true;
            btCfg.Enabled  = true;
            return;
        }
コード例 #4
0
        void DOButtonClicked(object sender, EventArgs eventArgs)
        {
            LampButton doBt   = sender as LampButton;
            string     doName = doBt.Text;

            JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDoCellInfo(doName);

            if (ci == null) //名称在配置中不存在
            {
                ShowTips("DO操作失败:名称 \"" + doName + "\" 不存在");
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;

            if (null == dev)
            {
                ShowTips(string.Format("DO: \"{0}\" 操作失败:所属设备 \"{1}\" 在系统中不存在", doName, ci.DeviceID));
                return;
            }
            if (!dev.IsDeviceOpen)
            {
                ShowTips(string.Format("DO \"{0}\" 操作失败:所属设备 \"{1}\" 未打开(关闭状态)", doName, ci.DeviceID));
                return;
            }
            if (dev.DioCount <= ci.ModuleIndex)
            {
                ShowTips(string.Format("DO \"{0}\" 操作失败:所属设备 \"{1}\" 所属模块Index = {2} 超出范围0~{3}", doName, ci.DeviceID, ci.ModuleIndex, dev.DioCount == 0 ? 0 : dev.DioCount - 1));
                return;
            }
            IJFModule_DIO md = dev.GetDio(ci.ModuleIndex);

            if (md.DOCount <= ci.ChannelIndex)
            {
                ShowTips(string.Format("DO \"{0}\" 操作失败:通道序号:{1} 超出范围0~{2}", doName, ci.ChannelIndex, md.DOCount == 0 ? 0 : md.DOCount - 1));
                return;
            }
            bool isON    = false;
            int  errCode = md.GetDO(ci.ChannelIndex, out isON);

            if (0 != errCode)
            {
                ShowTips(string.Format("DO \"{0}\" 操作失败:未能获取当前状态,信息:{1}", doName, md.GetErrorInfo(errCode)));
                return;
            }

            errCode = md.SetDO(ci.ChannelIndex, !isON);
            if (0 != errCode)
            {
                ShowTips(string.Format("DO \"{0}\" {1}操作失败:未能,信息:{2}", doName, isON?"关闭":"打开", md.GetErrorInfo(errCode)));
                return;
            }
        }
コード例 #5
0
        /// <summary>
        /// 将轴状态更新到界面
        /// </summary>
        public void UpdateStationUI()
        {
            int i = 0;

            if (null != _axisNames)
            {
                for (i = 0; i < _axisNames.Length; i++)
                {
                    JFDevCellInfo dcInfo = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(_axisNames[i]);
                    if (dcInfo == null)
                    {
                        tbCurrPoses[i].Text = "无效值";
                        continue;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(dcInfo.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        tbCurrPoses[i].Text = "无效值";
                        continue;
                    }
                    if (dcInfo.ModuleIndex >= dev.McCount)
                    {
                        tbCurrPoses[i].Text = "无效值";
                        continue;
                    }
                    IJFModule_Motion md = dev.GetMc(dcInfo.ModuleIndex);
                    if (dcInfo.ChannelIndex >= md.AxisCount)
                    {
                        tbCurrPoses[i].Text = "无效值";
                        continue;
                    }
                    double pos     = 0;
                    int    errCode = md.GetFbkPos(dcInfo.ChannelIndex, out pos);
                    if (0 != errCode)
                    {
                        tbCurrPoses[i].Text = "获取错误!代码:" + errCode;
                    }
                    else
                    {
                        tbCurrPoses[i].Text = pos.ToString();
                    }

                    bool isServon = md.IsSVO(i);
                    btServons[i].LampColor = isServon ? LampButton.LColor.Green : LampButton.LColor.Gray;
                }
            }
            for (; i < 4; i++)
            {
                tbCurrPoses[i].Text    = "无效值";
                btServons[i].LampColor = LampButton.LColor.Gray;
            }
        }
コード例 #6
0
        public void UpdateChannelsInfo(string devID, int moduleIndex)
        {
            //int nBottom = 0;
            pnAi.Controls.Clear();
            pnAo.Controls.Clear();
            JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr;
            IJFModule_AIO        md  = null;
            IJFDevice_MotionDaq  dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq;

            if (dev != null && dev.DioCount > moduleIndex)
            {
                md = dev.GetAio(moduleIndex);
            }
            int AiCount = mgr.GetAiChannelCount(devID, moduleIndex);

            for (int i = 0; i < AiCount; i++)
            {
                Label lbIndex = new Label();
                lbIndex.Text     = i.ToString("D2");
                lbIndex.Location = new Point(2, 10 + i * 33 + 2);
                lbIndex.Width    = 30;
                pnAi.Controls.Add(lbIndex);
                UcAIOChn ucAi = new UcAIOChn();
                pnAi.Controls.Add(ucAi);
                ucAi.Location = new Point(32, 2 + i * 33);
                ucAi.Width    = pnAi.Width - 34;
                ucAi.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                ucAi.SetIOInfo(md, i, false, mgr.GetAiName(devID, moduleIndex, i));
                //nBottom = ucAi.Bottom;
            }
            int aoCount = mgr.GetAoChannelCount(devID, moduleIndex);

            for (int i = 0; i < aoCount; i++)
            {
                Label lbIndex = new Label();
                lbIndex.Text     = i.ToString("D2");
                lbIndex.Location = new Point(2, 10 + i * 33 + 2);
                lbIndex.Width    = 30;
                pnAo.Controls.Add(lbIndex);
                UcAIOChn ucAo = new UcAIOChn();
                pnAo.Controls.Add(ucAo);
                ucAo.Location = new Point(32, 2 + i * 33);
                ucAo.Width    = pnAi.Width - 34;
                ucAo.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                ucAo.SetIOInfo(md, i, true, mgr.GetAoName(devID, moduleIndex, i));
                //if (nBottom < ucAo.Bottom)
                //    nBottom = ucAo.Bottom;
            }

            //rtTips.Top = nBottom + 10;
        }
コード例 #7
0
        /// <summary>
        /// 打开所有轴设备
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btOpenAllDev_Click(object sender, EventArgs e)
        {
            if (null == _station)
            {
                return;
            }
            string[] axisNames = _station.AxisNames;
            if (null == axisNames || 0 == axisNames.Length)
            {
                ShowTips("工站 未提供轴/电机!");
                return;
            }
            bool isOK = true;

            foreach (string axisName in axisNames)
            {
                JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(axisName);
                if (null == ci)
                {
                    isOK = false;
                    ShowTips("未发现轴 = \"" + axisName + "\"所属 通道信息!");
                    continue;
                }
                IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                if (null == dev)
                {
                    isOK = false;
                    ShowTips("未发现轴 = \"" + axisName + "\"所属 设备ID = \"" + ci.DeviceID + "\"!");
                    continue;
                }
                if (!dev.IsDeviceOpen)
                {
                    int errCode = dev.OpenDevice();
                    if (0 != errCode)
                    {
                        isOK = false;
                        ShowTips(string.Format("打开轴 = \"{0}\"所属设备=\"{1}\"失败,错误信息:{2}", axisName, ci.DeviceID, dev.GetErrorInfo(errCode)));
                        continue;
                    }
                    ShowTips(string.Format("轴 = \"{0}\"所属设备=\"{1}\"已打开 ", axisName, ci.DeviceID));
                }
            }
            if (isOK)
            {
                ShowTips("所有轴设备已打开");
            }
            LayoutStation();
        }
コード例 #8
0
        public void SetAxisName(string axisName)
        {
            //_isAxisEnabled = false;
            _axisName       = axisName;
            gbAxisName.Text = _axisName;
            JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(_axisName);

            if (ci == null)
            {
                gbAxisName.Text      += "  轴名无效";
                ucAxisStatus1.Enabled = false;
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;

            if (null == dev)
            {
                gbAxisName.Text      += "  设备无效";
                ucAxisStatus1.Enabled = false;
                return;
            }
            if (!dev.IsDeviceOpen)
            {
                gbAxisName.Text      += "  设备未打开";
                ucAxisStatus1.Enabled = false;
                return;
            }
            if (ci.ModuleIndex >= dev.McCount)
            {
                gbAxisName.Text      += "  模块号无效";
                ucAxisStatus1.Enabled = false;
                return;
            }

            IJFModule_Motion mm = dev.GetMc(ci.ModuleIndex);

            if (ci.ChannelIndex >= mm.AxisCount)
            {
                gbAxisName.Text      += "  轴序号无效";
                ucAxisStatus1.Enabled = false;
                return;
            }
            ucAxisStatus1.Enabled = true;
            ucAxisStatus1.SetAxis(mm, ci.ChannelIndex);
            //_isAxisEnabled = true;
        }
コード例 #9
0
        private void btCfgR_Click(object sender, EventArgs e)
        {
            string        errInfo;
            JFDevCellInfo ci = CheckAxisDevInfo(_axisNames[3], out errInfo);

            if (null == ci)
            {
                MessageBox.Show("R轴:\"" + _axisNames[3] + "\" 未能显示参数配置窗口,ErrorInfo:" + errInfo);
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
            IJFModule_Motion    md  = dev.GetMc(ci.ModuleIndex);
            FormAxisTest        fm  = new FormAxisTest();

            fm.SetAxisInfo(md, ci.ChannelIndex, _axisNames[3]);
            fm.ShowDialog();
        }
コード例 #10
0
        void CheckAxis(int index)
        {
            if (string.IsNullOrEmpty(_axisNames[index]))
            {
                ShowTips(_AxisAlias[index] + " 未设置/已禁用");
                AxisEnabled(index, false);
                return;
            }
            JFDevCellInfo dcInfo = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(_axisNames[index]);

            if (null == dcInfo)
            {
                ShowTips(_AxisAlias[index] + "对应轴名称:\"" + _axisNames[index] + "\"在设备命名表中不存在!");
                AxisEnabled(index, false);
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(dcInfo.DeviceID) as IJFDevice_MotionDaq;

            if (null == dev)
            {
                ShowTips(string.Format("{0}对应轴:\"{1}\"所属设备\"{2}\"不存在!", _AxisAlias[index], _axisNames[index], dcInfo.DeviceID));
                AxisEnabled(index, false);
                return;
            }
            if (!dev.IsDeviceOpen)
            {
                ShowTips(string.Format("{0}对应轴:\"{1}\"所属设备\"{2}\"未打开!", _AxisAlias[index], _axisNames[index], dcInfo.DeviceID));
                AxisEnabled(index, false);
                return;
            }
            if (dcInfo.ModuleIndex >= dev.McCount)
            {
                ShowTips(string.Format("{0} 对应轴名称:\"{1}\"所属模块序号{2}超限 (0~{3}) !", _AxisAlias[index], _axisNames[index], dcInfo.ModuleIndex, dev.McCount - 1));
                AxisEnabled(index, false);
                return;
            }
            IJFModule_Motion md = dev.GetMc(dcInfo.ModuleIndex);

            if (dcInfo.ChannelIndex >= md.AxisCount)
            {
                ShowTips(string.Format("{0} 对应轴名称:\"{1}\"所属轴序号{2}超限 (0~{3}) !", _AxisAlias[index], _axisNames[index], dcInfo.ChannelIndex, md.AxisCount - 1));
                AxisEnabled(index, false);
                return;
            }
            AxisEnabled(index, true);
        }
コード例 #11
0
        public void UpdateChannelsInfo(string devID, int moduleIndex)
        {
            pnDi.Controls.Clear();
            pnDo.Controls.Clear();
            JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr;
            IJFModule_DIO        md  = null;
            IJFDevice_MotionDaq  dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq;

            if (dev != null && dev.DioCount > moduleIndex)
            {
                md = dev.GetDio(moduleIndex);
            }
            int diCount = mgr.GetDiChannelCount(devID, moduleIndex);

            for (int i = 0; i < diCount; i++)
            {
                Label lbIndex = new Label();
                lbIndex.Text     = i.ToString("D2");
                lbIndex.Location = new Point(2, 10 + i * 33 + 2);
                lbIndex.Width    = 30;
                pnDi.Controls.Add(lbIndex);
                UcDioChn ucDi = new UcDioChn();
                pnDi.Controls.Add(ucDi);
                ucDi.Location = new Point(32, 2 + i * 33);
                ucDi.Width    = pnDi.Width - 34;
                ucDi.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                ucDi.SetDioInfo(md, i, false, mgr.GetDiName(devID, moduleIndex, i));
            }
            int doCount = mgr.GetDoChannelCount(devID, moduleIndex);

            for (int i = 0; i < doCount; i++)
            {
                Label lbIndex = new Label();
                lbIndex.Text     = i.ToString("D2");
                lbIndex.Location = new Point(2, 10 + i * 33 + 2);
                lbIndex.Width    = 30;
                pnDo.Controls.Add(lbIndex);
                UcDioChn ucDo = new UcDioChn();
                pnDo.Controls.Add(ucDo);
                ucDo.Location = new Point(32, 2 + i * 33);
                ucDo.Width    = pnDi.Width - 34;
                ucDo.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                ucDo.SetDioInfo(md, i, true, mgr.GetDoName(devID, moduleIndex, i));
            }
        }
コード例 #12
0
        public void UpdateChannelsInfo(string devID, int moduleIndex)
        {
            lstTbAxisIDs.Clear();
            pnAxes.Controls.Clear();
            JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr;
            IJFModule_Motion     md  = null;
            IJFDevice_MotionDaq  dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq;

            if (dev != null && dev.DioCount > moduleIndex)
            {
                md = dev.GetMc(moduleIndex);
            }
            int axisCount = mgr.GetAxisCount(devID, moduleIndex);

            for (int i = 0; i < axisCount; i++)
            {
                Label lbIndex = new Label();
                lbIndex.Text     = "轴序号:" + i.ToString("D2") + " 轴ID:";
                lbIndex.Location = new Point(2, 5 + i * 70 + 2);
                pnAxes.Controls.Add(lbIndex);
                TextBox tbAxisID = new TextBox();
                tbAxisID.Location = new Point(lbIndex.Right, i * 70 + 2);
                string axisID = mgr.GetAxisName(devID, moduleIndex, i);
                tbAxisID.Text = axisID;

                tbAxisID.Enabled   = false;
                tbAxisID.BackColor = SystemColors.Control;
                pnAxes.Controls.Add(tbAxisID);
                lstTbAxisIDs.Add(tbAxisID);
                UcAxisStatus ucas = new UcAxisStatus();

                tbAxisID.Width = ucas.Width - 5 - lbIndex.Width;
                pnAxes.Controls.Add(ucas);
                ucas.Location = new Point(2, lbIndex.Bottom - 3);
                //ucas.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                ucas.DisplayMode = UcAxisStatus.JFDisplayMode.simple;
                //ucDi.SetDioInfo(md, moduleIndex, false, mgr.GetDiName(devID, moduleIndex, i));
                ucas.SetAxis(md, i);
                UcAxisTest ucat = new UcAxisTest();
                ucat.DisplayMode = UcAxisTest.JFDisplayMode.simplest_vel;
                ucat.Location    = new Point(ucas.Right, tbAxisID.Top);
                pnAxes.Controls.Add(ucat);
                ucat.SetAxis(md, i);
            }
        }
コード例 #13
0
        /// <summary>
        /// 显示轴配置/调试窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btCfg_Click(object sender, EventArgs e)
        {
            FormAxisTest  fm = new FormAxisTest();
            JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(_axisName);

            if (null == ci)
            {
                gbAxisName.Text += " 无通道信息";
                ucAxisTest.SetAxis(null, 0);
                cbMode.Enabled = false;
                btCfg.Enabled  = false;
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
            //if(null == dev)
            //{
            //    gbAxisName.Text += " 无设备:" + ci.DeviceID;
            //    ucAxisTest.SetAxis(null, 0);
            //    cbMode.Enabled = false;
            //    btCfg.Enabled = false;
            //    return;
            //}
            //if(!dev.IsDeviceOpen)
            //{
            //    gbAxisName.Text += " 设备未打开" ;
            //    ucAxisTest.SetAxis(null, 0);
            //    cbMode.Enabled = false;
            //    btCfg.Enabled = false;
            //    return;
            //}

            //if(dev.McCount <= ci.ModuleIndex)
            //{
            //    gbAxisName.Text += " 模块Idx = :" + ci.ModuleIndex + " 超限";
            //    ucAxisTest.SetAxis(null, 0);
            //    cbMode.Enabled = false;
            //    btCfg.Enabled = false;
            //    return;
            //}
            IJFModule_Motion md = dev.GetMc(ci.ModuleIndex);

            fm.SetAxisInfo(md, ci.ChannelIndex, _axisName);
            fm.ShowDialog();
        }
コード例 #14
0
        private void btHomeR_Click(object sender, EventArgs e)
        {
            string        errInfo;
            JFDevCellInfo ci = CheckAxisDevInfo(_axisNames[3], out errInfo);

            if (null == ci)
            {
                MessageBox.Show("R轴:\"" + _axisNames[3] + "\" Home操作失败,ErrorInfo:" + errInfo);
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
            IJFModule_Motion    md  = dev.GetMc(ci.ModuleIndex);
            int errCode             = md.Home(ci.ChannelIndex);

            if (0 != errCode)
            {
                MessageBox.Show("R轴:\"" + _axisNames[3] + "\" Home操作失败,ErrorInfo:" + md.GetErrorInfo(errCode));
                return;
            }
            ShowTips("R轴:\"" + _axisNames[3] + "\" Home运动开始");
        }
コード例 #15
0
        void OnServonButtonClicked(object sender, EventArgs e)
        {
            int i = 0;

            for (i = 0; i < btServons.Length; i++)
            {
                if (sender == btServons[i])
                {
                    break;
                }
            }
            string        axisName = _axisNames[i];
            string        errInfo;
            JFDevCellInfo ci = CheckAxisDevInfo(axisName, out errInfo);

            if (null == ci)
            {
                MessageBox.Show("轴" + _axisNames[i] + "伺服操作失败,ErrorInfo:" + errInfo);
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
            IJFModule_Motion    md  = dev.GetMc(ci.ModuleIndex);
            bool isCurrSerOn        = md.IsSVO(ci.ChannelIndex);
            int  errCode            = 0;

            if (isCurrSerOn)
            {
                errCode = md.ServoOff(ci.ChannelIndex);
            }
            else
            {
                errCode = md.ServoOn(ci.ChannelIndex);
            }
            if (errCode != 0)
            {
                MessageBox.Show("轴" + _axisNames[i] + "伺服操作失败,ErrorInfo:" + md.GetErrorInfo(errCode));
                return;
            }
            ShowTips("轴" + _axisNames[i] + "伺服" + (isCurrSerOn?"去使能":"使能") + "成功");
        }
コード例 #16
0
        private void btAbsMoveR_Click(object sender, EventArgs e)
        {
            string        errInfo;
            JFDevCellInfo ci = CheckAxisDevInfo(_axisNames[3], out errInfo);

            if (null == ci)
            {
                MessageBox.Show("R轴:\"" + _axisNames[3] + "\" 定位操作失败,ErrorInfo:" + errInfo);
                return;
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
            IJFModule_Motion    md  = dev.GetMc(ci.ModuleIndex);
            double tgtPos           = Convert.ToDouble(numAbsCmdR.Value);
            int    errCode          = md.AbsMove(ci.ChannelIndex, tgtPos);

            if (errCode != 0)
            {
                MessageBox.Show("R轴:\"" + _axisNames[3] + "\" 定位操作失败,ErrorInfo:" + md.GetErrorInfo(errCode));
                return;
            }
            ShowTips("R轴:\"" + _axisNames[3] + "\" 开始移动到 :" + tgtPos);
        }
コード例 #17
0
        JFDevCellInfo CheckAxisDevInfo(string axisName, out string errorInfo)
        {
            JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(axisName); //在命名表中的通道信息

            if (null == ci)
            {
                errorInfo = "未找到轴:\"" + axisName + "\"设备信息";
                return(null);
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;

            if (null == dev)
            {
                errorInfo = "未找到轴:\"" + axisName + "\"所属设备:\"" + ci.DeviceID + "\"";
                return(null);
            }
            if (!dev.IsDeviceOpen)
            {
                errorInfo = "轴:\"" + axisName + "\"所属设备:\"" + ci.DeviceID + "\"未打开";
                return(null);
            }
            if (ci.ModuleIndex >= dev.McCount)
            {
                errorInfo = "轴:\"" + axisName + "\"模块序号:\"" + ci.ModuleIndex + "\"超出限制!";
                return(null);
            }
            IJFModule_Motion md = dev.GetMc(ci.ModuleIndex);

            if (ci.ChannelIndex >= md.AxisCount)
            {
                errorInfo = "轴:\"" + axisName + "\"通道序号:\"" + ci.ChannelIndex + "\"超出限制!";
                return(null);
            }

            errorInfo = "";
            return(ci);
        }
コード例 #18
0
        JFDevCellInfo CheckTrigDevInfo(string trigName, out string errorInfo)
        {
            JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetCmpTrigCellInfo(trigName); //在命名表中的通道信息

            if (null == ci)
            {
                errorInfo = "未找到设备信息";
                return(null);
            }
            IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;

            if (null == dev)
            {
                errorInfo = "未找到所属设备:\"" + ci.DeviceID + "\"";
                return(null);
            }
            if (!dev.IsDeviceOpen)
            {
                errorInfo = "所属设备:\"" + ci.DeviceID + "\"未打开";
                return(null);
            }
            if (ci.ModuleIndex >= dev.McCount)
            {
                errorInfo = "模块序号:\"" + ci.ModuleIndex + "\"超出限制!";
                return(null);
            }
            IJFModule_CmprTrigger md = dev.GetCompareTrigger(ci.ModuleIndex);

            if (ci.ChannelIndex >= md.EncoderChannels)
            {
                errorInfo = "通道序号:\"" + ci.ChannelIndex + "\"超出限制!";
                return(null);
            }

            errorInfo = "";
            return(ci);
        }
コード例 #19
0
ファイル: JFCMFunction.cs プロジェクト: xhyangxianjun/ASMZZZ
        /// <summary>
        /// 检查设备通道是否存在并且可用
        /// </summary>
        /// <param name="category"></param>
        /// <param name="cellName"></param>
        /// <param name="initor"></param>
        /// <param name="cellInfo"></param>
        /// <param name="errorInfo"></param>
        /// <returns></returns>
        public static bool CheckDevCellName(string category, string cellName, out IJFInitializable initor, out JFDevCellInfo ci, out string errorInfo)
        {
            initor    = null;
            ci        = null;
            errorInfo = null;

            if (string.IsNullOrEmpty(cellName))
            {
                errorInfo = "参数项\"cellName\"为空";
                return(false);
            }
            JFDevCellNameManeger nameMgr   = JFHubCenter.Instance.MDCellNameMgr;
            JFInitorManager      initorMgr = JFHubCenter.Instance.InitorManager;
            JFDevCellInfo        cellInfo  = null;

            if (category == DO) //获取数字量输出通道信息
            {
                cellInfo = nameMgr.GetDoCellInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在DO:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq ";
                    return(false);
                }

                IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq;
                if (!md.IsInitOK)
                {
                    errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ModuleIndex >= md.DioCount)
                {
                    errorInfo = "DO:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备DIO模块数量: " + md.DioCount;
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.GetDio(cellInfo.ModuleIndex).DOCount)
                {
                    errorInfo = "DO:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出模块DO通道数量: " + md.GetDio(cellInfo.ModuleIndex).DOCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == DI) //获取数字量输入
            {
                cellInfo = nameMgr.GetDiCellInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在DI:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq ";
                    return(false);
                }

                IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq;
                if (!md.IsInitOK)
                {
                    errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ModuleIndex >= md.DioCount)
                {
                    errorInfo = "DI:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备DIO模块数量: " + md.DioCount;
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.GetDio(cellInfo.ModuleIndex).DICount)
                {
                    errorInfo = "DI:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出模块DI通道数量: " + md.GetDio(cellInfo.ModuleIndex).DOCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == AI)
            {
            }
            else if (category == AO)
            {
            }
            else if (category == Axis)
            {
                cellInfo = nameMgr.GetAxisCellInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在Axis:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq ";
                    return(false);
                }

                IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq;
                if (!md.IsInitOK)
                {
                    errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ModuleIndex >= md.McCount)
                {
                    errorInfo = "Axis:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备轴模块数量: " + md.McCount;
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.GetMc(cellInfo.ModuleIndex).AxisCount)
                {
                    errorInfo = "Axis:\"" + cellName + "\" Channel = :" + cellInfo.ModuleIndex + "超出模块轴通道数量: " + md.GetMc(cellInfo.ModuleIndex).AxisCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == CmpTrig)
            {
                cellInfo = nameMgr.GetCmpTrigCellInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在CmpTrig:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq ";
                    return(false);
                }

                IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq;
                if (!md.IsInitOK)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ModuleIndex >= md.CompareTriggerCount)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备比较触发模块数量: " + md.CompareTriggerCount;
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.GetCompareTrigger(cellInfo.ModuleIndex).EncoderChannels)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" Channel = :" + cellInfo.ModuleIndex + "超出模块比较触发通道数量: " + md.GetCompareTrigger(cellInfo.ModuleIndex).EncoderChannels;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == LightCtrl)
            {
                cellInfo = nameMgr.GetLightCtrlChannelInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在LightCtrl:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_LightController).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是IJFDevice_LightController ";
                    return(false);
                }

                IJFDevice_LightController md = dev as IJFDevice_LightController;
                if (!md.IsInitOK)
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.LightChannelCount)
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备光源通道数量: " + md.LightChannelCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == LightTrig)
            {
                cellInfo = nameMgr.GetTrigCtrlChannelInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在LightTrig:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_TrigController).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是IJFDevice_TrigController ";
                    return(false);
                }

                IJFDevice_TrigController md = dev as IJFDevice_TrigController;
                if (!md.IsInitOK)
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.TrigChannelCount)
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备触发通道数量: " + md.TrigChannelCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == Cmr)
            {
                IJFInitializable dev = initorMgr.GetInitor(cellName);
                if (null == dev)
                {
                    errorInfo = "Camera:\"" + cellName + "\" 在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_Camera).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "Camera:\"" + cellName + "\" 设备类型不是IJFDevice_Camera ";
                    return(false);
                }
                initor    = dev;
                errorInfo = "Success";
                return(true);
            }
            else
            {
                errorInfo = "不支持的参数项\"category\" = " + category;
            }
            return(false);
        }
コード例 #20
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            _isRunning = true;
            string axisID = GetMethodInputValue(PN_AxisID) as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID))
            {
                errorInfo  = "参数项:\"轴ID\" = " + axisID + " 在设备名称表中不存在";
                _workCmd   = 0;
                _isRunning = false;
                SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                return(false);
            }

            int          timeoutMilSeconds = (int)GetMethodInputValue(PN_TimeoutMilliSeconds);
            int          cycleMilliSeconds = (int)GetInitParamValue(PN_CycleMilliSeconds);;
            JFDevChannel axisChn           = new JFDevChannel(JFDevCellType.Axis, axisID);

            if (!axisChn.CheckAvalid(out errorInfo))
            {
                _workCmd   = 0;
                _isRunning = false;
                SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFDevice_MotionDaq _dev = null;
            IJFModule_Motion    _md  = null;
            JFDevCellInfo       _ci  = null;

            _dev = axisChn.Device() as IJFDevice_MotionDaq;
            _ci  = axisChn.CellInfo();
            _md  = _dev.GetMc(_ci.ModuleIndex);

            DateTime startTime = DateTime.Now;

            while (true)
            {
                if (0 == _workCmd) //正常工作
                {
                    int    errCode = 0;
                    bool[] axisStatus;
                    errCode = _md.GetMotionStatus(_ci.ChannelIndex, out axisStatus);
                    if (errCode != 0)
                    {
                        errorInfo  = "获取轴状态失败!" + _md.GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }
                    if (axisStatus[_md.MSID_ALM])
                    {
                        errorInfo  = "轴已报警!";
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }

                    if (_md.MSID_EMG > -1 && axisStatus[_md.MSID_EMG])
                    {
                        errorInfo  = "轴已急停!";
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }

                    if (!axisStatus[_md.MSID_SVO])
                    {
                        errorInfo  = "轴伺服已断电!";
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }

                    if (axisStatus[_md.MSID_MDN])
                    {
                        ActionErrorInfo = "Success";
                        _workCmd        = 0;
                        _isRunning      = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.Success);
                        return(true);
                    }

                    if (timeoutMilSeconds >= 0)
                    {
                        TimeSpan ts = DateTime.Now - startTime;
                        if (ts.TotalMilliseconds >= timeoutMilSeconds)
                        {
                            errorInfo  = "超时未等到轴:\" " + axisID + "\"归零完成 ";
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.Timeout);
                            return(true);
                        }
                    }
                    Thread.Sleep(cycleMilliSeconds);
                }
                else if (1 == _workCmd)//当前为暂停状态
                {
                    int errCode = 0;
                    errCode = _md.StopAxis(_ci.ChannelIndex);
                    if (0 != errCode)
                    {
                        errorInfo  = "停止轴归零运动失败:" + _md.GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }
                    _workCmd = 0;
                    continue;
                }
                else if (2 == _workCmd)//当前为恢复状态
                {
                    double tgtPos  = 0;
                    int    errCode = _md.GetCmdPos(_ci.ChannelIndex, out tgtPos);
                    if (0 != errCode)
                    {
                        errorInfo  = "恢复运行时获取目标位置失败:" + _md.GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }
                    errCode = _md.AbsMove(_ci.ChannelIndex, tgtPos);
                    if (0 != errCode)
                    {
                        errorInfo  = "恢复轴P2P运动失败:" + _md.GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }

                    _workCmd = 0;
                    continue;
                }
                else if (-1 == _workCmd)//指令退出
                {
                    int errCode = 0;
                    errCode = _md.StopAxis(_ci.ChannelIndex);
                    if (0 != errCode)
                    {
                        errorInfo  = "停止轴归零运动失败:" + _md.GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }

                    errorInfo  = "收到退出指令";
                    _workCmd   = 0;
                    _isRunning = false;
                    SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                    return(false);
                }
                else
                {
                    Thread.Sleep(cycleMilliSeconds);
                    continue;
                }
            }
        }
コード例 #21
0
        /// <summary>
        /// 根据工站的DIO确定控件数量
        /// </summary>
        public void AdjustStationUI()
        {
            //rchTips.Text = "";
            if (_station == null)
            {
                diNamesInView.Clear();
                doNamesInView.Clear();
                panelDIs.Controls.Clear();
                panelDOs.Controls.Clear();
                ShowTips("工站未设置");
                btOpenAllDev.Enabled = false;
                return;
            }
            btOpenAllDev.Enabled = true;
            string[] doNamesInStation = _station.DONames; //当前
            string[] diNamesInStation = _station.DINames;
            bool     isNeedReAdjustDo = false;            // 需要重新规划控件(IO数量/名称/排列发生变化)

            do
            {
                if (doNamesInStation == null || 0 == doNamesInStation.Length)
                {
                    if (doNamesInView.Count != 0)
                    {
                        isNeedReAdjustDo = true;
                        break;
                    }
                }
                else
                {
                    if (doNamesInView.Count != doNamesInStation.Length)
                    {
                        isNeedReAdjustDo = true;
                        break;
                    }
                    for (int i = 0; i < doNamesInView.Count; i++)
                    {
                        if (doNamesInView[i] != doNamesInStation[i])
                        {
                            isNeedReAdjustDo = true;
                            break;
                        }
                    }
                }
            } while (false);
            if (isNeedReAdjustDo)
            {
                doNamesInView.Clear();
                panelDOs.Controls.Clear();
                if (null != doNamesInStation)
                {
                    doNamesInView.AddRange(doNamesInStation);
                }
                for (int i = 0; i < doNamesInView.Count; i++)
                {
                    LampButton lampDo = new LampButton();
                    lampDo.Size   = new Size(_ioButtonWidth, _ioButtonHeight);
                    lampDo.Text   = doNamesInView[i];
                    lampDo.Click += new EventHandler(DOButtonClicked);
                    panelDOs.Controls.Add(lampDo);
                }
            }

            bool isNeedReAdjustDi = false;

            do
            {
                if (diNamesInStation == null || 0 == diNamesInStation.Length)
                {
                    if (diNamesInView.Count != 0)
                    {
                        isNeedReAdjustDi = true;
                        break;
                    }
                }
                else
                {
                    if (diNamesInView.Count != diNamesInStation.Length)
                    {
                        isNeedReAdjustDi = true;
                        break;
                    }
                    for (int i = 0; i < diNamesInView.Count; i++)
                    {
                        if (diNamesInView[i] != diNamesInStation[i])
                        {
                            isNeedReAdjustDi = true;
                            break;
                        }
                    }
                }
            } while (false);
            if (isNeedReAdjustDi)
            {
                diNamesInView.Clear();
                panelDIs.Controls.Clear();
                if (null != diNamesInStation)
                {
                    diNamesInView.AddRange(diNamesInStation);
                }
                for (int i = 0; i < diNamesInView.Count; i++)
                {
                    LampButton lampDi = new LampButton();
                    lampDi.Enabled = false;
                    lampDi.Size    = new Size(_ioButtonWidth, _ioButtonHeight);
                    lampDi.Text    = diNamesInView[i];
                    panelDIs.Controls.Add(lampDi);
                }
            }

            ////更新按钮提示信息
            toolTips.RemoveAll();

            for (int i = 0; i < doNamesInView.Count; i++)
            {
                LampButton    lampDo = panelDOs.Controls[i] as LampButton;
                JFDevCellInfo ci     = JFHubCenter.Instance.MDCellNameMgr.GetDoCellInfo(doNamesInView[i]);
                do
                {
                    if (ci == null) //名称在配置中不存在
                    {
                        lampDo.LampColor = LampButton.LColor.Gray;
                        lampDo.ForeColor = Color.Red;
                        lampDo.Enabled   = false;
                        toolTips.SetToolTip(lampDo, "名称在命名配置表中不存在");
                        ShowTips(string.Format("DO: \"{0}\" 在命名配置表中不存在", doNamesInView[i]));
                        break;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        lampDo.LampColor = LampButton.LColor.Gray;
                        lampDo.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red;
                        lampDo.Enabled   = false;
                        toolTips.SetToolTip(lampDo, "未发现所属设备:" + ci.DeviceID);
                        ShowTips(string.Format("DO: \"{0}\" 所属设备 \"{1}\" 在系统中不存在", doNamesInView[i], ci.DeviceID));
                        break;
                    }
                    if (!dev.IsDeviceOpen)
                    {
                        lampDo.LampColor = LampButton.LColor.Gray;
                        lampDo.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red;
                        lampDo.Enabled   = false;
                        ShowTips(string.Format("DO: \"{0}\" 所属设备 \"{1}\" 未打开(关闭状态)", doNamesInView[i], ci.DeviceID));
                        toolTips.SetToolTip(lampDo, "设备未打开");
                        break;
                    }
                    if (dev.DioCount <= ci.ModuleIndex)
                    {
                        lampDo.LampColor = LampButton.LColor.Gray;
                        lampDo.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red;
                        lampDo.Enabled   = false;
                        toolTips.SetToolTip(lampDo, "所属模块序号超限");
                        ShowTips(string.Format("DO: \"{0}\" 所属设备 \"{1}\" 所属模块Index = {2} 超出范围0~{3}", doNamesInView[i], ci.DeviceID, ci.ModuleIndex, dev.DioCount == 0?0: dev.DioCount - 1));
                        break;
                    }
                    IJFModule_DIO md = dev.GetDio(ci.ModuleIndex);
                    if (md.DOCount <= ci.ChannelIndex)
                    {
                        lampDo.LampColor = LampButton.LColor.Gray;
                        lampDo.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red;
                        lampDo.Enabled   = false;
                        toolTips.SetToolTip(lampDo, "通道序号超限");
                        ShowTips(string.Format("DO: \"{0}\" 通道序号:{1} 超出范围0~{2}", doNamesInView[i], ci.ChannelIndex, md.DOCount == 0 ? 0 : md.DOCount - 1));
                        break;
                    }
                    lampDo.Enabled   = true;
                    lampDo.ForeColor = Color.Black;
                } while (false);
            }

            for (int i = 0; i < diNamesInView.Count; i++)
            {
                LampButton    lampDi = panelDIs.Controls[i] as LampButton;
                JFDevCellInfo ci     = JFHubCenter.Instance.MDCellNameMgr.GetDiCellInfo(diNamesInView[i]);
                do
                {
                    if (ci == null) //名称在配置中不存在
                    {
                        lampDi.LampColor = LampButton.LColor.Gray;
                        lampDi.ForeColor = Color.Red;
                        toolTips.SetToolTip(lampDi, "名称在命名配置表中不存在");
                        ShowTips(string.Format("DI: \"{0}\" 在命名配置表中不存在", diNamesInView[i]));
                        break;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        lampDi.LampColor = LampButton.LColor.Gray;
                        lampDi.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red;
                        toolTips.SetToolTip(lampDi, "未发现所属设备:" + ci.DeviceID);
                        ShowTips(string.Format("DI: \"{0}\" 所属设备 \"{1}\" 在系统中不存在", diNamesInView[i], ci.DeviceID));
                        break;
                    }
                    if (!dev.IsDeviceOpen)
                    {
                        lampDi.LampColor = LampButton.LColor.Gray;
                        lampDi.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red;
                        ShowTips(string.Format("DOI: \"{0}\" 所属设备 \"{1}\" 未打开(关闭状态)", diNamesInView[i], ci.DeviceID));
                        toolTips.SetToolTip(lampDi, "设备未打开");
                        break;
                    }
                    if (dev.DioCount <= ci.ModuleIndex)
                    {
                        lampDi.LampColor = LampButton.LColor.Gray;
                        lampDi.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red;
                        toolTips.SetToolTip(lampDi, "所属模块序号超限");
                        ShowTips(string.Format("DI: \"{0}\"  所属设备 \"{1}\" 所属模块Index = {2} 超出范围0~{3}", diNamesInView[i], ci.DeviceID, ci.ModuleIndex, dev.DioCount == 0 ? 0 : dev.DioCount - 1));
                        break;
                    }
                    IJFModule_DIO md = dev.GetDio(ci.ModuleIndex);
                    if (md.DICount <= ci.ChannelIndex)
                    {
                        lampDi.LampColor = LampButton.LColor.Gray;
                        lampDi.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red;
                        toolTips.SetToolTip(lampDi, "通道序号超限");
                        ShowTips(string.Format("DI: \"{0}\" 通道序号:{1} 超出范围0~{2}", diNamesInView[i], ci.ChannelIndex, md.DICount == 0 ? 0 : md.DOCount - 1));
                        break;
                    }
                    //lampDo.Enabled = true;
                    lampDi.ForeColor = Color.Black;
                } while (false);
            }
        }
コード例 #22
0
        private void btOpenAllDev_Click(object sender, EventArgs e)
        {
            if (null == _station)
            {
                ShowTips("打开所有DIO设备失败:工站未设置");
                return;
            }
            string[] diNames = _station.DINames;
            string[] doNames = _station.DONames;
            if ((null == diNames || 0 == diNames.Length) && (null == doNames || 0 == doNames.Length))
            {
                ShowTips("打开所有DIO设备失败:工站未设置DI/DO");
                return;
            }
            bool isOK = true;

            if (null != diNames)
            {
                foreach (string diName in diNames)
                {
                    JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDiCellInfo(diName);
                    if (null == ci)
                    {
                        isOK = false;
                        ShowTips("未发现DI = \"" + diName + "\"所属 通道信息!");
                        continue;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        isOK = false;
                        ShowTips("未发现DI = \"" + diName + "\"所属 设备ID = \"" + ci.DeviceID + "\"!");
                        continue;
                    }
                    if (!dev.IsDeviceOpen)
                    {
                        int errCode = dev.OpenDevice();
                        if (0 != errCode)
                        {
                            isOK = false;
                            ShowTips(string.Format("打开DI = \"{0}\"所属设备=\"{1}\"失败,错误信息:{2}", diName, ci.DeviceID, dev.GetErrorInfo(errCode)));
                            continue;
                        }
                        ShowTips(string.Format("DI = \"{0}\"所属设备=\"{1}\"已打开 ", diName, ci.DeviceID));
                    }
                }
            }


            if (null != doNames)
            {
                foreach (string doName in doNames)
                {
                    JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDoCellInfo(doName);
                    if (null == ci)
                    {
                        isOK = false;
                        ShowTips("未发现DO = \"" + doName + "\"所属 通道信息!");
                        continue;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        isOK = false;
                        ShowTips("未发现DO = \"" + doName + "\"所属 设备ID = \"" + ci.DeviceID + "\"!");
                        continue;
                    }
                    if (!dev.IsDeviceOpen)
                    {
                        int errCode = dev.OpenDevice();
                        if (0 != errCode)
                        {
                            isOK = false;
                            ShowTips(string.Format("打开DO = \"{0}\"所属设备=\"{1}\"失败,错误信息:{2}", doName, ci.DeviceID, dev.GetErrorInfo(errCode)));
                            continue;
                        }
                        ShowTips(string.Format("DO = \"{0}\"所属设备=\"{1}\"已打开 ", doName, ci.DeviceID));
                    }
                }
            }
            if (isOK)
            {
                ShowTips("工站所有DIO设备已打开");
            }
            AdjustStationUI();
        }
コード例 #23
0
        /// <summary>
        /// 将工站IO状态更新到界面上
        /// </summary>
        void UpdateStationUI()
        {
            if (_station == null)
            {
                return;
            }
            for (int i = 0; i < doNamesInView.Count; i++)
            {
                string        doName = doNamesInView[i];
                LampButton    lmpdo  = panelDOs.Controls[i] as LampButton;
                JFDevCellInfo ci     = JFHubCenter.Instance.MDCellNameMgr.GetDoCellInfo(doName);
                do
                {
                    if (ci == null) //名称在配置中不存在
                    {
                        lmpdo.LampColor = LampButton.LColor.Gray;
                        break;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        lmpdo.LampColor = LampButton.LColor.Gray;
                        break;
                    }
                    if (!dev.IsDeviceOpen)
                    {
                        lmpdo.LampColor = LampButton.LColor.Gray;
                        break;
                    }
                    if (dev.DioCount <= ci.ModuleIndex)
                    {
                        lmpdo.LampColor = LampButton.LColor.Gray;
                        break;
                    }

                    IJFModule_DIO md = dev.GetDio(ci.ModuleIndex);
                    if (md.DOCount <= ci.ChannelIndex)
                    {
                        lmpdo.LampColor = LampButton.LColor.Gray;
                        break;
                    }

                    bool isOn    = false;
                    int  errCode = md.GetDO(ci.ChannelIndex, out isOn);
                    if (0 == errCode)
                    {
                        lmpdo.ForeColor = Color.Black;
                        lmpdo.LampColor = isOn ? LampButton.LColor.Green : LampButton.LColor.Gray;
                    }
                    else
                    {
                        lmpdo.LampColor = LampButton.LColor.Gray;
                        lmpdo.ForeColor = Color.Orange;//ucdo.IONameTextColor = Color.Red;
                    }
                } while (false);
            }

            for (int i = 0; i < diNamesInView.Count; i++)
            {
                string        diName = diNamesInView[i];
                LampButton    lmpdi  = panelDIs.Controls[i] as LampButton;
                JFDevCellInfo ci     = JFHubCenter.Instance.MDCellNameMgr.GetDiCellInfo(diName);
                do
                {
                    if (ci == null) //名称在配置中不存在
                    {
                        lmpdi.LampColor = LampButton.LColor.Gray;
                        break;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        lmpdi.LampColor = LampButton.LColor.Gray;
                        break;
                    }
                    if (!dev.IsDeviceOpen)
                    {
                        lmpdi.LampColor = LampButton.LColor.Gray;
                        break;
                    }
                    if (dev.DioCount <= ci.ModuleIndex)
                    {
                        lmpdi.LampColor = LampButton.LColor.Gray;
                        break;
                    }

                    IJFModule_DIO md = dev.GetDio(ci.ModuleIndex);
                    if (md.DICount <= ci.ChannelIndex)
                    {
                        lmpdi.LampColor = LampButton.LColor.Gray;
                        break;
                    }

                    bool isOn    = false;
                    int  errCode = md.GetDI(ci.ChannelIndex, out isOn);
                    if (0 == errCode)
                    {
                        lmpdi.ForeColor = Color.Black;
                        lmpdi.LampColor = isOn ? LampButton.LColor.Green : LampButton.LColor.Gray;
                    }
                    else
                    {
                        lmpdi.LampColor = LampButton.LColor.Gray;
                        lmpdi.ForeColor = Color.Orange;//ucdo.IONameTextColor = Color.Red;
                    }
                } while (false);
            }
        }
コード例 #24
0
ファイル: JFCM_WaitDI_D.cs プロジェクト: xhyangxianjun/ASMZZZ
        protected override bool ActionGenuine(out string errorInfo)
        {
            _isRunning = true;
            string diName = GetMethodInputValue(PN_DIID) as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainDiName(diName))
            {
                errorInfo = "参数项:\"DI通道名称\" = " + diName + " 在设备名称表中不存在";
                return(false);
            }

            bool isDIEnable        = (bool)GetMethodInputValue(PN_WaitDIStatus);
            int  timeoutMilSeconds = (int)GetMethodInputValue(PN_TimeoutMilliSeconds);
            int  cycleMilliSeconds = (int)GetInitParamValue(PN_CycleMilliSeconds);

            JFDevChannel diChn = new JFDevChannel(JFDevCellType.DI, diName);
            string       avalidInfo;

            if (!diChn.CheckAvalid(out avalidInfo))
            {
                errorInfo = avalidInfo;
                return(false);
            }

            _dev = diChn.Device() as IJFDevice_MotionDaq;
            _ci  = diChn.CellInfo();
            _dio = _dev.GetDio(_ci.ModuleIndex);

            DateTime startTime = DateTime.Now;

            while (true)
            {
                if (0 == _workCmd) //正常工作
                {
                    // DI状态检查
                    bool isON    = false;
                    int  errCode = _dio.GetDI(_ci.ChannelIndex, out isON);
                    if (errCode != 0)
                    {
                        errorInfo  = "获取DI状态失败!" + _dio.GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.Timeout);
                        return(false);
                    }

                    if (isDIEnable == isON)
                    {
                        errorInfo  = "Success";
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.Success);
                        return(true);
                    }

                    if (timeoutMilSeconds >= 0)
                    {
                        TimeSpan ts = DateTime.Now - startTime;
                        if (ts.TotalMilliseconds >= timeoutMilSeconds)
                        {
                            errorInfo  = "超时未等到DI:\" " + diName + "\"状态为" + isDIEnable.ToString();
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.Timeout);
                            return(true);
                        }
                    }
                    Thread.Sleep(cycleMilliSeconds);
                }
                else if (1 == _workCmd)//当前为暂停状态
                {
                    Thread.Sleep(cycleMilliSeconds);
                    continue;
                }
                else//指令退出
                {
                    errorInfo  = "收到退出指令";
                    _workCmd   = 0;
                    _isRunning = false;
                    SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                    return(false);
                }
            }
        }
コード例 #25
0
        ///// <summary>
        ///// 使通道可用(如伺服上电,光源/触发可用)
        ///// 建议在 打开设备->检查通道可用性 之后调用
        ///// </summary>
        ///// <param name="errorInfo"></param>
        ///// <returns></returns>
        public bool EnabledChannel(out string errorInfo)
        {
            errorInfo = "Unknown-Error";
            bool isOK = false;

            if (!CheckAvalid(out errorInfo))
            {
                return(false);
            }
            int       errorCode = 0;
            IJFDevice dev       = Device();

            switch (CellType)
            {
            case JFDevCellType.DI:
                isOK      = true;
                errorInfo = "Success";
                break;

            case JFDevCellType.DO:
                errorInfo = "Success";
                isOK      = true;
                break;

            case JFDevCellType.Axis:
            {
                IJFDevice_MotionDaq devMD = Device() as IJFDevice_MotionDaq;
                JFDevCellInfo       ci    = CellInfo();
                IJFModule_Motion    mm    = devMD.GetMc(ci.ModuleIndex);
                errorCode = mm.ServoOn(ci.ChannelIndex);
                if (errorCode != 0)
                {
                    errorInfo = mm.GetErrorInfo(errorCode);
                }
                else
                {
                    isOK      = true;
                    errorInfo = "Success";
                }
            }
            break;

            case JFDevCellType.AI:
                errorInfo = "Success";
                isOK      = true;
                break;

            case JFDevCellType.AO:
                errorInfo = "Success";
                isOK      = true;
                break;

            case JFDevCellType.CmpTrig:
                errorInfo = "Success";
                isOK      = true;
                break;

            case JFDevCellType.Light:
                dev = Device();
                if (dev is IJFDevice_LightControllerWithTrig)    //光源控制器
                {
                    IJFDevice_LightControllerWithTrig devLT = dev as IJFDevice_LightControllerWithTrig;
                    errorCode = devLT.SetWorkMode(JFLightWithTrigWorkMode.TurnOnOff);     //切换为开关模式
                    if (errorCode != 0)
                    {
                        errorInfo = "切换为开关模式失败:" + devLT.GetErrorInfo(errorCode);
                        break;
                    }
                }
                IJFDevice_LightController devl = dev as IJFDevice_LightController;
                errorCode = devl.SetLightChannelEnable(CellInfo().ChannelIndex, true);
                if (errorCode != 0)
                {
                    errorInfo = "通道使能失败:" + devl.GetErrorInfo(errorCode);
                    break;
                }
                isOK      = true;
                errorInfo = "Success";
                break;

            case JFDevCellType.Trig:
                dev = Device();
                if (dev is IJFDevice_LightControllerWithTrig)     //光源控制器
                {
                    IJFDevice_LightControllerWithTrig devLT = dev as IJFDevice_LightControllerWithTrig;
                    errorCode = devLT.SetWorkMode(JFLightWithTrigWorkMode.Trigger);     //切换为触发模式
                    if (errorCode != 0)
                    {
                        errorInfo = "切换为触发模式失败:" + devLT.GetErrorInfo(errorCode);
                        break;
                    }
                }
                IJFDevice_TrigController devt = dev as IJFDevice_TrigController;
                errorCode = devt.SetTrigChannelEnable(CellInfo().ChannelIndex, true);
                if (errorCode != 0)
                {
                    errorInfo = "通道使能失败:" + devt.GetErrorInfo(errorCode);
                    break;
                }
                isOK      = true;
                errorInfo = "Success";
                break;

            default:
                errorInfo = "未定义的通道类型";
                break;
            }
            return(isOK);
        }
コード例 #26
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            _isRunning = true;
            string[] axisIDList = GetInitParamValue(PN_AxisID) as string[];
            if (axisIDList == null)
            {
                errorInfo = "轴ID列表长度为空";
                return(false);
            }

            int[] iAxisIDList = new int[axisIDList.Length];
            if (axisIDList.Length <= 0)
            {
                errorInfo = "轴ID列表长度<=0";
                return(false);
            }

            IJFModule_Motion     _md        = null;
            JFDevCellInfo        _ci        = null;
            IJFDevice_MotionDaq  _dev       = null;
            IJFDevice_MotionDaq  _devBuff   = null;
            List <JFDevCellInfo> cibuffList = new List <JFDevCellInfo>();

            _mdList = new List <IJFModule_Motion>();
            _ciList = new List <JFDevCellInfo>();

            //检查轴参数合法性
            for (int i = 0; i < axisIDList.Length; i++)
            {
                if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisIDList[i]))
                {
                    errorInfo = "参数项:\"轴ID\" = " + axisIDList[i] + " 在设备名称表中不存在";
                    return(false);
                }
                JFDevChannel axisChn = new JFDevChannel(JFDevCellType.Axis, axisIDList[1]);

                if (!axisChn.CheckAvalid(out errorInfo))
                {
                    return(false);
                }

                _dev = axisChn.Device() as IJFDevice_MotionDaq;
                _ci  = axisChn.CellInfo();
                _md  = _dev.GetMc(_ci.ModuleIndex);

                if (_devBuff != null)
                {
                    if (_devBuff != _dev)
                    {
                        errorInfo = "轴ID列表中的所有轴并不来源于同一个设备";
                        return(false);
                    }
                }
                _devBuff = _dev;

                foreach (JFDevCellInfo jFDevCellInfo in cibuffList)
                {
                    if (jFDevCellInfo.ChannelIndex == _ci.ChannelIndex)
                    {
                        errorInfo = "轴ID列表中存在重复的轴名称";
                        return(false);
                    }
                }
                cibuffList.Add(_ci);

                _ciList.Add(_ci);
                _mdList.Add(_md);
                iAxisIDList[i] = _ci.ChannelIndex;
            }

            int  timeoutMilSeconds = (int)GetMethodInputValue(PN_TimeoutMilliSeconds);
            int  cycleMilliSeconds = (int)GetInitParamValue(PN_CycleMilliSeconds);
            bool isAbs             = (bool)GetMethodInputValue(PN_AbsMode);

            DateTime startTime = DateTime.Now;

            while (true)
            {
                if (0 == _workCmd) //正常工作
                {
                    int errCode = 0;
                    // 其他状态检查
                    bool[] axisStatus;
                    bool   isMotionDone = true;
                    for (int i = 0; i < _ciList.Count; i++)
                    {
                        errCode = _mdList[i].GetMotionStatus(_ciList[i].ChannelIndex, out axisStatus);
                        if (errCode != 0)
                        {
                            errorInfo  = "获取轴状态失败!" + _mdList[i].GetErrorInfo(errCode);
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                            return(false);
                        }
                        if (axisStatus[_mdList[i].MSID_ALM])
                        {
                            errorInfo  = "轴已报警!";
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                            return(false);
                        }

                        if (_mdList[i].MSID_EMG > -1 && axisStatus[_mdList[i].MSID_EMG])
                        {
                            errorInfo  = "轴已急停!";
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                            return(false);
                        }

                        if (!axisStatus[_mdList[i].MSID_SVO])
                        {
                            errorInfo  = "轴伺服已断电!";
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                            return(false);
                        }

                        if (!axisStatus[_mdList[i].MSID_MDN])
                        {
                            isMotionDone = false;
                            break;
                        }
                    }

                    if (isMotionDone)
                    {
                        errorInfo  = "Success";
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.Success);
                        return(true);
                    }

                    if (timeoutMilSeconds >= 0)
                    {
                        TimeSpan ts = DateTime.Now - startTime;
                        if (ts.TotalMilliseconds >= timeoutMilSeconds)
                        {
                            errorInfo  = "超时未等到直线插补运动完成 ";
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.Timeout);
                            return(true);
                        }
                    }
                    Thread.Sleep(cycleMilliSeconds);
                }
                else if (1 == _workCmd)//当前为暂停状态
                {
                    int errCode = 0;
                    for (int i = 0; i < _ciList.Count; i++)
                    {
                        errCode = _mdList[i].StopAxis(_ciList[i].ChannelIndex);
                        if (0 != errCode)
                        {
                            errorInfo  = "停止轴归零运动失败:" + _mdList[i].GetErrorInfo(errCode);
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                            return(false);
                        }
                    }
                    _workCmd = 0;
                    continue;
                }
                else if (2 == _workCmd)//当前为恢复状态
                {
                    double[] dPosList = new double[_ciList.Count];
                    double   tgtPos   = 0;
                    int      errCode  = 0;
                    for (int i = 0; i < _ciList.Count; i++)
                    {
                        errCode = _mdList[i].GetCmdPos(_ciList[i].ChannelIndex, out tgtPos);
                        if (0 != errCode)
                        {
                            errorInfo  = "恢复直线插补运行时获取目标位置失败:" + _mdList[i].GetErrorInfo(errCode);
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                            return(false);
                        }
                        dPosList[i] = tgtPos;
                    }
                    if (isAbs)
                    {
                        errCode = _mdList[0].AbsLine(iAxisIDList, dPosList);
                    }
                    else
                    {
                        errCode = _mdList[0].RelLine(iAxisIDList, dPosList);
                    }
                    if (0 != errCode)
                    {
                        errorInfo  = "恢复轴" + (isAbs ? "绝对式" : "相对式") + "直线插补运动失败:" + _mdList[0].GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                        return(false);
                    }
                    _workCmd = 0;
                    continue;
                }
                else if (-1 == _workCmd)//指令退出
                {
                    int errCode = 0;
                    for (int i = 0; i < _ciList.Count; i++)
                    {
                        errCode = _mdList[i].StopAxis(_ciList[i].ChannelIndex);
                        if (0 != errCode)
                        {
                            errorInfo  = "停止轴归零运动失败:" + _mdList[i].GetErrorInfo(errCode);
                            _workCmd   = 0;
                            _isRunning = false;
                            SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                            return(false);
                        }
                    }

                    errorInfo  = "收到退出指令";
                    _workCmd   = 0;
                    _isRunning = false;
                    SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                    return(false);
                }
                else
                {
                    Thread.Sleep(cycleMilliSeconds);
                    continue;
                }
            }
        }
コード例 #27
0
ファイル: JFM_TrackLoad.cs プロジェクト: xhyangxianjun/ASMZZZ
        protected bool JFWaitDi(string diName, out string errorInfo, bool isTurnOn, int delaytime = -1)
        {
            if (!JFHubCenter.Instance.MDCellNameMgr.ContainDiName(diName))
            {
                errorInfo = "参数项:\"DI通道名称\" = " + diName + " 在设备名称表中不存在";
                return(false);
            }

            JFDevChannel diChn = new JFDevChannel(JFDevCellType.DI, diName);
            string       avalidInfo;

            if (!diChn.CheckAvalid(out avalidInfo))
            {
                errorInfo = avalidInfo;
                return(false);
            }
            IJFDevice_MotionDaq _dev = null;
            IJFModule_DIO       _dio = null;
            JFDevCellInfo       _ci  = null;

            _dev = diChn.Device() as IJFDevice_MotionDaq;
            _ci  = diChn.CellInfo();
            _dio = _dev.GetDio(_ci.ModuleIndex);

            DateTime startTime = DateTime.Now;

            while (true)
            {
                if (0 == _workCmd) //正常工作
                {
                    // DI状态检查
                    bool isON    = false;
                    int  errCode = _dio.GetDI(_ci.ChannelIndex, out isON);
                    if (errCode != 0)
                    {
                        errorInfo  = "获取DI状态失败!" + _dio.GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        return(false);
                    }

                    if (isTurnOn == isON)
                    {
                        errorInfo  = "Success";
                        _workCmd   = 0;
                        _isRunning = false;
                        return(true);
                    }

                    if (delaytime >= 0)
                    {
                        TimeSpan ts = DateTime.Now - startTime;
                        if (ts.TotalMilliseconds >= delaytime)
                        {
                            errorInfo  = "超时未等到DI:\" " + diName + "\"状态为" + isTurnOn.ToString();
                            _workCmd   = 0;
                            _isRunning = false;
                            return(false);
                        }
                    }
                    Thread.Sleep(10);
                }
                else if (1 == _workCmd)//当前为暂停状态
                {
                    Thread.Sleep(10);
                    continue;
                }
                else//指令退出
                {
                    errorInfo  = "收到退出指令";
                    _workCmd   = 0;
                    _isRunning = false;
                    return(false);
                }
            }
        }
コード例 #28
0
ファイル: JFM_TrackLoad.cs プロジェクト: xhyangxianjun/ASMZZZ
        protected bool JFMotionDone(string AxisName, out string errorInfo, int delaytime)
        {
            errorInfo = "";
            JFDevChannel axisChn = new JFDevChannel(JFDevCellType.Axis, AxisName);

            if (!axisChn.CheckAvalid(out errorInfo))
            {
                _workCmd   = 0;
                _isRunning = false;
                return(false);
            }

            IJFDevice_MotionDaq _dev = null;
            IJFModule_Motion    _md  = null;
            JFDevCellInfo       _ci  = null;

            _dev = axisChn.Device() as IJFDevice_MotionDaq;
            _ci  = axisChn.CellInfo();
            _md  = _dev.GetMc(_ci.ModuleIndex);

            DateTime startTime = DateTime.Now;

            while (true)
            {
                if (0 == _workCmd) //正常工作
                {
                    int    errCode = 0;
                    bool[] axisStatus;
                    errCode = _md.GetMotionStatus(_ci.ChannelIndex, out axisStatus);
                    if (errCode != 0)
                    {
                        errorInfo  = "获取轴状态失败!" + _md.GetErrorInfo(errCode);
                        _workCmd   = 0;
                        _isRunning = false;
                        return(false);
                    }
                    if (axisStatus[_md.MSID_ALM])
                    {
                        errorInfo  = "轴已报警!";
                        _workCmd   = 0;
                        _isRunning = false;
                        return(false);
                    }

                    if (_md.MSID_EMG > -1 && axisStatus[_md.MSID_EMG])
                    {
                        errorInfo  = "轴已急停!";
                        _workCmd   = 0;
                        _isRunning = false;
                        return(false);
                    }

                    //if (!axisStatus[_md.MSID_SVO])
                    //{
                    //    errorInfo = "轴伺服已断电!";
                    //    _workCmd = 0;
                    //    _isRunning = false;
                    //    SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError);
                    //    return false;
                    //}

                    if (axisStatus[_md.MSID_MDN])
                    {
                        ActionErrorInfo = "Success";
                        _workCmd        = 0;
                        _isRunning      = false;
                        return(true);
                    }
                    TimeSpan ts = DateTime.Now - startTime;
                    if (ts.TotalMilliseconds >= delaytime)
                    {
                        errorInfo  = "超时未等到轴:\" " + AxisName + "\"动作完成 ";
                        _workCmd   = 0;
                        _isRunning = false;
                        return(false);
                    }

                    Thread.Sleep(10);
                }
                else if (1 == _workCmd)//当前为暂停状态
                {
                    _station.StopAxis(LeftClampName);
                    _station.StopAxis(LeftPushName);

                    _isRunning = false;
                    _workCmd   = 0;
                    continue;
                }
                else if (2 == _workCmd)//当前为恢复状态
                {
                    _workCmd = 0;
                    continue;
                }
                else if (-1 == _workCmd)//指令退出
                {
                    _station.StopAxis(LeftClampName);
                    _station.StopAxis(LeftPushName);

                    errorInfo  = "收到退出指令";
                    _workCmd   = 0;
                    _isRunning = false;
                    return(false);
                }
                else
                {
                    Thread.Sleep(10);
                    continue;
                }
            }
        }
コード例 #29
0
        /// <summary>
        /// 保存当前视觉配置
        /// </summary>
        /// <param name="filePath"></param>
        public bool SaveProgram(string programName, out string errorInfo)
        {
            errorInfo = "UnknownError";
            bool ret = false;

            do
            {
                if (string.IsNullOrEmpty(programName))
                {
                    errorInfo = "配置名称为空字串";
                    break;
                }

                JFVisionManager        vm = JFHubCenter.Instance.VisionMgr;
                JFSingleVisionCfgParam vc = null;
                if (vm.ContainSingleVisionCfgByName(programName))
                {
                    vc = vm.GetSingleVisionCfgByName(programName);
                }
                else
                {
                    vc = new JFSingleVisionCfgParam();
                }
                string ei;
                if (!OpenEnableDevices(out ei))
                {
                    errorInfo = "设备未全部打开并使能:" + ei;
                    break;
                }
                ///相机参数
                double exposure = 0; //相机曝光值
                double gain     = 0;
                bool   isRevsX  = false;
                bool   isRevsY  = false;

                int errCode = _cmr.GetExposure(out exposure);
                if (errCode != 0)
                {
                    errorInfo = "获取相机曝光值失败:" + _cmr.GetErrorInfo(errCode);
                    break;
                }

                errCode = _cmr.GetGain(out gain);
                if (errCode != 0)
                {
                    errorInfo = "获取相机增益值失败:" + _cmr.GetErrorInfo(errCode);
                    break;
                }

                errCode = _cmr.GetReverseX(out isRevsX);
                if (errCode != 0)
                {
                    errorInfo = "获取相机X镜像参数失败:" + _cmr.GetErrorInfo(errCode);
                    break;
                }

                errCode = _cmr.GetReverseY(out isRevsY);
                if (errCode != 0)
                {
                    errorInfo = "获取相机Y镜像参数失败:" + _cmr.GetErrorInfo(errCode);
                    break;
                }

                ///光源通道参数
                int[] intensities = null;
                if (_lightNames != null && _lightNames.Length > 0)
                {
                    intensities = new int[_lightNames.Length];
                    for (int i = 0; i < _lightNames.Length; i++)
                    {
                        int nVal = 0;
                        IJFDevice_LightController dev = _lightChns[i].Device() as IJFDevice_LightController;
                        errCode = dev.GetLightIntensity(_lightChns[i].CellInfo().ChannelIndex, out nVal);
                        if (errCode != 0)
                        {
                            errorInfo = "获取光源:\"" + _lightNames[i] + "\"亮度值失败:" + dev.GetErrorInfo(errCode);
                            goto LoopExit;
                        }
                        intensities[i] = nVal;
                    }
                }


                double[] axisPos = null;
                ///配置轴参数
                if (_cfgAxisNames != null && _cfgAxisNames.Length > 0)
                {
                    double dVal = 0;
                    axisPos = new double[_cfgAxisNames.Length];
                    for (int i = 0; i < _cfgAxisNames.Length; i++)
                    {
                        IJFDevice_MotionDaq md = _cfgAxes[i].Device() as IJFDevice_MotionDaq;
                        JFDevCellInfo       ci = _cfgAxes[i].CellInfo();
                        errCode = md.GetMc(ci.ModuleIndex).GetFbkPos(ci.ChannelIndex, out dVal);
                        if (errCode != 0)
                        {
                            errorInfo = "获取轴:\"" + _cfgAxisNames[i] + "\"位置失败:" + md.GetMc(ci.ModuleIndex).GetErrorInfo(errCode);
                            goto LoopExit;
                        }
                        axisPos[i] = dVal;
                    }
                }

                vc.CmrReverseX      = isRevsX;
                vc.CmrReverseY      = isRevsY;
                vc.CmrExposure      = exposure;
                vc.CmrGain          = gain;
                vc.LightChnNames    = _lightNames == null ? new string[] { } : _lightNames;
                vc.LightIntensities = intensities == null ? new int[] { } : intensities;
                vc.AxisNames        = _cfgAxisNames == null ? new string[] { } : _cfgAxisNames;
                vc.AxisPositions    = axisPos == null ? new double[] { } : axisPos;
                if (!vm.ContainSingleVisionCfgByName(programName))
                {
                    vc.Name        = programName;
                    vc.OwnerAssist = Name;
                    vm.AddSingleVisionCfg(programName, vc);
                }
                else
                {
                    vm.Save();
                }

                errorInfo = "Success";
                ret       = true;
            } while (false);
LoopExit:
            return(ret);
        }
コード例 #30
0
        DevNodeCategory _currNodeCategory = DevNodeCategory.MotionDaqDev; //当前点击的节点类型
        private void tvDevs_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)//判断右键
            {
                Point    ClickPoint  = new Point(e.X, e.Y);
                TreeNode nodeClicked = tvDevs.GetNodeAt(ClickPoint);
                if (null == nodeClicked)
                {
                    return;
                }
                tvDevs.SelectedNode = nodeClicked;
                DevNodeInfo nodeInfo = nodeClicked.Tag as DevNodeInfo;
                if (null == nodeInfo)
                {
                    return;
                }
                if (nodeInfo.Categoty == DevNodeCategory.MotionDaqDev)
                {
                    contextMenuDev.Items["ToolStripMenuItemResetDevsModuleCount"].Text = "修改模块数量";
                    if (JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_MotionDaq)).Contains(nodeInfo.DevID))
                    {
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = true;
                        IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(nodeInfo.DevID) as IJFDevice_MotionDaq;
                        if (dev.IsDeviceOpen)
                        {
                            contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "关闭设备";
                        }
                        else
                        {
                            contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "打开设备";
                        }
                    }
                    else
                    {
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = false;
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text    = "无效设备";
                    }
                }
                else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev || nodeInfo.Categoty == DevNodeCategory.TrigCtrlDev)
                {
                    contextMenuDev.Items["ToolStripMenuItemResetDevsModuleCount"].Text = "修改通道数量";
                    if (JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_TrigController)).Contains(nodeInfo.DevID))
                    {
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = true;
                        IJFDevice_TrigController dev = JFHubCenter.Instance.InitorManager.GetInitor(nodeInfo.DevID) as IJFDevice_TrigController;
                        if (dev.IsDeviceOpen)
                        {
                            contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "关闭设备";
                        }
                        else
                        {
                            contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "打开设备";
                        }
                    }
                    else
                    {
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = false;
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text    = "无效设备";
                    }
                }
                else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev)
                {
                    contextMenuDev.Items["ToolStripMenuItemResetDevsModuleCount"].Text = "修改通道数量";
                    if (JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_LightControllerWithTrig)).Contains(nodeInfo.DevID))
                    {
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = true;
                        IJFDevice_LightControllerWithTrig dev = JFHubCenter.Instance.InitorManager.GetInitor(nodeInfo.DevID) as IJFDevice_LightControllerWithTrig;
                        if (dev.IsDeviceOpen)
                        {
                            contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "关闭设备";
                        }
                        else
                        {
                            contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "打开设备";
                        }
                    }
                    else
                    {
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = false;
                        contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text    = "无效设备";
                    }
                }
            }
            else if (e.Button == MouseButtons.Left) //左键
            {
                Point    ClickPoint  = new Point(e.X, e.Y);
                TreeNode nodeClicked = tvDevs.GetNodeAt(ClickPoint);
                if (null == nodeClicked)
                {
                    return;
                }
                DevNodeInfo nodeInfo = nodeClicked.Tag as DevNodeInfo;
                if (null == nodeInfo)
                {
                    return;
                }
                panel1.Controls.Clear();
                _currNodeCategory = nodeInfo.Categoty;
                switch (nodeInfo.Categoty)
                {
                case DevNodeCategory.MotionDaqDev:
                    timer1.Enabled = false;
                    break;

                case DevNodeCategory.DioModule:
                    ucDioNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex);
                    panel1.Controls.Add(ucDioNames);
                    ucDioNames.Dock = DockStyle.Fill;
                    timer1.Enabled  = true;
                    break;

                case DevNodeCategory.MotionModule:
                    timer1.Enabled = true;
                    ucAxisNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex);
                    panel1.Controls.Add(ucAxisNames);
                    ucAxisNames.Dock = DockStyle.Fill;
                    timer1.Enabled   = true;
                    break;

                case DevNodeCategory.AioModule:
                    ucAioNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex);
                    panel1.Controls.Add(ucAioNames);
                    ucAioNames.Dock = DockStyle.Fill;
                    timer1.Enabled  = true;
                    break;

                case DevNodeCategory.CmpTrigModule:
                    ucCmpTrigNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex);
                    panel1.Controls.Add(ucCmpTrigNames);
                    ucCmpTrigNames.Dock = DockStyle.Fill;
                    timer1.Enabled      = true;
                    break;

                case DevNodeCategory.TrigCtrlDev:
                    ucTrigCtrlNames.UpdateChannelsInfo(nodeInfo.DevID);
                    panel1.Controls.Add(ucTrigCtrlNames);
                    ucTrigCtrlNames.Dock = DockStyle.Fill;
                    timer1.Enabled       = true;
                    break;

                case DevNodeCategory.LightCtrlTDev:
                    ucLightCtrlNames.UpdateChannelsInfo(nodeInfo.DevID);
                    panel1.Controls.Add(ucLightCtrlNames);
                    ucLightCtrlNames.Dock = DockStyle.Fill;
                    timer1.Enabled        = true;
                    break;
                }
            }
        }