connect method
Future
connect(
{ - Duration? timeout = const Duration(seconds: 5),
})
override
Implementation
@override
Future connect({Duration? timeout = const Duration(seconds: 5)}) async {
if (Platform.isWindows) {
try {
docInfo =
calloc<DOC_INFO_1>()
..ref.pDocName = PWSTR(pDocName)
..ref.pOutputFile = PWSTR(nullptr.cast<Utf16>())
..ref.pDatatype = PWSTR(pDataType);
szPrinterName = printer.name!.toNativeUtf16();
final phPrinterPtr = calloc<Pointer>();
final openResult = OpenPrinter(PCWSTR(szPrinterName), phPrinterPtr, nullptr);
if (!openResult.value) {
calloc.free(phPrinterPtr);
return Future.error('Failed to open printer: ${printer.name}');
}
hPrinter = PRINTER_HANDLE(phPrinterPtr.value);
calloc.free(phPrinterPtr);
} catch (e) {
return Future.error(e.toString());
}
} else if (Platform.isAndroid) {
var usbDevice = await usbPrinter.connect(
printer.vendorId!,
printer.productId!,
);
if (usbDevice == null) {
return Future.error('Usb device is empty');
}
}
}