예제 #1
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();
        }
예제 #2
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);
        }
예제 #3
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);
            }
        }
예제 #4
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();
        }
예제 #5
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运动开始");
        }
예제 #6
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?"去使能":"使能") + "成功");
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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;
                }
            }
        }
예제 #11
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;
                }
            }
        }
예제 #12
0
        void AdjustUI()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(AdjustUI));
                return;
            }

            while (tabControlCF1.TabCount > 1)
            {
                tabControlCF1.TabPages.RemoveAt(tabControlCF1.TabCount - 1);
            }

            gbInitParams.Controls.Clear();

            if (null == _dev)
            {
                lbModel.Text        = "空";
                lbID.Text           = "空";
                lbOpend.Text        = "空";
                btOpenClose.Enabled = false;
                btOpenClose.Text    = "空设备";
                return;
            }
            else //更新设备信息
            {
                lbModel.Text = _dev.DeviceModel;
                lbID.Text    = _id;
                //UpdateDevice();

                int   locY      = 20;
                int   locX      = 5;
                Label lbDevInit = new Label();
                lbDevInit.Text     = _dev.IsInitOK?"初始化完成":"初始化失败";
                lbDevInit.Location = new Point(locX, locY);
                gbInitParams.Controls.Add(lbDevInit);
                locY += 28;
                for (int i = 0; i < _dev.InitParamNames.Length; i++)
                {
                    UcJFParamEdit ucParam = new UcJFParamEdit();
                    ucParam.SetParamDesribe(_dev.GetInitParamDescribe(_dev.InitParamNames[i]));
                    ucParam.SetParamValue(_dev.GetInitParamValue(_dev.InitParamNames[i]));
                    ucParam.Enabled  = false;
                    ucParam.Location = new Point(locX, locY);
                    gbInitParams.Controls.Add(ucParam);
                    ucParam.Width = gbInitParams.Width - 20;
                    locY          = ucParam.Bottom + 2;
                }

                if (_dev.DioCount > 0)
                {
                    ///fmDios = new FormDios();
                    for (int i = 0; i < _dev.DioCount; i++)
                    {
                        fmDios.AddModule(_dev.GetDio(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "DIO模块";
                    tabPage.Name      = "DioModules";
                    tabPage.BackColor = fmDios.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmDios.TopLevel        = false;
                    fmDios.FormBorderStyle = FormBorderStyle.None;
                    fmDios.Dock            = DockStyle.Fill;
                    fmDios.Parent          = tabPage;
                    fmDios.Visible         = true;
                    tabPage.Controls.Add(fmDios);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.McCount > 0)
                {
                    //fmMotions = new FormMotions();
                    for (int i = 0; i < _dev.McCount; i++)
                    {
                        fmMotions.AddModule(_dev.GetMc(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "Motion模块";
                    tabPage.Name      = "MotionModules";
                    tabPage.BackColor = fmMotions.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmMotions.TopLevel        = false;
                    fmMotions.FormBorderStyle = FormBorderStyle.None;
                    fmMotions.Dock            = DockStyle.Fill;
                    fmMotions.Parent          = tabPage;
                    fmMotions.Visible         = true;
                    tabPage.Controls.Add(fmMotions);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.CompareTriggerCount > 0)
                {
                    for (int i = 0; i < _dev.CompareTriggerCount; i++)
                    {
                        fmCmprTrigs.AddModule(_dev.GetCompareTrigger(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "CmprTrig模块";
                    tabPage.Name      = "CmprTrigModule";
                    tabPage.BackColor = fmCmprTrigs.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmCmprTrigs.TopLevel        = false;
                    fmCmprTrigs.FormBorderStyle = FormBorderStyle.None;
                    fmCmprTrigs.Dock            = DockStyle.Fill;
                    fmCmprTrigs.Parent          = tabPage;
                    fmCmprTrigs.Visible         = true;
                    tabPage.Controls.Add(fmCmprTrigs);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.AioCount > 0)
                {
                    for (int i = 0; i < _dev.AioCount; i++)
                    {
                        fmAios.AddModule(_dev.GetAio(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "AIO模块";
                    tabPage.Name      = "AioModules";
                    tabPage.BackColor = fmAios.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmAios.TopLevel        = false;
                    fmAios.FormBorderStyle = FormBorderStyle.None;
                    fmAios.Dock            = DockStyle.Fill;
                    fmAios.Parent          = tabPage;
                    fmAios.Visible         = true;
                    tabPage.Controls.Add(fmAios);  //tabPage选项卡添加一个窗体对象
                }
            }

            tabControlCF1.SelectedIndex = 0;
            UpdateModuleStatus();
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
        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;
                }
            }
        }
예제 #15
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);
        }