This package allows Dart programs to access the Fermilab ACSys API.
Dart programs can use the ACSysService class to make requests to the
Fermilab control system as well as stream real-time device data. Flutter
applications should use the flutter-gql-acsys package, which depends
on this package.
Add this to your pubspec.yaml file:
dependencies:
dart_gql_acsys:
git:
url: https://github.com/fermi-ad/dart-gql-acsys.git
tag_pattern: v{{version}}
version: ^1.5.0This is a simple example to read the outdoor temperature once every 10 seconds.
$ dart create -t cli my_demo
$ cd my_demoUpdate pubspec.yaml with the dependency mentioned about. Replace lib/main.dart with this:
import 'package:dart_gql_acsys/dart_gql_acsys.dart';
void main() async {
// Create a stream of readings. Specify M:OUTTMP being read once
// every 10 seconds.
final strm = ACSysService().monitorDevices(["M:OUTTMP@p,10000"]);
// It's an asynchronous stream, so we use an 'await for-loop'.
await for (final reply in strm) {
// Pattern match the result. We expect a `Reading` with a `refId`
// of 0 and the `value` field to have a scalar value.
if (reply case Reading(refId: 0, value: DevScalar(value: final val))) {
// Print the value to 1 significant digit to the right of
// the decimal point.
print("Reading: ${val.toStringAsFixed(1)} F");
} else {
print("unexpected reply: $reply");
}
}
}$ dart runEnjoy the outdoor temperature!
If the GraphQL schema changes, you need to rebuild the supporting files. After running the build command, it's good to run the formatter over the code so it's consistent with the rest of the project.
$ dart run build_runner build --delete-conflicting-outputs
$ dart format lib