modbus 0.0.3
modbus-dart #
MODBUS client library
Using #
import 'package:modbus/modbus.dart' as modbus;
import 'package:modbus/modbus.dart' as modbus;
main(List<String> arguments) async {
var client = modbus.createTcpClient('10.170.1.20', port: 1001, mode: modbus.ModbusMode.rtu);
try {
await client.connect();
var slaveIdResponse = await client.reportSlaveId();
print("Slave ID: " + slaveIdResponse);
} finally {
client.close();
}
}
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.level.name}: ${rec.time} [${rec.loggerName}]: ${rec.message}');
});
var client = modbus.createTcpClient('10.170.1.20', 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 {
client.close();
}
}
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
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';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
32
|
Health:
Code health derived from static analysis.
[more]
|
97
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
70
|
Overall:
Weighted score of the above.
[more]
|
59
|
We analyzed this package on Dec 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.6.1
- pana: 0.12.21
Platforms
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.
Fix lib/src/acii_converter.dart
. (-0.50 points)
Analysis of lib/src/acii_converter.dart
reported 1 hint:
line 8 col 29: Unnecessary new keyword.
Fix additional 3 files with analysis or formatting issues. (-1 points)
Additional issues in the following files:
lib/src/client.dart
(1 hint)lib/src/tcp_connector.dart
(1 hint)lib/src/exceptions.dart
(Rundartfmt
to formatlib/src/exceptions.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.