send static method
Future<void>
send({
- required String mti,
- required String processingCode,
- required FutureOr<
void> onSuccess(), - required FutureOr<
void> onError(), - required FutureOr<
void> onException(- String e
- Map<
int, Object?> fields = const <int, Object?>{}, - Map<
int, String> tags = const <int, String>{}, - bool sendTerminalId = true,
- Duration? timeout,
- 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());
}
}