Whether it is. net Framework set or. net (simplified framework set) can perfectly support XML files, and Microsoft strongly recommends that you replace the INI file with XML files. However, most projects in the industrial control field use the system information configured in the INI file.
In the past, the tunnel management system used the INI file configuration information. To achieve compatibility, we had to use the INI file configuration information in the lower computer. Because the wince platform does not provide the API function getprivateprofilestring for INI file reading, you need to write it on your own. Some time ago, an INI file of the EVC version was provided for reading, later, C # programming was adopted on the wince platform of da66x. Therefore, a C # version of INI reading function is not required.
This is an ini read function that I excerpted based on the original project code.
// Read the INI file;
Private string getprivateprofilestring (string applicationname, string keyname, string default, string filename)
{
String [] iniitems = new string [0];
String inilines;
String iniline;
Int I, J;
Try
{
// Read the INI file;
System. Io. streamreader INIFILE = new system. Io. streamreader (filename, system. Text. encoding. Default );
Inilines = INIFILE. readtoend ();
INIFILE. Close ();
}
Catch
{
Return default;
}
// Separate the lines with carriage returns to get each line
Iniitems = inilines. Split ('');
// Traverse each row
For (I = 0; I <iniitems. getlength (0); I ++)
{
// Find the matching Value
If (iniitems [I]. Trim (). toupper () = '[' + applicationname. Trim (). toupper () + ']')
{
// Search from the next row
For (j = I + 1; j <iniitems. getlength (0); j ++)
{
Iniline = iniitems [J]. Trim ();
If (iniline. length> 0)
{
// If another segment is found, the longer the segment, the default value is returned.
If (iniline [0] = '[' & iniline [iniline. Length-1] = ']') return default;
}
// Remove all spaces
Iniline = iniitems [J]. trimstart (). Replace ("","");
If (iniline. substring (0, math. Min (keyname. Length + 1, iniline. Length). toupper () = keyname. toupper () + "= ")
{
// If key matching is found
Return iniitems [J]. substring (iniitems [J]. indexof ('=') + 1 );
}
}
Return default; // if no matching key is found, the default value is returned.
}
}
Return default; // return the default value.
}