示例#1
0
        /// <summary>初始化HubCenter</summary>
        void Initialize()
        {
            dataPool = new JFDataPool();

            string chkError   = "";
            string sysCfgFile = SystemCfgFilePath;

            while (string.IsNullOrEmpty(sysCfgFile) || //系统配置文件未设置
                   !File.Exists(sysCfgFile) ||                     //系统配置文件已设置,但是文件不存在
                   !_CheckSysCfg(sysCfgFile, false, out chkError)) //系统文件已存在,但是格式不正确
            {
                FormSelCfg fm = new FormSelCfg();
                if (string.IsNullOrEmpty(sysCfgFile))
                {
                    fm.Tips = "系统配置文件未设置!";
                }
                else if (!File.Exists(sysCfgFile))
                {
                    fm.Tips = "系统配置文件:" + "\"" + sysCfgFile + "\"不存在!\n请检查路径或选择/创建新的配置文件";
                }
                else//(!_CheckSysCfg(SystemCfgFilePath,false)) //文件已存在,但格式不正确(缺少必要的数据项)
                {
                    fm.Tips = "系统配置文件:" + "\"" + sysCfgFile + "\"格式错误!\nError:" + chkError + "\n请检查文件或选择/创建新的配置文件";
                }

                fm.ShowDialog();//////////FormInitHub.ShowDialog()中有退出程序的出口,如果运行到下一步,肯定是已经选择了配置文件
                sysCfgFile = fm.SysCfgFilePath;
                if (_CheckSysCfg(sysCfgFile, true, out chkError))
                {
                    SetSystemCfgFilePath(sysCfgFile);//退出程序,重新启动
                    break;
                }
            }//end while , 系统配置文件检查OK
            SystemCfg = new JFXCfg();
            SystemCfg.Load(sysCfgFile, false);
            InitorHelp = new JFinitializerHelper();
            //加载JFDll库文件
            List <string> dllFiles = SystemCfg.GetItemValue(CK_ExpandDllFiles) as List <string>;

            foreach (string dllFile in dllFiles)
            {
                try
                {
                    InitorHelp.AppendDll(dllFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Hub-Center 加载dll = \"" + dllFile + "\"异常:\n" + ex);
                }
            }

            _mdCellNameMgr = new JFDevCellNameManeger(sysCfgFile);//运动控制卡单元名称管理



            return;
        }
示例#2
0
        /// <summary>确定创建Initor对象</summary>
        private void btOK_Click(object sender, EventArgs e)
        {
            if (dgvTypes.SelectedRows == null || dgvTypes.SelectedRows.Count == 0)
            {
                MessageBox.Show("请选择需要创建的设备类型");
                return;
            }
            if (string.IsNullOrWhiteSpace(tbID.Text))
            {
                MessageBox.Show("设备ID不能为空,请重新输入");
                tbID.Focus();
                return;
            }

            if (!_isFixedID && JFHubCenter.Instance.InitorManager.ContainID(tbID.Text))
            {
                IJFInitializable dev         = JFHubCenter.Instance.InitorManager.GetInitor(tbID.Text);
                string           disTypeName = JFinitializerHelper.DispalyTypeName(dev.GetType());
                MessageBox.Show(string.Format("Initor列表中已存在ID = \"{0}\" Type = \"{1}\"的设备\n请重新输入ID!", tbID.Text, disTypeName));
                tbID.Focus();
                return;
            }
            //IJFDevice newDev = JFHubCenter.Instance.InitorHelp.CreateInstance(dgvTypes.SelectedRows[0].Cells[0].Value.ToString()) as IJFDevice;

            //for (int i = 2; i < gbParams.Controls.Count;i++)
            for (int i = 0; i < panelParams.Controls.Count; i++)
            {
                //UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit;
                UcJFParamEdit pe       = panelParams.Controls[i] as UcJFParamEdit;
                object        paramVal = null;
                if (!pe.GetParamValue(out paramVal))
                {
                    MessageBox.Show("初始化参数:\"" + pe.Name + "\"获取失败!Error:" + pe.GetParamErrorInfo());
                    //newDev.Dispose();
                    pe.Focus();
                    return;
                }
                if (!initor.SetInitParamValue(initor.InitParamNames[i], paramVal))
                {
                    MessageBox.Show(string.Format("设置初始化参数失败:Name = {0},Value = {1}", initor.InitParamNames[i], paramVal.ToString()));
                    //newDev.Dispose();
                    pe.Focus();
                    return;
                }
            }

            DialogResult = DialogResult.OK;
        }
示例#3
0
        private void FormDevMgr_Load(object sender, EventArgs e)
        {
            isEditting        = false;
            btCancel.Enabled  = false;
            btInit.Enabled    = false;
            btRemove.Enabled  = false;
            btDebug.Enabled   = false;
            btCfg.Enabled     = false;
            chkSelfUI.Enabled = false;
            ///加载现有设备到列表中
            dgvDevs.Rows.Clear();
            string[] devIDs = JFHubCenter.Instance.InitorManager.GetIDs(InitorType);
            foreach (string devID in devIDs)
            {
                IJFInitializable        dev    = JFHubCenter.Instance.InitorManager[devID];
                DataGridViewRow         row    = new DataGridViewRow();
                DataGridViewTextBoxCell cellID = new DataGridViewTextBoxCell();
                cellID.Value = devID;
                row.Cells.Add(cellID);

                DataGridViewTextBoxCell cellModel = new DataGridViewTextBoxCell();
                cellModel.Value = JFinitializerHelper.DispalyTypeName(dev.GetType());
                row.Cells.Add(cellModel);
                DataGridViewTextBoxCell cellType = new DataGridViewTextBoxCell();
                cellType.Value = dev.GetType().Name;
                row.Cells.Add(cellType);
                dgvDevs.Rows.Add(row);
                if (!dev.IsInitOK)
                {
                    row.DefaultCellStyle.ForeColor = Color.Red;
                }
            }

            dgvDevs.ClearSelection();
            RemoveAllPEs();
        }
示例#4
0
        private void FormDllMgr_Load(object sender, EventArgs e)
        {
            /////配置文件中的dll路径
            List <string>       dllPaths     = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_ExpandDllFiles) as List <string>;
            JFinitializerHelper initorHelper = JFHubCenter.Instance.InitorHelp;

            trvDlls.Nodes.Clear();
            foreach (string dllPath in dllPaths)
            {
                TreeNode dllNode = new TreeNode(dllPath);
                trvDlls.Nodes.Add(dllNode);
                if (!initorHelper.AllApendDllPaths().Contains(dllPath)) //InitorHelp未加载
                {
                    dllNode.ForeColor = Color.Red;
                    continue;
                }
                Type[] types = initorHelper.InstantiatedClassesInDll(dllPath);
                foreach (Type type in types)
                {
                    dllNode.Nodes.Add(type.Name);
                }
            }
            UpdateInitorsView();
        }
示例#5
0
        /// <summary>添加新设备</summary>
        private void btAdd_Click(object sender, EventArgs e)
        {
            FormCreateInitor fm = new FormCreateInitor();

            fm.Text      = "创建" + InitorCaption + "对象";
            fm.MatchType = InitorType;
            if (DialogResult.OK == fm.ShowDialog())
            {
                IJFInitializable newDevice = fm.Initor;
                string           devID     = fm.ID;
                JFHubCenter.Instance.InitorManager.Add(devID, newDevice);


                DataGridViewRow         row    = new DataGridViewRow();
                DataGridViewTextBoxCell cellID = new DataGridViewTextBoxCell();
                cellID.Value = devID;
                row.Cells.Add(cellID);

                DataGridViewTextBoxCell cellModel = new DataGridViewTextBoxCell();
                cellModel.Value = JFinitializerHelper.DispalyTypeName(newDevice.GetType());
                row.Cells.Add(cellModel);
                DataGridViewTextBoxCell cellType = new DataGridViewTextBoxCell();
                cellType.Value = newDevice.GetType().Name;
                row.Cells.Add(cellType);
                dgvDevs.Rows.Add(row);
                newDevice.Initialize();
                if (!newDevice.IsInitOK)
                {
                    btInit.Enabled = true;
                    row.DefaultCellStyle.ForeColor = Color.Red;
                }
                else
                {
                    btInit.Enabled = false;
                }



                /// 更新参数到界面
                dgvDevs.Rows[dgvDevs.Rows.Count - 1].Selected = true;
                RemoveAllPEs();
                string[] iniParamNames = newDevice.InitParamNames;
                if (null == iniParamNames)
                {
                    btEditSave.Enabled = false;
                    return;
                }
                btEditSave.Enabled = true;
                int locY = btInit.Location.Y + btInit.Size.Height + 5;
                foreach (string ipName in iniParamNames)
                {
                    UcJFParamEdit pe = new UcJFParamEdit();
                    pe.Width    = gbParams.Width - 1;
                    pe.Location = new Point(4, locY);
                    pe.SetParamDesribe(newDevice.GetInitParamDescribe(ipName));
                    locY += pe.Height;
                    pe.SetParamValue(newDevice.GetInitParamValue(ipName));
                    pe.IsValueReadOnly = true;
                    gbParams.Controls.Add(pe);
                }

                Type devType = newDevice.GetType();
                if (typeof(IJFDevice_Camera).IsAssignableFrom(devType) ||
                    typeof(IJFDevice_LightController).IsAssignableFrom(devType) ||
                    typeof(IJFDevice_MotionDaq).IsAssignableFrom(devType) ||
                    typeof(IJFDevice_TrigController).IsAssignableFrom(devType) ||
                    typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) //提供调试界面
                {
                    btDebug.Enabled = true;
                    if (typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType))
                    {
                        chkSelfUI.Enabled = true;
                    }
                    else
                    {
                        chkSelfUI.Checked = false;
                        chkSelfUI.Enabled = false;
                    }
                }
                else
                {
                    btDebug.Enabled = false;
                }

                if (typeof(IJFConfigUIProvider).IsAssignableFrom(devType))
                {
                    btCfg.Enabled = true;
                }
                else
                {
                    btCfg.Enabled = false;
                }
            }
        }