Пример #1
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;
        }
Пример #2
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();
        }
Пример #3
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;
                }
            }
        }