Ejemplo n.º 1
0
 public void SetStationChnType(JFStationBase station, NamedChnType chnType)
 {
     _station = station;
     _chnType = chnType;
     if (_isFormLoaded)
     {
         UpdateStation2UI();
     }
 }
Ejemplo n.º 2
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            if (_station == null)
            {
                errorInfo = "工站未设置/空值";
                return(false);
            }
            NamedChnType chnType    = (NamedChnType)GetInitParamValue(PN_DevChnType);
            string       devChnName = GetInitParamValue(PN_DevChnName) as string;

            return(_station.OpenChnDevice(chnType, devChnName, out errorInfo));
        }
Ejemplo n.º 3
0
 public override JFParamDescribe GetInitParamDescribe(string name)
 {
     if (name == PN_DevChnName)
     {
         NamedChnType chnType = (NamedChnType)GetInitParamValue(PN_DevChnType);
         if (_station != null && chnType != NamedChnType.None)
         {
             string[] devChnNames = _station.AllDecDevChnNames(chnType);
             return(JFParamDescribe.Create(PN_DevChnName, typeof(string), JFValueLimit.Options, devChnNames));
         }
         //日后添加可选的设备名称
         //if(_station != null)
         //    string[] allDevNames =
     }
     return(base.GetInitParamDescribe(name));
 }
Ejemplo n.º 4
0
        protected override bool InitializeGenuine(out string errorInfo)
        {
            NamedChnType chnType = (NamedChnType)GetInitParamValue(PN_DevChnType);

            if (chnType == NamedChnType.None)
            {
                errorInfo = PN_DevChnType + " 未设置";
                return(false);
            }
            string devChnName = GetInitParamValue(PN_DevChnName) as string;

            if (string.IsNullOrEmpty(devChnName))
            {
                errorInfo = PN_DevChnName + " 未设置";
                return(false);
            }

            errorInfo = "Success";
            return(true);
        }
        /// <summary>
        /// 将界面上的内容保存到Station配置中
        /// </summary>
        /// <returns></returns>
        bool Save2Station(out string errorInfo)
        {
            errorInfo = "Success";
            if (_station == null)
            {
                return(true);
            }
            bool          isCheckOK   = true;
            StringBuilder sbErrorInfo = new StringBuilder();

            //先检查所有参数合法性
            foreach (TabPage tp in tabControlCF1.TabPages)
            {
                DataGridView dgv     = tp.Controls[0] as DataGridView;
                NamedChnType chnType = (NamedChnType)tp.Tag;
                foreach (DataGridViewRow row in dgv.Rows)
                {
                    List <List <string> > locAndGlobMaps = null;
                    string[] allGlobChnNamesInStation    = null; //所有可供绑定的全局通道名称
                    switch (chnType)
                    {
                    case NamedChnType.Di:    //数字输入
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Di];
                        allGlobChnNamesInStation = _station.DINames;
                        break;

                    case NamedChnType.Do:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Do];
                        allGlobChnNamesInStation = _station.DONames;
                        break;

                    case NamedChnType.Axis:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Axis];
                        allGlobChnNamesInStation = _station.AxisNames;
                        break;

                    case NamedChnType.CmpTrig:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.CmpTrig];
                        allGlobChnNamesInStation = _station.CmpTrigNames;
                        break;

                    case NamedChnType.Ai:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Ai];
                        allGlobChnNamesInStation = _station.AINames;
                        break;

                    case NamedChnType.Ao:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Ao];
                        allGlobChnNamesInStation = _station.AONames;
                        break;

                    case NamedChnType.Camera:
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Camera];
                        allGlobChnNamesInStation = _station.CameraNames;
                        break;

                    case NamedChnType.Light:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Light];
                        allGlobChnNamesInStation = _station.LightChannelNames;
                        break;

                    case NamedChnType.Trig:    //数字输入
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Trig];
                        allGlobChnNamesInStation = _station.TrigChannelNames;
                        break;

                    default:
                        continue;
                    }
                    string chnLocName = row.Cells[0].Value as string;//站内通道名称
                    //string currGlobName = null;//当前绑定的全局通道名
                    //foreach (List<string> kv in locAndGlobMaps)
                    //    if (kv[0] == chnLocName)
                    //        currGlobName = kv[1];
                    DataGridViewComboBoxCell cellGlobNames = row.Cells[1] as DataGridViewComboBoxCell;
                    string currGlobNameSel = cellGlobNames.Value as string; //当前所选的全局通道名称
                    if (string.IsNullOrEmpty(currGlobNameSel))
                    {
                        isCheckOK = false;
                        sbErrorInfo.AppendLine("站内" + chnType.ToString() + "通道:\"" + chnLocName + "\"未绑定全局ID");
                    }
                    else
                    {
                        if (null == allGlobChnNamesInStation || !allGlobChnNamesInStation.Contains(currGlobNameSel))
                        {
                            isCheckOK = false;
                            sbErrorInfo.AppendLine("站内" + chnType.ToString() + "通道:\"" + chnLocName + "\n绑定的全局ID = \"" + currGlobNameSel + "\"在工站设备表中不存在");
                        }
                    }
                }
            }
            if (!isCheckOK)
            {
                errorInfo = sbErrorInfo.ToString();
                return(false);
            }
            //保存所有参数

            foreach (TabPage tp in tabControlCF1.TabPages)
            {
                DataGridView dgv     = tp.Controls[0] as DataGridView;
                NamedChnType chnType = (NamedChnType)tp.Tag;
                foreach (DataGridViewRow row in dgv.Rows)
                {
                    string locName  = row.Cells[0].Value as string;
                    string globName = row.Cells[1].Value as string;
                    List <List <string> > locGlobMappings = _station.DeclearedDevChnMapping[chnType];
                    foreach (List <string> lg in locGlobMappings)
                    {
                        if (lg[0] == locName)
                        {
                            lg[1] = globName;
                            break;
                        }
                    }
                }
            }
            _station.SaveCfg();
            return(true);
        }
        /// <summary>
        /// 将Station的名称映射表加载到界面上
        /// </summary>
        void LoadStation()
        {
            if (_station == null)
            {
                return;
            }
            foreach (TabPage tp in tabControlCF1.TabPages)
            {
                DataGridView dgv     = tp.Controls[0] as DataGridView;
                NamedChnType chnType = (NamedChnType)tp.Tag;
                foreach (DataGridViewRow row in dgv.Rows)
                {
                    List <List <string> > locAndGlobMaps = null;
                    string[] allGlobChnNamesInStation    = null; //所有可供绑定的全局通道名称
                    switch (chnType)
                    {
                    case NamedChnType.Di:    //数字输入
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Di];
                        allGlobChnNamesInStation = _station.DINames;
                        break;

                    case NamedChnType.Do:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Do];
                        allGlobChnNamesInStation = _station.DONames;
                        break;

                    case NamedChnType.Axis:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Axis];
                        allGlobChnNamesInStation = _station.AxisNames;
                        break;

                    case NamedChnType.CmpTrig:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.CmpTrig];
                        allGlobChnNamesInStation = _station.CmpTrigNames;
                        break;

                    case NamedChnType.Ai:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Ai];
                        allGlobChnNamesInStation = _station.AINames;
                        break;

                    case NamedChnType.Ao:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Ao];
                        allGlobChnNamesInStation = _station.AONames;
                        break;

                    case NamedChnType.Camera:
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Camera];
                        allGlobChnNamesInStation = _station.CameraNames;
                        break;

                    case NamedChnType.Light:    //
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Light];
                        allGlobChnNamesInStation = _station.LightChannelNames;
                        break;

                    case NamedChnType.Trig:    //数字输入
                        locAndGlobMaps           = _station.DeclearedDevChnMapping[NamedChnType.Trig];
                        allGlobChnNamesInStation = _station.TrigChannelNames;
                        break;

                    default:
                        continue;
                    }
                    string chnLocName   = row.Cells[0].Value as string; //站内通道名称
                    string currGlobName = null;                         //当前绑定的全局通道名
                    foreach (List <string> kv in locAndGlobMaps)
                    {
                        if (kv[0] == chnLocName)
                        {
                            currGlobName = kv[1];
                        }
                    }
                    DataGridViewComboBoxCell cellGlobNames = row.Cells[1] as DataGridViewComboBoxCell;
                    cellGlobNames.Items.Clear();
                    if (allGlobChnNamesInStation != null)
                    {
                        foreach (string s in allGlobChnNamesInStation)
                        {
                            cellGlobNames.Items.Add(s);
                        }
                    }
                    if (!string.IsNullOrEmpty(currGlobName))
                    {
                        cellGlobNames.Value = currGlobName;
                        if (allGlobChnNamesInStation == null || !allGlobChnNamesInStation.Contains(currGlobName))
                        {
                            cellGlobNames.Style.ForeColor = Color.Red;
                        }
                        else
                        {
                            cellGlobNames.Style.ForeColor = Color.Black;
                        }
                    }
                    else
                    {
                        cellGlobNames.Value = "";
                    }
                }
            }
        }