send static method

Future<void> send({
  1. required String mti,
  2. required String processingCode,
  3. required FutureOr<void> onSuccess(
    1. UIsoResult r
    ),
  4. required FutureOr<void> onError(
    1. UIsoResult r
    ),
  5. required FutureOr<void> onException(
    1. String e
    ),
  6. Map<int, Object?> fields = const <int, Object?>{},
  7. Map<int, String> tags = const <int, String>{},
  8. bool sendTerminalId = true,
  9. Duration? timeout,
  10. IsoLinkEvents? events,
})

Implementation

static Future<void> send({
  required String mti,
  required String processingCode,
  required FutureOr<void> Function(UIsoResult r) onSuccess,
  required FutureOr<void> Function(UIsoResult r) onError,
  required FutureOr<void> Function(String e) onException,
  Map<int, Object?> fields = const <int, Object?>{},
  Map<int, String> tags = const <int, String>{},
  bool sendTerminalId = true,
  Duration? timeout,
  IsoLinkEvents? events,
}) async {
  try {
    final DateTime now = DateTime.now();
    final int traceNumber = await UIso.nextTraceNumber();
    final IsoMsg request = _buildRequest(mti, processingCode, fields, tags, sendTerminalId, traceNumber, now);

    final IsoMsg? answer = await UIso.link.sendMessage(request, timeout: timeout, events: events);
    if (answer == null) throw UIsoException(UIsoErrorCode.noResponse, "no answer from the host");

    final UIsoResult result = UIsoResult(
      traceNumber: traceNumber,
      sentAt: now,
      raw: answer,
      tags: answer.hasField(63) ? OssAcqTlvPackager.unpackToTlvMessage(answer.getBytes(63)!) : null,
    );
    if (result.isSuccess) {
      await onSuccess(result);
    } else {
      await onError(result);
    }
  } on UIsoException catch (error) {
    await onException(error.message);
  } catch (error) {
    await onException(error.toString());
  }
}