public IntelHEXfile(string filename) { if (filename.EndsWith(".hex") != true) { FileErrorMessages.Add("Файл имеет расширение отличное от hex"); } try { StreamReader sr = new StreamReader(filename); bool eof = false; int lineNumber = 0; while (!eof) { lineNumber++; HEXline line = new HEXline(sr.ReadLine(), lineNumber); //if (ErrorMessage == "") ErrorMessage = line.ErrorMessages; FileErrorMessages.AddRange(line.LineErrorMessages); if (line.CriticalErrors == true) { CriticalError = true; } switch (line.recordtype) { case HEXline.RecordType.DataRecord: //data.AddRange(line.data); int ij = 0; foreach (byte bt in line.data) { AddressByteSorted.Add((long)(line.address + ij), line.data[ij]); ij++; } break; case HEXline.RecordType.EndOfFile: eof = true; break; } if (sr.EndOfStream) { eof = true; } } foreach (KeyValuePair <long, byte> dabs in AddressByteSorted) { Addresses.Add(dabs.Key); Bytes.Add(dabs.Value); } for (int i = 0; i < AddressByteSorted.Count; i++) { if (Addresses[i] < minAddress) { minAddress = Addresses[i]; } } for (int i = 0; i < AddressByteSorted.Count; i++) { if (Addresses[i] > maxAddress) { maxAddress = Addresses[i]; } } sr.Close(); sr.Dispose(); } catch (Exception ex) { ErrorMessage = ex.Message; CriticalError = true; } }
public MotorolaSRECfile_long(string filename) { if (filename.ToLower().EndsWith(".s19") | filename.ToLower().EndsWith(".srec")) { } else { FileErrorMessages.Add(" Файл имеет расширение отличное от .s19(.srec)"); } try { StreamReader sr = new StreamReader(filename); bool eof = false; int lineNumber = 0; while (!eof) { lineNumber++; SRECline line = new SRECline(sr.ReadLine(), lineNumber); //if (ErrorMessage == "") ErrorMessage = line.ErrorMessages; FileErrorMessages.AddRange(line.LineErrorMessages); if (line.CriticalErrors == true) { CriticalError = true; } switch (line.recordtype) { case SRECline.RecordType.DataRecordS19: case SRECline.RecordType.DataRecordSREC: AddressLineSorted.Add((long)(line.address), line.data); AddressLine.Add((long)(line.address), line.data); int ij = 0; foreach (byte bt in line.data) { AddressByteSorted.Add((long)(line.address + ij), line.data[ij]); ij++; } break; case SRECline.RecordType.EndOfFileS19: case SRECline.RecordType.EndOfFileSREC: eof = true; break; } if (sr.EndOfStream) { eof = true; } } if (AddressByteSorted.Count != 0) { foreach (KeyValuePair <long, byte> dabs in AddressByteSorted) { Addresses.Add(dabs.Key); Bytes.Add(dabs.Value); } for (int i = 0; i < AddressByteSorted.Count; i++) { if (Addresses[i] < minAddress) { minAddress = Addresses[i]; } } for (int i = 0; i < AddressByteSorted.Count; i++) { if (Addresses[i] > maxAddress) { maxAddress = Addresses[i]; } } } else { FileErrorMessages.Add(" Файл не имеет адресов."); minAddress = maxAddress = long.MinValue; } sr.Close(); sr.Dispose(); } catch (Exception ex) { ErrorMessage = ex.Message; CriticalError = true; } }
public MotorolaSRECfile(string filename) { // if (filename.ToLower().EndsWith(".s19") != true) FileErrorMessages.Add("Файл имеет расширение отличное от s19"); if (filename.ToLower().EndsWith(".s19") | filename.ToLower().EndsWith(".s28") | filename.ToLower().EndsWith(".s37") | filename.ToLower().EndsWith(".srec") | filename.ToLower().EndsWith(".sx")) { } else { FileErrorMessages.Add(" Файл имеет расширение отличное от srec (s19, s28, s37, sx)"); } try { StreamReader sr = new StreamReader(filename); bool eof = false; int lineNumber = 0; while (!eof) { lineNumber++; SRECline line = new SRECline(sr.ReadLine(), lineNumber); //if (ErrorMessage == "") ErrorMessage = line.ErrorMessages; FileErrorMessages.AddRange(line.LineErrorMessages); if (line.CriticalErrors == true) { CriticalError = true; } LinesOfFile.Add(line.crntLine); switch (line.recordtype) { case SRECline.RecordType.DataRecord16: case SRECline.RecordType.DataRecord24: case SRECline.RecordType.DataRecord32: //data.AddRange(line.data); AddressLineSorted.Add(line.address, line.data); int ij = 0; foreach (byte bt in line.data) { AddressByteSorted.Add((long)(line.address + ij), line.data[ij]); Addresses.Add((long)(line.address + ij)); Bytes.Add(line.data[ij]); if (minAddress > (long)(line.address + ij)) { minAddress = (long)(line.address + ij); } if (maxAddress < (long)(line.address + ij)) { maxAddress = (long)(line.address + ij); } ij++; } break; case SRECline.RecordType.CountRecord16: case SRECline.RecordType.CountRecord24: //recordCount = line.address; break; case SRECline.RecordType.StartAddressRecord32: case SRECline.RecordType.StartAddressRecord24: case SRECline.RecordType.StartAddressRecord16: eof = true; break; } if (sr.EndOfStream) { eof = true; } } sr.Close(); sr.Dispose(); } catch (Exception ex) { ErrorMessage = ex.Message; CriticalError = true; } }