public void ReleaseAllPrinters() { ReleaseClaimedPrinter(); if (Printer != null) { Printer.Dispose(); Printer = null; StateChanged?.Invoke(); } }
/// <summary> /// Releases claim of printer instance 1 /// </summary> void Release1_Click(object sender, RoutedEventArgs e) { if (claimedPrinter1 != null) { claimedPrinter1.ReleaseDeviceRequested -= ClaimedPrinter1_ReleaseDeviceRequested; claimedPrinter1.Dispose(); claimedPrinter1 = null; if (printerInstance1 != null) { printerInstance1.Dispose(); printerInstance1 = null; } rootPage.NotifyUser("Released claimed Instance 1", NotifyType.StatusMessage); } else { rootPage.NotifyUser("Instance 1 not claimed to release", NotifyType.StatusMessage); } }
// By default, use all connections types. public static async Task <PosPrinter> GetFirstReceiptPrinterAsync(PosConnectionTypes connectionTypes = PosConnectionTypes.All) { return(await DeviceHelpers.GetFirstDeviceAsync(PosPrinter.GetDeviceSelector(connectionTypes), async (id) => { PosPrinter printer = await PosPrinter.FromIdAsync(id); if (printer != null && printer.Capabilities.Receipt.IsPrinterPresent) { return printer; } // Dispose the unwanted printer. printer?.Dispose(); return null; })); }
private void ResetTheScenarioState() { //Remove releasedevicerequested handler and dispose claimed printer object. if (claimedPrinter != null) { claimedPrinter.ReleaseDeviceRequested -= ClaimedPrinter_ReleaseDeviceRequested; claimedPrinter.Dispose(); claimedPrinter = null; } if (printer != null) { printer.Dispose(); printer = null; } }
async void FindPrinter_Click() { isBusy = true; UpdateButtons(); rootPage.NotifyUser("", NotifyType.StatusMessage); rootPage.ReleaseAllPrinters(); // Select a PosPrinter device using the Device Picker. DevicePicker devicePicker = new DevicePicker(); devicePicker.Filter.SupportedDeviceSelectors.Add(PosPrinter.GetDeviceSelector()); // Anchor the picker on the Find button. GeneralTransform ge = FindButton.TransformToVisual(Window.Current.Content as UIElement); Rect rect = ge.TransformBounds(new Rect(0, 0, FindButton.ActualWidth, FindButton.ActualHeight)); DeviceInformation deviceInfo = await devicePicker.PickSingleDeviceAsync(rect); rootPage.deviceInfo = deviceInfo; PosPrinter printer = null; if (deviceInfo != null) { printer = await PosPrinter.FromIdAsync(deviceInfo.Id); } if (printer != null && printer.Capabilities.Receipt.IsPrinterPresent) { rootPage.Printer = printer; rootPage.NotifyUser("Found receipt printer.", NotifyType.StatusMessage); } else { // Get rid of the printer we can't use. printer?.Dispose(); rootPage.NotifyUser("Please select a device whose printer is present.", NotifyType.ErrorMessage); } isBusy = false; UpdateButtons(); }