示例#1
0
        /// <summary>
        /// initData
        /// </summary>
        /// <param name="errorStr"></param>
        /// <returns></returns>
        public bool initNodeData(ref string errorStr)
        {
            _dt = null;

            try
            {
                if (_typeStr.Length == 0)
                {
                    return(false);
                }

                string configDirStr = MAppConfig.getValueByName("defaultCfgDir");
                string csvFileName  = configDirStr + "/" + _typeStr + ".csv";// _typeStr是MY1500, 采用MY1500.csv作为模型名
                bool   ret          = CSVReader.readCSV(csvFileName, out _dt);
                if (!ret)
                {
                    return(false);
                }

                for (int i = 0; i < _dt.Rows.Count; i++) //写入各行数据
                {
                    {
                        string ioName = _dt.Rows[i]["path"].ToString();
                        if (ioName.Length == 0)
                        {
                            errorStr = csvFileName + "[path] 列出现空值";
                            return(false);
                        }

                        _ioName2index[ioName] = i;
                    }

                    string groupindexStr = _dt.Rows[i]["groupIndex"].ToString();
                    if (groupindexStr.Length == 0)
                    {
                        errorStr = csvFileName + "[groupIndex] 列出现空值";
                        return(false);
                    }
                    int groupindex = int.Parse(groupindexStr);     //功能码

                    string offsetStr = _dt.Rows[i]["offs"].ToString();
                    if (offsetStr.Length == 0)
                    {
                        errorStr = csvFileName + "[offs] 列出现空值";
                        return(false);
                    }
                    if (offsetStr.Contains(':'))
                    {
                        offsetStr = offsetStr.Substring(0, offsetStr.IndexOf(":"));
                    }
                    int offset = int.Parse(offsetStr);

                    string dataTypeStr = _dt.Rows[i]["dataType"].ToString();
                    if (dataTypeStr.Length == 0)
                    {
                        errorStr = csvFileName + "[dataType] 列出现空值";
                        return(false);
                    }

                    float  coe         = float.Parse(_dt.Rows[i]["coe"].ToString());
                    int    coe_reverse = floatToInt(1.00000000f / coe);//1.0除以0.1得到0.9
                    string valueStr    = "0";
                    if (_dt.Columns.Contains("value"))
                    {
                        valueStr = _dt.Rows[i]["value"].ToString();//如果有value这一列就赋值,否则默认是0
                    }

                    bool ret1 = setValueUniverse(groupindex, offset, dataTypeStr, coe_reverse, valueStr);
                    if (ret1 != true)
                    {
                        return(false);
                    }
                }//for

                return(true);
            }
            catch (Exception e)
            {
                errorStr = e.Message;
                return(false);
            }
        }