예제 #1
0
        //delegate void dlgtUpdateIO();
        public void UpdateIO()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(UpdateIO));
                return;
            }
            if (null == _dio)
            {
                return;
            }

            if (_ioIndex < 0 || (_isDo?_ioIndex >= _dio.DOCount:_ioIndex >= _dio.DICount))
            {
                return;
            }
            bool isSigOn = false;

            if (0 != (_isDo ? _dio.GetDO(_ioIndex, out isSigOn): _dio.GetDI(_ioIndex, out isSigOn)))
            {
                return;
            }
            IsTurnOn = isSigOn;
        }
예제 #2
0
        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);
                }
            }
        }
        /// <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);
            }
        }
예제 #4
0
        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);
                }
            }
        }