modbus 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 44

modbus-dart #

MODBUS client library

pub package

Using #

import 'package:modbus/modbus.dart' as modbus;

  import 'package:modbus/modbus.dart' as modbus;

  main(List<String> arguments) async {
    var client = modbus.createTcpClient('', port: 1001, mode: modbus.ModbusMode.rtu);

    try {
      await client.connect();

      var slaveIdResponse = await client.reportSlaveId();

      print("Slave ID: " + slaveIdResponse);
    } finally {

Limitations #

SerialConnector is not implemented yet

0.0.1 #

Initial release


import 'package:modbus/modbus.dart' as modbus;
import 'package:logging/logging.dart';

main(List<String> arguments) async {

  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((LogRecord rec) {
    print('${}: ${rec.time} [${rec.loggerName}]: ${rec.message}');

  var client = modbus.createTcpClient('', port: 1001, mode: modbus.ModbusMode.rtu);

  try {
    await client.connect();

    var slaveIdResponse = await client.reportSlaveId();

    StringBuffer sb = StringBuffer();
    slaveIdResponse.forEach((f) {
      sb.write(f.toRadixString(16).padLeft(2, '0'));
      sb.write(" ");
    print("Slave ID: " + sb.toString());

    var exceptions = await client.readExceptionStatus();

    print("Exceptions: " + exceptions.toRadixString(2));

      var registers = await client.readInputRegisters(0x0002, 6);
      for (int i = 0; i < registers.length; i++) {
        print("REG_I[${i}]: " + registers.elementAt(i).toString());
  } finally {

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  modbus: ^0.0.3

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:modbus/modbus.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21


Detected platforms: Flutter, other

Primary library: package:modbus/modbus.dart with components: io.

Health suggestions

Fix lib/src/serial_connector.dart. (-1 points)

Analysis of lib/src/serial_connector.dart reported 2 hints:

line 7 col 10: The value of the field '_device' isn't used.

line 28 col 13: The declaration '_crc' isn't referenced.

Fix lib/modbus.dart. (-0.50 points)

Analysis of lib/modbus.dart reported 1 hint:

line 88 col 48: Use = to separate a named parameter from its default value.

Format lib/src/acii_converter.dart.

Run dartfmt to format lib/src/acii_converter.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/client.dart (Run dartfmt to format lib/src/client.dart.)
  • lib/src/exceptions.dart (Run dartfmt to format lib/src/exceptions.dart.)
  • lib/src/tcp_connector.dart (Run dartfmt to format lib/src/tcp_connector.dart.)

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
logging ^0.11.3+2 0.11.3+2
Dev dependencies
test ^1.3.0