コード例 #1
0
 async Task <bool> CreateDeviceList_OneTime(Type[] deviceClasses)
 {
     foreach (Type ty in deviceClasses)
     {
         DeviceInformationCollection deviceList = null;
         if (ty == typeof(BarcodeScanner))
         {
             deviceList = await DeviceInformation.FindAllAsync(BarcodeScanner.GetDeviceSelector());
         }
         else if (ty == typeof(PosPrinter))
         {
             deviceList = await DeviceInformation.FindAllAsync(PosPrinter.GetDeviceSelector());
         }
         else if (ty == typeof(CashDrawer))
         {
             deviceList = await DeviceInformation.FindAllAsync(CashDrawer.GetDeviceSelector());
         }
         else if (ty == typeof(MagneticStripeReader))
         {
             deviceList = await DeviceInformation.FindAllAsync(MagneticStripeReader.GetDeviceSelector());
         }
         else if (ty == typeof(LineDisplay))
         {
             deviceList = await DeviceInformation.FindAllAsync(LineDisplay.GetDeviceSelector());
         }
         AddToSelectionList(ty, deviceList);
     }
     return(true);
 }
コード例 #2
0
ファイル: SampleConfiguration.cs プロジェクト: ice0/test
 // 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;
     }));
 }
コード例 #3
0
        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();
        }
コード例 #4
0
 private static string GetPosSelector(Type ty)
 {
     if (ty == typeof(BarcodeScanner))
     {
         return(BarcodeScanner.GetDeviceSelector());
     }
     if (ty == typeof(PosPrinter))
     {
         return(PosPrinter.GetDeviceSelector());
     }
     if (ty == typeof(CashDrawer))
     {
         return(CashDrawer.GetDeviceSelector());
     }
     if (ty == typeof(MagneticStripeReader))
     {
         return(MagneticStripeReader.GetDeviceSelector());
     }
     if (ty == typeof(LineDisplay))
     {
         return(LineDisplay.GetDeviceSelector());
     }
     return(null);
 }
コード例 #5
0
        /// <summary>
        /// GetDeviceSelector method returns the string needed to identify a PosPrinter. This is passed to FindAllAsync method to get the list of devices currently available and we connect the first device.
        /// </summary>
        private async Task <bool> FindReceiptPrinter()
        {
            if (printer == null)
            {
                rootPage.NotifyUser("Finding printer", NotifyType.StatusMessage);
                DeviceInformationCollection deviceCollection = await DeviceInformation.FindAllAsync(PosPrinter.GetDeviceSelector());

                if (deviceCollection != null && deviceCollection.Count > 0)
                {
                    DeviceInformation deviceInfo = deviceCollection[0];
                    printer = await PosPrinter.FromIdAsync(deviceInfo.Id);

                    if (printer != null)
                    {
                        if (printer.Capabilities.Receipt.IsPrinterPresent)
                        {
                            rootPage.NotifyUser("Got Printer with Device Id : " + printer.DeviceId, NotifyType.StatusMessage);
                            return(true);
                        }
                    }
                    else
                    {
                        rootPage.NotifyUser("No Printer found", NotifyType.ErrorMessage);
                        return(false);
                    }
                }
                else
                {
                    rootPage.NotifyUser("No devices returned by FindAllAsync.", NotifyType.ErrorMessage);
                    return(false);
                }
            }
            return(true);
        }