srec 1.1.0

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

A Dart library that can read and write Motorola S-Record files. The Motorola S-Record is a file format that contains binary information as ASCII text.

Motorola S-Record library

Dart codecov

A dart library that reads and writes Motorola S-Record files (common file extensions: .s19, .s28, .s37, .srec). Motorola S-Record is a file format that is used to store binary data as ASCII text. It is often used to program microcontrollers. The file is comprised of record blocks. Each record block is represented as a line in the text file. A record starts with a "S" character and ends at the end of the line. The last byte of a record block is the checksum of all other bytes in this block.

A record has six fields:

  • Start code. Usually "S".
  • Record type
  • Byte count
  • Address
  • Data. May be empty.
  • Checksum

Features

The library can both read and write files in the Motorola S-record format. The checksum will be validated when reading a file. If the format cannot be parsed, then an exception is thrown with the line where the error occurred. Therefore, this library can also be used as linter for s-record files.

The following record types can be parsed:

Record typeIdDescription
HeaderS0A meta data field with a description of the following records.
DataS1, S2, S3A normal data field.
CountS5, S6The count of previous S1, S2 and S3 records.
Start Address (termination)S7, S8, S9A data field that holds the initial instruction pointer and terminates the record block.

Each record can contain a payload of 0-255 bytes.

Getting started

To use the package, simply add it to your pubspec.yaml:

dependencies:
  srec: ^1.1.0

And you are good to go!

Usage

Here is a simple example showing how to read a file:

import 'package:srec/srec.dart';

// example reading a file ...
final file = File(path).readAsStringSync();
var srec = SRecordFile.fromString(file);

Converting binary data to an Intel HEX string can be done with the following code:

import 'package:srec/srec.dart';

Uint8List data = /* get binary data */;
var srec = SRecordFile.fromData(data);
var hexString = srec.toFileContents();

See also the examples in the examples directory. There is also an up to date documentation on pub.dev that explains the API of the library.

Additional information

In case of bug reports or feature requests, please use the issue tracker on github.

Dependencies

The library uses the Memory Segments from the intel_hex package.