示例#1
0
        /// <summary>移除所选设备</summary>
        private void btRemove_Click(object sender, EventArgs e)
        {
            if (dgvDevs.SelectedRows == null || 0 == dgvDevs.SelectedRows.Count)
            {
                MessageBox.Show("请先选择需要移除的" + _initorCaption);
                return;
            }

            DataGridViewRow row = dgvDevs.SelectedRows[0];

            if (JFHubCenter.Instance.StationMgr.DeclearedStationNames.Contains(row.Cells[0].Value.ToString()))
            {
                MessageBox.Show("注册工站不能被移除!");
                return;
            }
            if (DialogResult.Cancel == MessageBox.Show("确定要移除:" + row.Cells[0].Value.ToString() + "?", "移除设备警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
            {
                return;
            }
            JFHubCenter.Instance.InitorManager.Remove(row.Cells[0].Value.ToString()); //从设备管理器中删除
            JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;

            devCfg.Remove(row.Cells[0].Value.ToString());//从设备配置文件中删除
            JFHubCenter.Instance.SystemCfg.NotifyItemChanged(JFHubCenter.CK_InitDevParams);
            JFHubCenter.Instance.SystemCfg.Save();
            MessageBox.Show(_initorCaption + row.Cells[0].Value.ToString() + "已从系统中移除!");
            dgvDevs.Rows.Remove(row);
            RemoveAllPEs();
            dgvDevs.ClearSelection();
        }
示例#2
0
        internal void Clear()
        {
            dictInitors.Clear();
            JFXmlSortedDictionary <string, List <object> > dictInitorParam = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;

            dictInitorParam.Clear();
            JFHubCenter.Instance.SystemCfg.Save();
        }
示例#3
0
        /// <summary>取消编辑,将配置中的参数恢复到界面和对象中</summary>
        private void btCancel_Click(object sender, EventArgs e)
        {
            IJFInitializable dev = JFHubCenter.Instance.InitorManager[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()];
            JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;
            List <object> initParams = devCfg[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()];

            for (int i = 1; i < initParams.Count; i++)
            {
                UcJFParamEdit pe = gbParams.Controls[i + 4] as UcJFParamEdit;
                pe.SetParamValue(initParams[i]);
                pe.IsValueReadOnly = true;
                dev.SetInitParamValue(dev.InitParamNames[i - 1], initParams[i]);
            }
            btInit.Enabled   = !dev.IsInitOK;
            btAdd.Enabled    = true;
            btRemove.Enabled = true;
            //btDebug.Enabled = true;
            isEditting       = false;
            btEditSave.Text  = "编辑参数";
            btCancel.Enabled = false;
            dgvDevs.Enabled  = true;

            Type devType = dev.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;
            }
        }
示例#4
0
        /// <summary>
        /// 从系统中删除一个单相机视觉示教助手
        /// </summary>
        /// <param name="name"></param>
        public void DelSVAssist(string name)
        {
            if (!ContainSVAssistName(name))
            {
                return;
            }
            IJFInitializable initor = JFHubCenter.Instance.InitorManager.GetInitor(name);

            if (typeof(JFSingleVisionAssist) != initor.GetType())
            {
                throw new Exception("DelSVAssist(string name = " + name + ") failed by the initor's type is not JFSingleVisionAssist");
            }
            JFHubCenter.Instance.InitorManager.Remove(name); //从设备管理器中删除
            JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;

            devCfg.Remove(name);//从设备配置文件中删除
            JFHubCenter.Instance.SystemCfg.NotifyItemChanged(JFHubCenter.CK_InitDevParams);
            JFHubCenter.Instance.SystemCfg.Save();
        }
示例#5
0
        bool isEditting; ///是否处于编辑初始化参数状态
        /// <summary>编辑/保存 初始化参数</summary>
        private void btEditSave_Click(object sender, EventArgs e)
        {
            if (!isEditting)//参数未编辑状态
            {
                if (dgvDevs.SelectedRows == null || 0 == dgvDevs.SelectedRows.Count)
                {
                    MessageBox.Show("请选择需要编辑参数的对象");
                    return;
                }

                if (gbParams.Controls.Count <= 5) //没有初始化参数
                {
                    return;
                }

                for (int i = 5; i < gbParams.Controls.Count; i++)
                {
                    UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit;
                    pe.IsValueReadOnly = false;
                }

                dgvDevs.Enabled  = false;
                btEditSave.Text  = "保存";
                btCancel.Enabled = true;
                btInit.Enabled   = false;
                btAdd.Enabled    = false;
                btRemove.Enabled = false;
                btDebug.Enabled  = false;
                isEditting       = true;
            }
            else //编辑完成,需要存储编辑后的参数
            {
                IJFInitializable dev        = JFHubCenter.Instance.InitorManager[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()];
                List <object>    initParams = new List <object>();
                initParams.Add(dev.GetType().AssemblyQualifiedName);//DevType
                for (int i = 5; i < gbParams.Controls.Count; i++)
                {
                    object        paramVal = null;
                    UcJFParamEdit pe       = gbParams.Controls[i] as UcJFParamEdit;
                    if (!pe.GetParamValue(out paramVal))
                    {
                        pe.Focus();
                        MessageBox.Show("参数\"" + dev.InitParamNames[i - 5] + "\"格式错误:" + pe.GetParamErrorInfo());
                        return;
                    }
                    if (!dev.SetInitParamValue(dev.InitParamNames[i - 5], paramVal))
                    {
                        pe.Focus();
                        MessageBox.Show("设置参数\"" + dev.InitParamNames[i - 5] + "\"失败:" + dev.GetInitErrorInfo());
                        return;
                    }
                    //initParams.Add(paramVal); //替换为以下代码,适应数组/基类型混编的参数列表



                    //paramsInCfg.Add(dev.GetInitParamValue(dev.InitParamNames[i])); 本行代码用以下代码代替,以支持有限的 简单类型 + 数组(列表)类型的组合
                    //暂时的解决方法:将数组类型转化为字符串存储
                    Type paramType = dev.GetInitParamDescribe(dev.InitParamNames[i - 5]).ParamType;
                    SerializableAttribute[] sas = paramType.GetCustomAttributes(typeof(SerializableAttribute), false) as SerializableAttribute[];
                    if (sas != null && sas.Length > 0)     //如果是可序列化的类型,直接保存序列化后的文本
                    {
                        StringBuilder buffer     = new StringBuilder();
                        XmlSerializer serializer = new XmlSerializer(paramType);
                        using (TextWriter writer = new StringWriter(buffer))
                        {
                            serializer.Serialize(writer, paramVal);
                        }
                        string xmlTxt = buffer.ToString();
                        initParams.Add(xmlTxt); // paramsInCfg.Add(xmlTxt);
                    }
                    else
                    {
                        if (paramType.IsValueType || paramType == typeof(string))     //单值对象和字符串对象直接添加
                        {
                            initParams.Add(paramVal);
                        }
                        else                       //目前支持Array 和 List
                        {
                            if (paramType.IsArray) //参数类型是数组
                            {
                                if (null == paramVal)
                                {
                                    initParams.Add("");
                                }
                                else
                                {
                                    StringBuilder sb          = new StringBuilder();
                                    string        splitString = "$";
                                    for (int j = 0; j < (paramVal as Array).Length; j++)
                                    {
                                        sb.Append((paramVal as Array).GetValue(j).ToString());
                                        if (j < (paramVal as Array).Length - 1)
                                        {
                                            sb.Append(splitString);
                                        }
                                    }
                                    initParams.Add(sb.ToString());//paramsInCfg.Add(string.Join(splitString, paramVal)); //使用ASC 响铃符作为间隔
                                }
                            }
                            else if (typeof(IList).IsAssignableFrom(paramType))     //除了数组之外的队列类型
                            {
                                if (null == paramVal)
                                {
                                    initParams.Add("");
                                }
                                else
                                {
                                    StringBuilder sb          = new StringBuilder();
                                    string        splitString = "$";
                                    for (int j = 0; j < (paramVal as IList).Count; j++)
                                    {
                                        sb.Append((paramVal as IList)[j].ToString());
                                        if (j < (paramVal as IList).Count - 1)
                                        {
                                            sb.Append(splitString);
                                        }
                                    }
                                    initParams.Add(sb.ToString());
                                    //paramsInCfg.Add(string.Join(System.Text.Encoding.ASCII.GetString(new byte[] { 0x07 }), paramVal)); //使用ASC 响铃符作为间隔
                                }
                            }
                        }
                    }
                }
                for (int i = 5; i < gbParams.Controls.Count; i++)
                {
                    UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit;
                    pe.IsValueReadOnly = true;
                }
                if (!dev.Initialize())
                {
                    MessageBox.Show("用当前参数初始化设备失败:" + dev.GetInitErrorInfo());
                }
                JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;
                devCfg[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()] = initParams;
                JFHubCenter.Instance.SystemCfg.NotifyItemChanged(JFHubCenter.CK_InitDevParams);
                JFHubCenter.Instance.SystemCfg.Save();

                btInit.Enabled   = true;
                btAdd.Enabled    = true;
                btRemove.Enabled = true;
                //btDebug.Enabled = true;

                isEditting       = false;
                btEditSave.Text  = "编辑参数";
                btCancel.Enabled = false;
                dgvDevs.Enabled  = true;


                Type devType = dev.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;
                }
            }
        }
示例#6
0
        internal void Init()
        {
            JFXmlSortedDictionary <string, List <object> > devInitParams = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;

            foreach (KeyValuePair <string, List <object> > kv in devInitParams)
            {
                IJFInitializable dev = JFHubCenter.Instance.InitorHelp.CreateInstance(kv.Value[0] as string); // as IJFDevice;
                dictInitors.Add(kv.Key, dev);
                try                                                                                           //尝试初始化
                {
                    string[] paramNames = dev.InitParamNames;
                    if (null != paramNames && paramNames.Length > 0)
                    {
                        for (int i = 0; i < paramNames.Length; i++)
                        {
                            object pr                   = i < kv.Value.Count - 1 ? kv.Value[i + 1] : null;
                            object relParamVal          = null;
                            Type   paramType            = dev.GetInitParamDescribe(paramNames[i]).ParamType;
                            SerializableAttribute[] sas = paramType.GetCustomAttributes(typeof(SerializableAttribute), false) as SerializableAttribute[];
                            if (sas != null && sas.Length > 0) //如果是可序列化的类型,直接保存序列化后的文本
                            {
                                relParamVal = JFFunctions.FromXTString(pr as string, paramType);
                            }
                            else
                            {
                                if (paramType.IsValueType || paramType == typeof(string)) //单值对象和字符串对象直接添加
                                {
                                    relParamVal = pr;
                                }
                                else //目前支持Array 和 List
                                {
                                    if (paramType.IsArray) //参数类型是数组
                                    {
                                        if (null == pr || string.Empty == pr as string)
                                        {
                                            relParamVal = null;
                                        }
                                        else
                                        {
                                            string[] elmts = (pr as string).Split(new char[] { '$' });
                                            relParamVal = GenArrayObject(paramType, elmts.Length);
                                            if (elmts.Length != 0)
                                            {
                                                for (int j = 0; j < elmts.Length; j++)
                                                {
                                                    (relParamVal as Array).SetValue(JFConvertExt.ChangeType(elmts[j], paramType.GetElementType()), j);
                                                }
                                            }
                                        }
                                    }
                                    else if (typeof(IList).IsAssignableFrom(paramType)) //队列类型
                                    {
                                        if (null == pr || string.Empty == pr as string)
                                        {
                                            relParamVal = null;
                                        }
                                        else
                                        {
                                            string[] elmts = (pr as string).Split(new char[] { '$' });
                                            relParamVal = GenListObject(paramType);
                                            if (elmts.Length != 0)
                                            {
                                                for (int j = 0; j < elmts.Length; j++)
                                                {
                                                    (relParamVal as IList).Add(JFConvertExt.ChangeType(elmts[j], paramType.GetElementType()));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            dev.SetInitParamValue(paramNames[i], relParamVal);
                        }
                    }
                    dev.Initialize();
                    if (dev is IJFDevice)
                    {
                        (dev as IJFDevice).OpenDevice();
                        Thread.Sleep(100);
                    }
                }
                catch
                {
                    //初始化发生异常
                }
                //dictInitors.Add(kv.Key, dev);
                //if (dev is IJFStation)
                //{
                //    (dev as IJFStation).WorkStatusChanged += JFHubCenter.Instance.StationMgr.StationWorkStatusChanged;
                //    (dev as IJFStation).CustomStatusChanged += JFHubCenter.Instance.StationMgr.StationCustomStatusChanged;
                //    if (dev is JFCmdWorkBase)
                //        (dev as JFCmdWorkBase).WorkMsg2Outter += JFHubCenter.Instance.StationMgr.StationWorkMsg;
                //}
            }
        }
示例#7
0
        //internal bool SaveCfgWhenAdd { get; set; }

        internal void Add(string id, IJFInitializable dev)
        {
            dictInitors.Add(id, dev);
            JFXmlSortedDictionary <string, List <object> > dictInitorParam = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;
            List <object> paramsInCfg = new List <object>();

            paramsInCfg.Add(dev.GetType().AssemblyQualifiedName);
            for (int i = 0; i < dev.InitParamNames.Length; i++)
            {
                //paramsInCfg.Add(dev.GetInitParamValue(dev.InitParamNames[i])); 本行代码用以下代码代替,以支持有限的 简单类型 + 数组(列表)类型的组合
                //暂时的解决方法:将数组类型转化为字符串存储
                object paramVal             = dev.GetInitParamValue(dev.InitParamNames[i]);
                Type   paramType            = dev.GetInitParamDescribe(dev.InitParamNames[i]).ParamType;
                SerializableAttribute[] sas = paramType.GetCustomAttributes(typeof(SerializableAttribute), false) as SerializableAttribute[];
                if (sas != null && sas.Length > 0)     //如果是可序列化的类型,直接保存序列化后的文本
                {
                    StringBuilder buffer     = new StringBuilder();
                    XmlSerializer serializer = new XmlSerializer(paramType);
                    using (TextWriter writer = new StringWriter(buffer))
                    {
                        serializer.Serialize(writer, paramVal);
                    }
                    string xmlTxt = buffer.ToString();
                    paramsInCfg.Add(xmlTxt);
                }
                else
                {
                    if (paramType.IsValueType || paramType == typeof(string))     //单值对象和字符串对象直接添加
                    {
                        paramsInCfg.Add(paramVal);
                    }
                    else                       //目前支持Array 和 List
                    {
                        if (paramType.IsArray) //参数类型是数组
                        {
                            if (null == paramVal)
                            {
                                paramsInCfg.Add("");
                            }
                            else
                            {
                                StringBuilder sb          = new StringBuilder();
                                string        splitString = "$";
                                for (int j = 0; j < (paramVal as Array).Length; j++)
                                {
                                    sb.Append((paramVal as Array).GetValue(j).ToString());
                                    if (j < (paramVal as Array).Length - 1)
                                    {
                                        sb.Append(splitString);
                                    }
                                }
                                paramsInCfg.Add(sb.ToString());//paramsInCfg.Add(string.Join(splitString, paramVal)); //使用ASC 响铃符作为间隔
                            }
                        }
                        else if (typeof(IList).IsAssignableFrom(paramType))     //除了数组之外的队列类型
                        {
                            if (null == paramVal)
                            {
                                paramsInCfg.Add("");
                            }
                            else
                            {
                                StringBuilder sb          = new StringBuilder();
                                string        splitString = "$";
                                for (int j = 0; j < (paramVal as IList).Count; j++)
                                {
                                    sb.Append((paramVal as IList)[j].ToString());
                                    if (j < (paramVal as IList).Count - 1)
                                    {
                                        sb.Append(splitString);
                                    }
                                }
                                paramsInCfg.Add(sb.ToString());
                                //paramsInCfg.Add(string.Join(System.Text.Encoding.ASCII.GetString(new byte[] { 0x07 }), paramVal)); //使用ASC 响铃符作为间隔
                            }
                        }
                    }
                }
            }
            dictInitorParam.Add(id, paramsInCfg);
            JFHubCenter.Instance.SystemCfg.NotifyItemChanged(JFHubCenter.CK_InitDevParams);
            JFHubCenter.Instance.SystemCfg.Save();
        }