private static ReadBytes ( |
||
ip | ||
Résultat | byte[] |
private static byte[] ReadBytes(StreamReader ip)
{
string line = ip.ReadLine();
if (line == null)
return null;
byte[] buffer = new byte[(line.Length + 2) / 3];
int index = 0;
for (int i = 0; (i + 1) < line.Length; i += 3)
{
char ch = line[i + 0];
char cl = line[i + 1];
if (ch >= '0' && ch <= '9')
ch -= '0';
else if (ch >= 'a' && ch <= 'f')
ch -= (char)('a' - 10);
else if (ch >= 'A' && ch <= 'F')
ch -= (char)('A' - 10);
else
return null;
if (cl >= '0' && cl <= '9')
cl -= '0';
else if (cl >= 'a' && cl <= 'f')
cl -= (char)('a' - 10);
else if (cl >= 'A' && cl <= 'F')
cl -= (char)('A' - 10);
else
return null;
buffer[index++] = (byte)((ch << 4) | cl);
}
return buffer;
}
public static CalibrationInfo[] GetList() { ArrayList arrayList = new ArrayList(); string path = Path.Combine(Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]), "calibration.cfg"); if (File.Exists(path)) { using (StreamReader ip = new StreamReader(path)) { string str; while ((str = ip.ReadLine()) != null) { byte[] mask; byte[] vals; byte[] detx; byte[] dety; byte[] detz; byte[] detf; if (str.Trim().ToLower() == "Begin" && (mask = CalibrationInfo.ReadBytes(ip)) != null && ((vals = CalibrationInfo.ReadBytes(ip)) != null && (detx = CalibrationInfo.ReadBytes(ip)) != null) && ((dety = CalibrationInfo.ReadBytes(ip)) != null && (detz = CalibrationInfo.ReadBytes(ip)) != null && (detf = CalibrationInfo.ReadBytes(ip)) != null)) { arrayList.Add((object)new CalibrationInfo(mask, vals, detx, dety, detz, detf)); } } } } arrayList.AddRange((ICollection)CalibrationInfo.DefaultList); return((CalibrationInfo[])arrayList.ToArray(typeof(CalibrationInfo))); }