bool setValueUniverse(int groupindex, int offset, string dataTypeStr, int coe_reverse, string valueStr) { float value_f; string offsetAddOne = MAppConfig.getValueByName("offsetAddOne"); if (offsetAddOne != "0") { offset += 1;//此处的内存对应的是modbus协议中的地址,比offset要多1。 } else { offset += 0;//只在配置为0时才不加1 } try { if (valueStr.Contains('.'))//有些点虽为INT型,但最终的值是float。风速为INT,modbus值为988这样。 { value_f = float.Parse(valueStr); } else { value_f = int.Parse(valueStr); } } catch (Exception) { return(false); } return(true); }
/// <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); } }
public IActionResult GetServerVersion([FromForm] string AppGuid) { MAppConfig config = new MAppConfig(); return(Ok(config.GetAppVersion(appguid: AppGuid))); }