Пример #1
0
        /// <summary>
        /// 打开/关闭设备
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolStripMenuItemOpenCloseDev_Click(object sender, EventArgs e)
        {
            DevNodeInfo nodeInfo = tvDevs.SelectedNode.Tag as DevNodeInfo;
            IJFDevice   dev      = JFHubCenter.Instance.InitorManager.GetInitor(nodeInfo.DevID) as IJFDevice;

            if (dev.IsDeviceOpen)
            {
                int nRet = dev.CloseDevice();
                if (nRet != 0)
                {
                    MessageBox.Show("关闭设备失败!错误信息 :" + dev.GetErrorInfo(nRet));
                }
                else
                {
                    MessageBox.Show("设备已关闭");
                }
            }
            else
            {
                int nRet = dev.OpenDevice();
                if (nRet != 0)
                {
                    MessageBox.Show("打开设备失败!错误信息 :" + dev.GetErrorInfo(nRet));
                }
                else
                {
                    MessageBox.Show("设备已打开!");
                }
            }
        }
Пример #2
0
        public bool Action()
        {
            _startPfCnt = JFFunctions.PerformanceCounter();
            if (!IsInitOK)
            {
                _endPfCnt        = JFFunctions.PerformanceCounter();
                _actionErrorInfo = "初始化未完成";
                return(false);
            }
            IJFDevice dev = JFHubCenter.Instance.InitorManager.GetInitor(_devID) as IJFDevice;

            if (null == dev)
            {
                _endPfCnt        = JFFunctions.PerformanceCounter();
                _actionErrorInfo = "设备不存在,DevID = " + _devID;
                return(false);
            }

            int errCode = 0;

            if (_isOpen)
            {
                errCode = dev.OpenDevice();
            }
            else
            {
                errCode = dev.CloseDevice();
            }
            _endPfCnt = JFFunctions.PerformanceCounter();
            if (0 != errCode)
            {
                _actionErrorInfo = (_isOpen ? "打开" : "关闭") + "设备失败:" + dev.GetErrorInfo(errCode);
                return(false);
            }
            _actionErrorInfo = "Success";
            return(true);
        }
Пример #3
0
        /// <summary>
        /// 打开并使能设备通道
        /// </summary>
        /// <param name="errInfo"></param>
        /// <returns></returns>
        public bool OpenDev(out string errInfo)
        {
            errInfo = "Success";
            if (string.IsNullOrEmpty(Name))
            {
                errInfo = "名称未设置/空字串";
                return(false);
            }

            JFDevCellInfo ci = CellInfo();

            if (null == ci)
            {
                errInfo = "通道名称:\"" + Name + "\"在设备名称表中不存在";
                return(false);
            }

            IJFDevice dev = Device();

            if (dev == null)
            {
                errInfo = "通道:\"" + Name + "\"所属设备:\"" + ci.DeviceID + "\"在设备表中不存在";
                return(false);
            }

            if (!dev.IsDeviceOpen)
            {
                int errCode = dev.OpenDevice();
                if (0 != errCode)
                {
                    errInfo = "通道:\"" + Name + "\"所属设备:\"" + ci.DeviceID + "\"打开失败:" + dev.GetErrorInfo(errCode);
                    return(false);
                }
            }

            //switch(CellType)
            //{
            //    case JFDevCellType.Axis:
            //        {
            //            IJFDevice_MotionDaq devMD = dev as IJFDevice_MotionDaq;
            //            if(ci.ModuleIndex>= devMD.McCount)
            //            {
            //                errInfo = CellType + "通道:\"" + Name + "\"模块序号超过设备:\"" + ci.DeviceID + "\"允许范围0~" + (devMD.McCount - 1);
            //                return false;
            //            }
            //            IJFModule_Motion mm = devMD.GetMc(ci.ModuleIndex);
            //            if(ci.ChannelIndex >= mm.AxisCount)
            //            {
            //                errInfo = CellType + "通道:\"" + Name + "\"通道序号超过模块:\"" + ci.DeviceID + "-" + ci.ModuleIndex + "\"允许范围0~" + (mm.AxisCount - 1);
            //                return false;
            //            }

            //        }
            //        break;
            //    case JFDevCellType.Light:
            //        break;
            //    case JFDevCellType.Trig:
            //        break;
            //}


            return(true);
        }