111,129
社区成员
发帖
与我相关
我的任务
分享 public class IniFile
{
public string path;//INI文件名
/*声明读写INI文件的API函数*/
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
/*类的构造函数,传递INI文件名*/
public IniFile(string INIPath)
{
path = INIPath;
}
/*写INI文件*/
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
/*读取指定INI文件*/
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(500);
int i = GetPrivateProfileString(Section, Key, "", temp, 500, this.path);
return temp.ToString();
}
public bool ExistINIFile()
{
return File.Exists(path);
}
} if ((readBuffer[0] == 254) && (readBuffer[1] > 4 ) && (checksum1(readBuffer[1]) != 0))//保存每个以254开头的数组
{
IniFile ini = new IniFile("C:\\moto.ini");
for (int i = 0; i < readBuffer[1]; i++)
{
ini.IniWriteValue("", "readBuffer" + i.ToString(), readBuffer[i].ToString());
}
} /*实时数据输出*/
if ((readBuffer[0] == 253) && (readBuffer[1] == 34) && (checksum1(readBuffer[1]) != 0))
{
pacurrent = (readBuffer[2] + readBuffer[3] * 256.00) / 1000.00;
textBox10.Text = pacurrent.ToString("f2");
pbcurrent = (readBuffer[4] + readBuffer[5] * 256.00) / 1000.00;
textBox11.Text = pbcurrent.ToString("f2");
pccurrent = (readBuffer[6] + readBuffer[7] * 256.00) / 1000.00;
textBox12.Text = pccurrent.ToString("f2");
mcurrent = (readBuffer[8] + readBuffer[9] * 256.00) / 1000.00;
textBox6.Text = mcurrent.ToString("f2");
bvoltage = (readBuffer[10] + readBuffer[11] * 256.00) / 1000.00;
textBox5.Text = bvoltage.ToString("f2");
cspeed = (readBuffer[14] + readBuffer[15] * 256);
textBox2.Text = cspeed.ToString();
pusage = (readBuffer[18]);
textBox7.Text = pusage.ToString();
temp = (readBuffer[21] + readBuffer[22] * 256);
textBox13.Text = temp.ToString();
cpower = (readBuffer[25] + readBuffer[26] * 256.00) / 1000.00;
textBox3.Text = cpower.ToString("f2");
distance = (readBuffer[29] + readBuffer[30] * 256 + readBuffer[31] * 65536);
textBox8.Text = distance.ToString();
} else if ((readBuffer[0] == 254) && (readBuffer[1] > 4 ) && (checksum1(readBuffer[1]) != 0))//保存每个以254开头的数组
{
//IniFile ini = new IniFile("C:\\param.ini");
for (int i = 0; i < readBuffer[1]; i++)
{
//ini.IniWriteValue("", "readBuffer" + i.ToString(), readBuffer[i].ToString());
File.AppendAllText("c:\\param.txt", readBuffer[i].ToString() + Environment.NewLine);
}
} else if ((readBuffer[0] == 254) && (readBuffer[1] > 4 ) && (checksum1(readBuffer[1]) != 0))//保存每个以254开头的数组
{
//IniFile ini = new IniFile("C:\\moto.ini");
for (int i = 0; i < readBuffer[1]; i++)
{
//ini.IniWriteValue("", "readBuffer" + i.ToString(), readBuffer[i].ToString());
File.AppendAllText("c:\\Param.txt", readBuffer[i].ToString() + Environment.NewLine);
}
}

File.AppendAllText("c:\\param.txt", readBuffer[i].ToString() + readBuffer[i].ToString().StartsWith("254")?Environment.NewLine:",");Environment.NewLine","