コード例 #1
0
ファイル: JFHubCenter.cs プロジェクト: xhyangxianjun/ASMZZZ
        /// <summary>
        /// 关闭工站/设备,释放各种资源
        /// </summary>
        public void Close()
        {
            string errInfo = "";
            ///关闭工站
            IJFMainStation mainStation = StationMgr.MainStation;

            if (null != mainStation)
            {
                mainStation.Stop(out errInfo);
            }
            string[] stationNames = StationMgr.AllStationNames();
            if (null != stationNames && stationNames.Length > 0)
            {
                foreach (string stationName in stationNames)
                {
                    IJFStation station = StationMgr.GetStation(stationName);
                    station.Stop();
                }
            }
            ///关闭所有设备
            string[] deviceIDs = InitorManager.GetIDs(typeof(IJFDevice));
            if (null != deviceIDs && deviceIDs.Length > 0)
            {
                foreach (string devID in deviceIDs)
                {
                    IJFDevice dev = InitorManager.GetInitor(devID) as IJFDevice;
                    dev.CloseDevice();
                }
            }

            ///释放其他对象
            ///添加代码 ...
        }
コード例 #2
0
        public IJFStation GetStation(string stationName)
        {
            //foreach (IJFStation station in _lstDeclearStations) //查询申明的工站列表
            //    if (station.Name == stationName)
            //        return station;
            JFInitorManager initorMgr = JFHubCenter.Instance.InitorManager;

            string[] allInitorStation = initorMgr.GetIDs(typeof(IJFStation)); //通过架构UI创建的工站对象
            if (null == allInitorStation)
            {
                return(null);
            }
            foreach (string stName in allInitorStation)
            {
                if (stationName == stName)
                {
                    return(initorMgr.GetInitor(stationName) as IJFStation);
                }
            }
            return(null);
        }
コード例 #3
0
        ///// <summary>
        ///// 通道类型DI 数字量输入
        ///// </summary>
        //public static string CategoryDI = "DI";

        ///// <summary>
        ///// 通道类型DO 数字量输出
        ///// </summary>
        //public static string CategoryDO = "DO";
        //public static string CategoryAxis = "Axis";
        //public static string CategoryAI = "AI";//
        //public static string CategoryAO = "AO";

        //public static string CategoryCmpTrig = "CmpTrig";

        //public static string CategoryLightChn = "LightChn";
        //public static string CategoryTrigChn = "TrigChn";//触发控制器通道

        /// <summary>
        /// 检查DIO/轴...等设备通道是否存在
        /// </summary>
        /// <param name="category"></param>
        /// <param name="name"></param>
        /// <param name="dev"></param>
        /// <param name="ci"></param>
        /// <param name="errorInfo"></param>
        /// <returns></returns>
        public static bool CheckChannel(JFDevCellType cellType, string name, out IJFDevice dev, out JFDevCellInfo ci, out string errorInfo)
        {
            dev       = null;
            ci        = null;
            errorInfo = "Success";


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if (cellInfo.ChannelIndex >= md.TrigChannelCount)
                {
                    errorInfo = "LightTrig:\"" + name + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备触发通道数量: " + md.TrigChannelCount;
                    return(false);
                }
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else
            {
                errorInfo = "不支持的参数项\"CellType\" = " + cellType.ToString();
            }
            return(false);
        }
コード例 #4
0
        void _AddCmrNames()
        {
            string[]        allChnNames   = null; //系统中所有已命名的通道
            string[]        existChnNames = null; //已存在的通道名称
            JFInitorManager initorMgr     = JFHubCenter.Instance.InitorManager;

            allChnNames   = initorMgr.GetIDs(typeof(IJFDevice_Camera));
            existChnNames = _station.CameraNames; //工站中已有的DI通道名称

            if (null == allChnNames || 0 == allChnNames.Length)
            {
                MessageBox.Show("不存在" + _chnType.ToString() + "命名通道");
                return;
            }

            List <string> lstAddNames = new List <string>(); //可供添加的DI通道名称

            if (null == existChnNames || 0 == existChnNames.Length)
            {
                lstAddNames.AddRange(allChnNames);
            }
            else
            {
                foreach (string chnName in allChnNames)
                {
                    if (!existChnNames.Contains(chnName))
                    {
                        lstAddNames.Add(chnName);
                    }
                }
            }

            if (lstAddNames.Count == 0)
            {
                MessageBox.Show("没有可供添加的" + _chnType.ToString() + "命名通道");
                return;
            }
            List <string> lstAddInfos = new List <string>();

            foreach (string addName in lstAddNames)
            {
                StringBuilder    sbDevInfo  = new StringBuilder();
                IJFDevice_Camera cmr        = initorMgr.GetInitor(addName) as IJFDevice_Camera;
                string[]         paramNames = cmr.InitParamNames;
                if (null != paramNames)
                {
                    foreach (string paramName in paramNames)
                    {
                        sbDevInfo.Append(paramName + ":" + cmr.GetInitParamValue(paramName).ToString() + " ");
                    }
                }

                lstAddInfos.Add(sbDevInfo.ToString());
            }
            FormAddNames frm = new FormAddNames();

            frm.Text = "为工站:" + _station.Name + " 添加Camera命名通道";
            frm.SetAvailedNames(lstAddNames.ToArray(), lstAddInfos.ToArray());
            if (DialogResult.OK == frm.ShowDialog())
            {
                string[] chnNamesWillAdd = null;
                string[] chnInfosWillAdd = null;
                frm.GetSelectNameInfos(out chnNamesWillAdd, out chnInfosWillAdd);
                for (int i = 0; i < chnNamesWillAdd.Length; i++)
                {
                    string chnName = chnNamesWillAdd[i];
                    _station.AddCamera(chnName);
                }
                _station.SaveCfg();
                UpdateStation2UI();
            }
        }