sendTransaction method
timeout
Milliseconds to wait.
Implementation
@override
void sendTransaction(String data, int timeout) async {
if (_isTimerActive()) {
logger?.log("Job is already running.");
return;
}
final isOTGSupported = await _isUsbOTGSupported() ?? false;
if (!isOTGSupported) {
final error = PosConnectorException(
PosConnectorException.usbOtgNotSupported,
"Your system doesn't support USB OTG. The operation cannot be done.");
logger?.logError(error);
_callback?.onOperationError(error);
return;
}
final usbDevice = await _getSupportedUsbDevice();
if (usbDevice == null) {
final error = PosConnectorException(PosConnectorException.noDeviceFound,
"No USB device was found. You may need to enable USB OTG or re-insert the device.");
logger?.logError(error);
_callback?.onOperationError(error);
return;
}
final serialPort = await usbDevice.create();
final isOpened = await serialPort?.open() ?? false;
if (!isOpened) {
final error = PosConnectorException(
PosConnectorException.openSerialPortError, "Unable to open port.");
logger?.logError(error);
_callback?.onOperationError(error);
return;
}
_serialPort = serialPort;
logger?.log("Serial port opened.");
_sendAndWaitForResponse(serialPort!, data, timeout);
}