public void ReadDeviceInit() { try { if (File.Exists(IniFileName)) { TargetType = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "TargetType", "0")); WarmUpWaitSec = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "WarmUpWaitSec", "360")); WarmUpVoltage = Convert.ToDouble(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "WarmUpVoltage", "10.0")); WarmUpCurrent = Convert.ToDouble(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "WarmUpCurrent", "5.0")); WarmUpLastTime = IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "WarmUpLastTime", " "); WarmUpIntervalMinute = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "WarmUpIntervalMinute", "28800")); DetectorType = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "DetectorType", "0")); SDDMotorMode = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "SDDMotorMode", "3")); DefaultVotage = Convert.ToDouble(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "DefaultVotage", "10")); DefaultCurrent = Convert.ToDouble(IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "DefaultCurrent", "5")); SavePath = IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "SavePath", " "); OpenDataFileName = IniHelper.INIGetStringValue(IniFileName, SectionDevInit, "OpenDataFileName", " "); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void SaveTextureSettings() { try { IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "SampleNameTxt", string.Join(",", SampleNameTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "SampleSnTxt", string.Join(",", SampleSnTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "FaceExpTxt", string.Join(",", FaceExpTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "PeakDegreeTxt", string.Join(",", PeakDegreeTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "TubeVoltageTxt", string.Join(",", TubeVoltageTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "TubeCurrentTxt", string.Join(",", TubeCurrentTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "BMIndexTxt", string.Join(",", BMIndexTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "ScanMethodTxt", ScanMethodTxt.ToString()); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "PsiStepTxt", string.Join(",", PsiStepTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "PsiStartAngleTxt", string.Join(",", PsiStartAngleTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "PsiStopAngleTxt", string.Join(",", PsiStopAngleTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "PhiSpeedTxt", string.Join(",", PhiSpeedTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "MeasureTimeTxt", string.Join(",", MeasureTimeTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "FaceExpTxt", string.Join(",", FaceExpTxt)); IniHelper.INIWriteValue(IniFileName, SectionTextureSetting, "MeasureMethodTxt", MeasureMethodTxt.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void ReadMeasureSettings() { try { if (File.Exists(IniFileName)) { SampleName = IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "SampleName", "SDD_sample_name,LDA_sample_name").Split(','); SampleSn = IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "SampleSn", "01234,56789").Split(','); MeasureMethod = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "MeasureMethod", "0")); StartDegree = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "StartDegree", "150,150,150,150").Split(','), double.Parse); StopDegree = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "StopDegree", "150, 150, 150, 150").Split(','), double.Parse); MeasureStep = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "MeasureStep", "0.05,0.05,0.05,0.05").Split(','), double.Parse); MeasureTime = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "MeasureTime", "15,15,15,15").Split(','), double.Parse); TubeVoltage = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "TubeVoltage", "15,15,15,15").Split(','), double.Parse); TubeCurrent = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "TubeCurrent", "15,15,15,15").Split(','), double.Parse); FiveAxisInUse = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "FiveAxis", "0,0,0,0").Split(','), int.Parse); AnglePsi_Method0 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AnglePsi0", "0,15,30,45").Split(','), double.Parse); AngleX_Method0 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleX0", "0,15,30,45").Split(','), double.Parse); AngleY_Method0 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleY0", "0,15,30,45").Split(','), double.Parse); AngleZ_Method0 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleZ0", "0,15,30,45").Split(','), double.Parse); AngleAlpha_Method0 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleAlpha0", "0,15,30,45").Split(','), double.Parse); AngleBeta_Method0 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleBeta0", "0,15,30,45").Split(','), double.Parse); AnglePsi_Method1 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AnglePsi1", "0,15,30,45").Split(','), double.Parse); AngleX_Method1 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleX1", "0,15,30,45").Split(','), double.Parse); AngleY_Method1 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleY1", "0,15,30,45").Split(','), double.Parse); AngleZ_Method1 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleZ1", "0,15,30,45").Split(','), double.Parse); AngleAlpha_Method1 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleAlpha1", "0,15,30,45").Split(','), double.Parse); AngleBeta_Method1 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleBeta1", "0,15,30,45").Split(','), double.Parse); AnglePsi_Method2 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AnglePsi2", "0,15,30,45").Split(','), double.Parse); AngleX_Method2 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleX2", "0,15,30,45").Split(','), double.Parse); AngleY_Method2 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleY2", "0,15,30,45").Split(','), double.Parse); AngleZ_Method2 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleZ2", "0,15,30,45").Split(','), double.Parse); AngleAlpha_Method2 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleAlpha2", "0,15,30,45").Split(','), double.Parse); AngleBeta_Method2 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleBeta2", "0,15,30,45").Split(','), double.Parse); AnglePsi_Method3 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AnglePsi3", "0,15,30,45").Split(','), double.Parse); AngleX_Method3 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleX3", "0,15,30,45").Split(','), double.Parse); AngleY_Method3 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleY3", "0,15,30,45").Split(','), double.Parse); AngleZ_Method3 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleZ3", "0,15,30,45").Split(','), double.Parse); AngleAlpha_Method3 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleAlpha3", "0,15,30,45").Split(','), double.Parse); AngleBeta_Method3 = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AngleBeta3", "0,15,30,45").Split(','), double.Parse); ZeroPointMotorTS = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "ZeroPointMotorTS", "0,0").Split(','), double.Parse); ZeroPointMotorTD = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "ZeroPointMotorTD", "0,0").Split(','), double.Parse); ZeroPointAlpha = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "ZeroPointAlpha", "0,0").Split(','), double.Parse); ZeroPointBeta = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "ZeroPointBeta", "0,0").Split(','), double.Parse); ZeroPointX = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "ZeroPointX", "0,0").Split(','), double.Parse); ZeroPointY = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "ZeroPointY", "0,0").Split(','), double.Parse); ZeroPointZ = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "ZeroPointZ", "0,0").Split(','), double.Parse); AutoFocus = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionSDDSetting, "AutoFocus", "0,0").Split(','), double.Parse); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 读取INI文件中指定KEY的字符串型值 /// </summary> /// <param name="iniFile">Ini文件</param> /// <param name="section">节点名称</param> /// <param name="key">键名称</param> /// <param name="defaultValue">如果没此KEY所使用的默认值</param> /// <returns>读取到的值</returns> public static string INIGetStringValue(string iniFile, string section, string key, string defaultValue) { string value = defaultValue; const int SIZE = 1024 * 10; if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("必须指定键名称(key)", "key"); } StringBuilder sb = new StringBuilder(SIZE); uint bytesReturned = IniHelper.GetPrivateProfileString(section, key, defaultValue, sb, SIZE, iniFile); if (bytesReturned != 0) { value = sb.ToString(); } sb = null; return(value); }
public void ReadTextureSettings() { try { if (File.Exists(IniFileName)) { SampleNameTxt = IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "SampleNameTxt", "sample_name1,sample_name2").Split(','); SampleSnTxt = IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "SampleSnTxt", "01234,01235,56789").Split(','); FaceExpTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "FaceExpTxt", "110,200,210").Split(','), double.Parse); PeakDegreeTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "PeakDegreeTxt", "28.4,28.6,56.1").Split(','), double.Parse); TubeVoltageTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "TubeVoltageTxt", "25,26,30").Split(','), double.Parse); TubeCurrentTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "TubeCurrentTxt", "25,26,30").Split(','), double.Parse); BMIndexTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "BMIndexTxt", "0,0,1").Split(','), int.Parse); ScanMethodTxt = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "ScanMethodTxt", "0")); PsiStepTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "PsiStepTxt", "5,5,1").Split(','), double.Parse); PsiStartAngleTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "PsiStartAngleTxt", "0,0,0").Split(','), double.Parse); PsiStopAngleTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "PsiStopAngleTxt", "70,70,70").Split(','), double.Parse); PhiSpeedTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "PhiSpeedTxt", "5,5,10").Split(','), double.Parse); MeasureTimeTxt = Array.ConvertAll(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "MeasureTimeTxt", "1,0.5,1").Split(','), double.Parse); MeasureMethodTxt = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionTextureSetting, "MeasureMethodTxt", "0")); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 读取INI文件中指定INI文件中的所有节点名称(Section) /// </summary> /// <param name="iniFile">Ini文件</param> /// <returns>所有节点,没有内容返回string[0]</returns> public string[] INIGetAllSectionNames(string iniFile) { uint MAX_BUFFER = 32767; //默认为32767 string[] sections = new string[0]; //返回值 try { //申请内存 IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char)); uint bytesReturned = IniHelper.GetPrivateProfileSectionNames(pReturnedString, MAX_BUFFER, iniFile); if (bytesReturned != 0) { //读取指定内存的内容 string local = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned).ToString(); //每个节点之间用\0分隔,末尾有一个\0 sections = local.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } //释放内存 Marshal.FreeCoTaskMem(pReturnedString); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(sections); }
/// <summary> /// 在INI文件中,删除指定节点中的所有内容。 /// </summary> /// <param name="iniFile">INI文件</param> /// <param name="section">节点</param> /// <returns>操作是否成功</returns> public static bool INIEmptySection(string iniFile, string section) { if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } return(IniHelper.WritePrivateProfileSection(section, string.Empty, iniFile)); }
public void SaveMeasureSettings() { try { IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "SampleName", string.Join(",", SampleName)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "SampleSn", string.Join(",", SampleSn)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "MeasureMethod", MeasureMethod.ToString()); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "StartDegree", string.Join(",", StartDegree)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "StopDegree", string.Join(",", StopDegree)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "MeasureStep", string.Join(",", MeasureStep)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "MeasureTime", string.Join(",", MeasureTime)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "TubeVoltage", string.Join(",", TubeVoltage)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "TubeCurrent", string.Join(",", TubeCurrent)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "FiveAxis", string.Join(",", FiveAxisInUse)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AnglePsi0", string.Join(",", AnglePsi_Method0)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleX0", string.Join(",", AngleX_Method0)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleY0", string.Join(",", AngleY_Method0)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleZ0", string.Join(",", AngleZ_Method0)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleAlpha0", string.Join(",", AngleAlpha_Method0)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleBeta0", string.Join(",", AngleBeta_Method0)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AnglePsi1", string.Join(",", AnglePsi_Method1)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleX1", string.Join(",", AngleX_Method1)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleY1", string.Join(",", AngleY_Method1)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleZ1", string.Join(",", AngleZ_Method1)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleAlpha1", string.Join(",", AngleAlpha_Method1)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleBeta1", string.Join(",", AngleBeta_Method1)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AnglePsi2", string.Join(",", AnglePsi_Method2)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleX2", string.Join(",", AngleX_Method2)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleY2", string.Join(",", AngleY_Method2)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleZ2", string.Join(",", AngleZ_Method2)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleAlpha2", string.Join(",", AngleAlpha_Method2)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleBeta2", string.Join(",", AngleBeta_Method2)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AnglePsi3", string.Join(",", AnglePsi_Method3)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleX3", string.Join(",", AngleX_Method3)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleY3", string.Join(",", AngleY_Method3)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleZ3", string.Join(",", AngleZ_Method3)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleAlpha3", string.Join(",", AngleAlpha_Method3)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AngleBeta3", string.Join(",", AngleBeta_Method3)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "ZeroPointMotorTS", string.Join(",", ZeroPointMotorTS)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "ZeroPointMotorTD", string.Join(",", ZeroPointMotorTD)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "ZeroPointAlpha", string.Join(",", ZeroPointAlpha)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "ZeroPointBeta", string.Join(",", ZeroPointBeta)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "ZeroPointX", string.Join(",", ZeroPointX)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "ZeroPointY", string.Join(",", ZeroPointY)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "ZeroPointZ", string.Join(",", ZeroPointZ)); IniHelper.INIWriteValue(IniFileName, SectionSDDSetting, "AutoFocus", string.Join(",", AutoFocus)); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 保存value /// </summary> /// <param name="_section">节点名称</param> /// <param name="_key">key</param> /// <param name="_value">value</param> /// <returns>保存结果</returns> public bool SaveValueWithKey(string _section, string _key, string _value) { if (IniFileName != null && IniFileName != "") { return(IniHelper.INIWriteValue(IniFileName, _section, _key, _value)); } else { return(false); } }
/// <summary> /// 读取value /// </summary> /// <param name="_section">节点名称</param> /// <param name="_key">key</param> /// <returns>返回值</returns> public string GetVlueWithKey(string _section, string _key) { if (IniFileName != null && IniFileName != "") { return(IniHelper.INIGetStringValue(IniFileName, _section, _key, "")); } else { return("Error"); } }
public void SaveWarmUpTime() { try { WarmUpLastTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "WarmUpLastTime", WarmUpLastTime); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void SaveLogin() { try { IniHelper.INIWriteValue(IniFileName, SectionLogin, "User", UserName); IniHelper.INIWriteValue(IniFileName, SectionLogin, "Pwd", UserPwd); IniHelper.INIWriteValue(IniFileName, SectionLogin, "Language", Language.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void SaveCommunication() { try { IniHelper.INIWriteValue(IniFileName, SectionComm, "UartPort", UartPortName); IniHelper.INIWriteValue(IniFileName, SectionComm, "UartBaudrate", UartBaudrate); IniHelper.INIWriteValue(IniFileName, SectionComm, "UartSendRetryMax", UartSendRetryMax.ToString()); IniHelper.INIWriteValue(IniFileName, SectionComm, "IPAddress", IPAddress); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 在INI文件中,删除指定节点中的指定的键。 /// </summary> /// <param name="iniFile">INI文件</param> /// <param name="section">节点</param> /// <param name="key">键</param> /// <returns>操作是否成功</returns> public static bool INIDeleteKey(string iniFile, string section, string key) { if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("必须指定键名称", "key"); } return(IniHelper.WritePrivateProfileString(section, key, null, iniFile)); }
/// <summary> /// 在INI文件中,将指定的键值对写到指定的节点,如果已经存在则替换 /// </summary> /// <param name="iniFile">INI文件</param> /// <param name="section">节点,如果不存在此节点,则创建此节点</param> /// <param name="items">键值对,多个用\0分隔,形如key1=value1\0key2=value2</param> /// <returns></returns> public bool INIWriteItems(string iniFile, string section, string items) { if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } if (string.IsNullOrEmpty(items)) { throw new ArgumentException("必须指定键值对", "items"); } return(IniHelper.WritePrivateProfileSection(section, items, iniFile)); }
public void SavePearson() { try { IniHelper.INIWriteValue(IniFileName, SectionPearson, "FunctionIndex", FunctionIndex.ToString()); IniHelper.INIWriteValue(IniFileName, SectionPearson, "CustomExpEnabled", CustomExpEnabled.ToString()); IniHelper.INIWriteValue(IniFileName, SectionPearson, "n", n.ToString()); IniHelper.INIWriteValue(IniFileName, SectionPearson, "s", s.ToString()); IniHelper.INIWriteValue(IniFileName, SectionPearson, "BackgroudType", BackgroudType.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void ReadLogin() { try { if (File.Exists(IniFileName)) { UserName = IniHelper.INIGetStringValue(IniFileName, SectionLogin, "User", "administrator"); UserPwd = IniHelper.INIGetStringValue(IniFileName, SectionLogin, "Pwd", "123456"); Language = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionLogin, "Language", "0")); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void ReadCommunication() { try { if (File.Exists(IniFileName)) { UartPortName = IniHelper.INIGetStringValue(IniFileName, SectionComm, "UartPort", "COM1"); UartBaudrate = IniHelper.INIGetStringValue(IniFileName, SectionComm, "UartBaudrate", "2400"); UartSendRetryMax = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionComm, "UartSendRetryMax", "3")); IPAddress = IniHelper.INIGetStringValue(IniFileName, SectionComm, "IPAddress", "192.168.1.2"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void ReadPearson() { try { if (File.Exists(IniFileName)) { FunctionIndex = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionPearson, "FunctionIndex", "0")); CustomExpEnabled = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionPearson, "CustomExpEnabled", "0")); n = Convert.ToDouble(IniHelper.INIGetStringValue(IniFileName, SectionPearson, "n", "0")); s = Convert.ToDouble(IniHelper.INIGetStringValue(IniFileName, SectionPearson, "s", "0")); BackgroudType = Convert.ToInt32(IniHelper.INIGetStringValue(IniFileName, SectionPearson, "BackgroudType", "0")); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 在INI文件中,指定节点写入指定的键及值。如果已经存在,则替换。如果没有则创建。 /// </summary> /// <param name="iniFile">INI文件</param> /// <param name="section">节点</param> /// <param name="key">键</param> /// <param name="value">值</param> /// <returns>操作是否成功</returns> public static bool INIWriteValue(string iniFile, string section, string key, string value) { if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("必须指定键名称", "key"); } if (value == null) { throw new ArgumentException("值不能为null", "value"); } return(IniHelper.WritePrivateProfileString(section, key, value, iniFile)); }
/// <summary> /// 获取INI文件中指定节点(Section)中的所有条目的Key列表 /// </summary> /// <param name="iniFile">Ini文件</param> /// <param name="section">节点名称</param> /// <returns>如果没有内容,反回string[0]</returns> public static string[] INIGetAllItemKeys(string iniFile, string section) { string[] value = new string[0]; const int SIZE = 1024 * 10; if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } char[] chars = new char[SIZE]; uint bytesReturned = IniHelper.GetPrivateProfileString(section, null, null, chars, SIZE, iniFile); if (bytesReturned != 0) { value = new string(chars).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } chars = null; return(value); }
/// <summary> /// 获取INI文件中指定节点(Section)中的所有条目(key=value形式) /// </summary> /// <param name="iniFile">Ini文件</param> /// <param name="section">节点名称</param> /// <returns>指定节点中的所有项目,没有内容返回string[0]</returns> public static string[] INIGetAllItems(string iniFile, string section) { //返回值形式为 key=value,例如 Color=Red uint MAX_BUFFER = 32767; //默认为32767 string[] items = new string[0]; //返回值 //分配内存 IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char)); uint bytesReturned = IniHelper.GetPrivateProfileSection(section, pReturnedString, MAX_BUFFER, iniFile); if (!(bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0)) { string returnedString = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned); items = returnedString.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } Marshal.FreeCoTaskMem(pReturnedString); //释放内存 return(items); }
public void SaveDeviceInit() { try { IniHelper.INIWriteValue(IniFileName, SectionDevInit, "TargetType", TargetType.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "WarmUpWaitSec", WarmUpWaitSec.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "WarmUpVoltage", WarmUpVoltage.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "WarmUpCurrent", WarmUpCurrent.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "WarmUpLastTime", WarmUpLastTime); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "WarmUpIntervalMinute", WarmUpIntervalMinute.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "DetectorType", DetectorType.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "SDDMotorMode", SDDMotorMode.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "DefaultVotage", DefaultVotage.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "DefaultCurrent", DefaultCurrent.ToString()); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "SavePath", SavePath); IniHelper.INIWriteValue(IniFileName, SectionDevInit, "OpenDataFileName", OpenDataFileName); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }