/// <summary> /// Creates the default barcode scanner. /// </summary> /// <returns>true if barcode scanner is created. Otherwise returns false</returns> private async Task<bool> CreateDefaultScannerObject() { if (scanner == null) { rootPage.NotifyUser("Creating barcode scanner object.", NotifyType.StatusMessage); if (posDeviceWatcher.FoundDeviceList != null && posDeviceWatcher.FoundDeviceList.Count > 0) { scanner = await BarcodeScanner.FromIdAsync(posDeviceWatcher.FoundDeviceList[0].Id); if (scanner == null) { rootPage.NotifyUser("Failed to create barcode scanner object.", NotifyType.ErrorMessage); return false; } } else { rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage); return false; } } return true; }
/// <summary> /// Creates the default barcode scanner. /// </summary> /// <returns>true if barcode scanner is created. Otherwise returns false</returns> private async Task<bool> CreateDefaultScannerObject() { if (scanner == null) { rootPage.NotifyUser("Creating barcode scanner object.", NotifyType.StatusMessage); DeviceInformationCollection deviceCollection = await DeviceInformation.FindAllAsync(BarcodeScanner.GetDeviceSelector()); if (deviceCollection != null && deviceCollection.Count > 0) { scanner = await BarcodeScanner.FromIdAsync(deviceCollection[0].Id); if (scanner == null) { rootPage.NotifyUser("Failed to create barcode scanner object.", NotifyType.ErrorMessage); return false; } } else { rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage); return false; } } return true; }
void scanner_Completed(object sender, BarcodeScanner.ScannerResult e) { if (e.TaskResult == TaskResult.OK) { string result = String.Format("\"cancelled\":{0},\"text\":\"{1}\"", 0, e.ScanCode); result = "{" + result + "}"; DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result)); } else { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Failed to scan QR code")); } }
private async Task Startprocess(BarcodeScanner scanner) { while (true) { scannedBarcode = await serialCom.GetScannedBarcode(scanner, cts.Token); if (!string.IsNullOrWhiteSpace(scannedBarcode)) { CommunicationsList.Insert(0, "Sent to Server ---->" + scannedBarcode); rxCommand = await client.SendRecTCPCommand(scannedBarcode + "<EOF>", "10.51.169.65"); CommunicationsList.Insert(0, "Recvd from Server <----" + rxCommand); sqlLogger.LogServerClientCommunications(rxCommand, scannedBarcode); } } }
/// <summary> /// This is the click handler for the 'ScenarioEndScanningInstance1' button. /// Initiates the disposal of scanner instance 1. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private void ButtonEndScanningInstance1_Click(object sender, RoutedEventArgs e) { //remove the event handlers claimedBarcodeScannerInstance1.DataReceived -= claimedBarcodeScannerInstance1_DataReceived; claimedBarcodeScannerInstance1.ReleaseDeviceRequested -= claimedBarcodeScannerInstance1_ReleaseDeviceRequested; //dispose the instance claimedBarcodeScannerInstance1.Dispose(); claimedBarcodeScannerInstance1 = null; scannerInstance1 = null; //reset the UI ResetUI(); UpdateOutput("Scanner Instance 1 Destroyed\n"); }
/// <summary> /// This is the click handler for the 'ScenarioEndScanningInstance2' button. /// Initiates the disposal fo scanner instance 2. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private void ButtonEndScanningInstance2_Click(object sender, RoutedEventArgs e) { //remove the event handlers claimedBarcodeScannerInstance2.DataReceived -= claimedBarcodeScannerInstance2_DataReceived; claimedBarcodeScannerInstance2.ReleaseDeviceRequested -= claimedBarcodeScannerInstance2_ReleaseDeviceRequested; //dispose the instance claimedBarcodeScannerInstance2.Dispose(); claimedBarcodeScannerInstance2 = null; scannerInstance2 = null; //reset the UI ResetUI(); rootPage.NotifyUser("Click a start scanning button to begin.", NotifyType.StatusMessage); }
/// <summary> /// Event Handler for Start Scan Button Click. /// Sets up the barcode scanner to be ready to receive the data events from the scan. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs e) { ScenarioStartScanButton.IsEnabled = false; rootPage.NotifyUser("Acquiring barcode scanner object.", NotifyType.StatusMessage); // Acquire the barcode scanner. scanner = await DeviceHelpers.GetFirstBarcodeScannerAsync(); if (scanner != null) { // after successful creation, claim the scanner for exclusive use and enable it so that data reveived events are received. claimedScanner = await scanner.ClaimScannerAsync(); if (claimedScanner != null) { // It is always a good idea to have a release device requested event handler. If this event is not handled, there are chances of another app can // claim ownsership of the barcode scanner. claimedScanner.ReleaseDeviceRequested += claimedScanner_ReleaseDeviceRequested; // after successfully claiming, attach the datareceived event handler. claimedScanner.DataReceived += claimedScanner_DataReceived; // Ask the API to decode the data by default. By setting this, API will decode the raw data from the barcode scanner and // send the ScanDataLabel and ScanDataType in the DataReceived event claimedScanner.IsDecodeDataEnabled = true; // enable the scanner. // Note: If the scanner is not enabled (i.e. EnableAsync not called), attaching the event handler will not be any useful because the API will not fire the event // if the claimedScanner has not beed Enabled await claimedScanner.EnableAsync(); rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage); ScenarioEndScanButton.IsEnabled = true; } else { rootPage.NotifyUser("Claim barcode scanner failed.", NotifyType.ErrorMessage); ScenarioStartScanButton.IsEnabled = true; } } else { rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage); ScenarioStartScanButton.IsEnabled = true; } }
static void Main() { if (false == Is1st(true)) { return; } AppC.AppScope = AppC.APP4MC; // сканер BarcodeScanner xBCScanner = BarcodeScannerFacade.GetBarcodeScanner(null); // Новая рабочая область - весь экран Rectangle rtDesktop, rtNew; rtDesktop = Screen.PrimaryScreen.Bounds; rtNew = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); //TouchPanelDisable(); // Отключить TouchScreen //xBCScanner.TouchScr(false); //oKeyW = new MessageHooker(); // создание инициализация //oKeyW.SetHook(); // установка обработчика //Rectangle rtNew = new Rectangle(); //SetRect(ref rtNew, 0, 0, 240, 320); SystemParametersInfo(47, 0, ref rtNew, 1); HideTaskbar(); MainF frmMain = new MainF(xBCScanner); Application.Run(frmMain); ShowTaskbar(); SystemParametersInfo(47, 0, ref rtDesktop, 1); //mutex.Close(); xBCScanner.TouchScr(true); Is1st(false); }
public static async Task <string> ScanQRCode(string message, string closeButtonTitle, Activity activity, bool tryInverted = false) { BarcodeScanner.Initialize(activity.Application); var scanner = new BarcodeScanner(); var overlayView = new ScanQrOverlayView(activity); scanner.CustomOverlay = overlayView; overlayView.SetDescriptionText(message); overlayView.SetCloseButtonText(closeButtonTitle); var options = MobileBarcodeScanningOptions.Default; options.TryInverted = tryInverted; var result = await scanner.Scan(options); return(result?.Text); }
public IHttpActionResult PostCopy(byte[] image) { string result = BarcodeScanner.Scan(image); if (result.Equals("")) { return(NotFound()); } int id = Convert.ToInt32(result); Copy copy = db.Copies.FirstOrDefault(c => c.Id == id); if (copy == null) { return(NotFound()); } return(Ok(result)); }
//<SnippetCreateBarcodeScanner> //Creates a barcode scanner. private async Task <bool> CreateDefaultScannerObject() { if (scanner == null) { scanner = await BarcodeScanner.GetDefaultAsync(); if (scanner != null) { // UpdateOutput("Default Barcode Scanner created."); // UpdateOutput("Device Id is:" + scanner.DeviceId); } else { // UpdateOutput("Barcode Scanner not found. Please connect a Barcode Scanner."); return(false); } } return(true); }
public bool TestConn(bool bForcibly, BarcodeScanner xBCS, FuncPanel xFP) { bool ret = true; //string sOldInf = xFPan.RegInf; WiFiStat.CONN_TYPE cT = xBCS.WiFi.ConnectionType(); if ((cT == WiFiStat.CONN_TYPE.NOCONNECTIONS) || (bForcibly)) { bool bHidePan = false; if (!xFP.IsShown) { //xBCS.WiFi.IsEnabled = true; xBCS.WiFi.ShowWiFi((Control)xFP.xPan, true); xFP.ShowP(6, 50, "Переподключение к сети", "Wi-Fi"); bHidePan = true; } Cursor crsOld = Cursor.Current; Cursor.Current = Cursors.WaitCursor; xFP.RegInf = "Переподключение Wi-Fi..."; ret = xBCS.WiFi.ResetWiFi(2); if (ret) { Thread.Sleep(4000); xBCS.WiFi.GetIPList(); xFP.RegInf = "IP: " + xBCS.WiFi.IPCurrent; } else { xFP.RegInf = "Wi-Fi недоступен..."; } if (bHidePan) { xFP.HideP(); } Cursor.Current = crsOld; } return(ret); }
private async void buttonEnable_Click(object sender, RoutedEventArgs e) { scanner = await BarcodeScanner.GetDefaultAsync(); if (claimedScanner != null) { claimedScanner.Dispose(); } claimedScanner = await scanner.ClaimScannerAsync(); claimedScanner.DataReceived += ClamedScanner_DataReceived; await claimedScanner.EnableAsync(); claimedScanner.IsDecodeDataEnabled = true; await claimedScanner.SetActiveSymbologiesAsync(new uint[] { BarcodeSymbologies.Aztec, BarcodeSymbologies.AusPost, BarcodeSymbologies.CanPost, BarcodeSymbologies.Codabar, BarcodeSymbologies.Codablock128, BarcodeSymbologies.Code11, BarcodeSymbologies.Code128, BarcodeSymbologies.Code39, BarcodeSymbologies.Code39Ex, BarcodeSymbologies.DataMatrix, BarcodeSymbologies.Ean13, BarcodeSymbologies.Ean8, BarcodeSymbologies.Gs1128, BarcodeSymbologies.Gs1DatabarType1, BarcodeSymbologies.Gs1DatabarType2, BarcodeSymbologies.Gs1DatabarType3, BarcodeSymbologies.Pdf417, BarcodeSymbologies.Qr, BarcodeSymbologies.OcrB, BarcodeSymbologies.UccEan128, BarcodeSymbologies.Upca, BarcodeSymbologies.Upce, BarcodeSymbologies.UsPostNet, }); changeButtonEnable(true); }
/// <summary> /// Select the scanner specified by its device ID. /// </summary> /// <param name="scannerDeviceId"></param> private async Task SelectScannerAsync(string scannerDeviceId) { isSelectionChanging = true; await CloseScannerResourcesAsync(); selectedScanner = await BarcodeScanner.FromIdAsync(scannerDeviceId); if (selectedScanner != null) { claimedScanner = await selectedScanner.ClaimScannerAsync(); if (claimedScanner != null) { await claimedScanner.EnableAsync(); claimedScanner.Closed += ClaimedScanner_Closed; ScannerSupportsPreview = !String.IsNullOrEmpty(selectedScanner.VideoDeviceId); RaisePropertyChanged(nameof(ScannerSupportsPreview)); claimedScanner.DataReceived += ClaimedScanner_DataReceived; if (ScannerSupportsPreview) { await StartMediaCaptureAsync(selectedScanner.VideoDeviceId); } } else { rootPage.NotifyUser("Failed to claim the selected barcode scanner", NotifyType.ErrorMessage); } } else { rootPage.NotifyUser("Failed to create a barcode scanner object", NotifyType.ErrorMessage); } IsScannerClaimed = claimedScanner != null; RaisePropertyChanged(nameof(IsScannerClaimed)); isSelectionChanging = false; }
/// <summary> /// Creates the default barcode scanner. /// </summary> /// <returns>true if barcode scanner is created. Otherwise returns false</returns> private async Task<bool> CreateDefaultScannerObject() { if (scanner == null) { UpdateOutput("Creating Barcode Scanner object."); scanner = await BarcodeScanner.GetDefaultAsync(); if (scanner != null) { UpdateOutput("Default Barcode Scanner created."); UpdateOutput("Device Id is:" + scanner.DeviceId); } else { UpdateOutput("Barcode Scanner not found. Please connect a Barcode Scanner."); return false; } } return true; }
/// <summary> /// Reset the Scenario state /// </summary> private void ResetTheScenarioState() { if (claimedBarcodeScannerInstance1 != null) { claimedBarcodeScannerInstance1.Dispose(); claimedBarcodeScannerInstance1 = null; } scannerInstance1 = null; if (claimedBarcodeScannerInstance2 != null) { claimedBarcodeScannerInstance2.Dispose(); claimedBarcodeScannerInstance2 = null; } scannerInstance2 = null; ResetUI(); }
/// <summary> /// Analyse chaque fichier contenu dans le répertoire initialisé par le constructeur /// </summary> /// <returns>Dictionnaire contenant le nom du fichier et le résultat du scan</returns> public Dictionary <string, string> Analyse() { Dictionary <string, string> recognizedEAN = new Dictionary <string, string>(); string filesDirectory = Path.Combine(Path.GetTempPath(), FolderLocation); foreach (string file in Directory.GetFiles(filesDirectory)) { string[] barcode = BarcodeScanner.Scan(file, BarcodeType.EAN13); if (barcode.Count() != 0) { recognizedEAN.Add(file, barcode.First()); } else { recognizedEAN.Add(file, null); } } return(recognizedEAN); }
private void Sen_Message_Click(object sender, RoutedEventArgs e) { Communication_DatabaseEntities1 var_data = new Communication_DatabaseEntities1(); string valuetopass = ""; string[] reading_image = BarcodeScanner.Scan("QRCode.png", Spire.Barcode.BarCodeType.QRCode); if (reading_image != null) { foreach (var item in reading_image) { Console.WriteLine("Credentials found. Logging into system."); valuetopass = item; } } Console.WriteLine(valuetopass); var call_data = valuetopass.Split(','); Console.WriteLine(call_data[0]); var_data.New_Message(Int32.Parse(call_data[0]), Text_Outbound.Text); }
public MainF(BarcodeScanner xSc) { int nW, nH; double nKoef = Screen.PrimaryScreen.Bounds.Width / 240.0; InitializeComponent(); xSc.BCInvoker = this; Point p; Size s; switch (xSc.nTermType) { case TERM_TYPE.UNKNOWN: nW = (int)(81 * nKoef); nH = (int)(21 * nKoef); p = new Point(1, 1); s = new Size(nW, nH); break; case TERM_TYPE.HWELL6100: case TERM_TYPE.DL_SCORP: p = new Point(136, 140); s = new Size(72, 20); break; case TERM_TYPE.HWELLHX2: p = new Point(216, 60); s = new Size(72, 18); break; case TERM_TYPE.SYMBOL: default: p = new Point(1, 1); s = new Size(0, 0); break; } InitializeDop(xSc, s, p); }
public static OneDCodeData GetOneDCode(Mat img, int x, int y, int w, int h, int s1, int s2) { img = img.Clone() * (s2 / 1000); img = img.CvtColor(ColorConversionCodes.BGR2GRAY); img = img.Threshold(s1, 255, ThresholdTypes.Binary); OneDCodeData codedata = new OneDCodeData(); var code = img.SubMat(y, y + h, x, x + w); code = code.Resize(new OpenCvSharp.Size(code.Width * 0.4, code.Height * 0.4)); string[] data = BarcodeScanner.Scan(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(code), BarCodeType.Code128); if (data.Length != 0) { codedata.code = data[0]; } codedata.code = codedata.code.Replace("-", ""); codedata.code_img = code; codedata.full_img = img; return(codedata); }
/// <summary> /// Read the Barcode from the Image. /// </summary> /// <param name="FileName"></param> /// <returns></returns> public static String Read(Bitmap bmpImage) { //Bitmap bmpImage = new Bitmap(FileName); bmpImage = AdjustContrast(bmpImage, (float)30.0); String _return = ""; System.Collections.ArrayList barcodes = new System.Collections.ArrayList(); int iScans = 100; BarcodeScanner.FullScanPage(ref barcodes, bmpImage, iScans, BarcodeScanner.BarcodeType.All); if (barcodes.Count <= 0) { BarcodeScanner.ScanPage(ref barcodes, bmpImage, iScans, BarcodeScanner.ScanDirection.Horizontal, BarcodeScanner.BarcodeType.All); } foreach (var Str in barcodes) { _return = _return + Str.ToString(); } return(_return); }
/// <summary> /// Reset the Scenario state /// </summary> private void ResetTheScenarioState() { if (claimedScanner != null) { // Detach the event handlers claimedScanner.DataReceived -= claimedScanner_DataReceived; claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested; // Release the Barcode Scanner and set to null claimedScanner.Dispose(); claimedScanner = null; } if (scanner != null) { scanner.Dispose(); scanner = null; } symbologyAttributes = null; // Reset the UI if we are still the current page. if (Frame.Content == this) { rootPage.NotifyUser("Click the start scanning button to begin.", NotifyType.StatusMessage); this.ScenarioOutputScanData.Text = "No data"; this.ScenarioOutputScanDataLabel.Text = "No data"; this.ScenarioOutputScanDataType.Text = "No data"; // reset the button state ScenarioEndScanButton.IsEnabled = false; ScenarioStartScanButton.IsEnabled = true; SetSymbologyAttributesButton.IsEnabled = false; EnableCheckDigit.IsEnabled = false; TransmitCheckDigit.IsEnabled = false; SetDecodeRangeLimits.IsEnabled = false; // reset symbology list listOfSymbologies.Clear(); } }
public async Task <bool> ReleaseScannerAsync(bool exit) { try { if (claimedScanner != null) { claimedScanner.DataReceived -= ClaimedScanner_DataReceivedAsync; claimedScanner.ReleaseDeviceRequested -= OnClaimedScannerReleaseDeviceRequested; claimedScanner.IsDecodeDataEnabled = false; await claimedScanner.DisableAsync(); claimedScanner.Dispose(); } scanner = null; } catch (Exception ex) { //Console.WriteLine(ex.Message); return(false); } return(true); }
private async Task <bool> CreateScannerObjectFromVideo() { var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); // Return the first device found var device = (allVideoDevices.Count == 1) ? allVideoDevices[0] : null; if (allVideoDevices.Count > 1) { // try to get the back panel first device = allVideoDevices.First(w => w.EnclosureLocation.Panel == Panel.Back); if (device == null) { device = allVideoDevices[0]; } } if (device != null) { var isExternal = (device.EnclosureLocation == null || device.EnclosureLocation.Panel == Panel.Unknown || device.EnclosureLocation.InDock || device.EnclosureLocation.InLid); if (!isExternal) { if (device.EnclosureLocation.RotationAngleInDegreesClockwise > 0) { //await SetPreviewRotationAsync(); //_rotationHelper = new CameraRotationHelper(device.EnclosureLocation); //_rotationHelper.OrientationChanged += RotationHelper_OrientationChanged; } } } scanner = await BarcodeScanner.FromIdAsync(device.Id); if (scanner == null) { //rootPage.NotifyUser("Failed to create barcode scanner object.", NotifyType.ErrorMessage); return(false); } return(true); }
public bool Deactivate() { if (claimedScanner != null) { try { // Detach the event handlers claimedScanner.DataReceived -= claimedScanner_DataReceived; claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested; // Release the Barcode Scanner and set to null claimedScanner.Dispose(); claimedScanner = null; } catch (Exception) { } } scanner = null; return(true); }
private void ProcessBarcodeResponse(byte[] packet) { BarcodeResponse response = new BarcodeResponse(packet); string barCode = response.Barcode; BarcodeScanner type = response.ScannerType; switch (type) { case BarcodeScanner.TubeScanner: TubeBarcodeReceived?.Invoke(barCode); analyzerState.TubeBarcode = barCode; break; case BarcodeScanner.CartridgeScanner: CartridgeBarcodeReceived?.Invoke(barCode); analyzerState.CartridgeBarcode = barCode; break; default: break; } }
private void button1_Click(object sender, EventArgs e) // Mygtuko Skenuoti paspaudimo event { OpenFileDialog open = new OpenFileDialog(); // Atidaro dialog langa atsidaryti nuotrauką iš kompiuterio failų open.Filter = "JPG(*.JPG|*.jpg"; // Folderiuose filtruoja JPG failus if (open.ShowDialog() == DialogResult.OK) //Event jei mygtukas OK dialog lange buvo paspaustas { textBox1.Clear(); File = Image.FromFile(open.FileName); pictureBox1.Image = File; BarcodeLocation = open.FileName; String[] Barcode = BarcodeScanner.Scan(BarcodeLocation); if (Barcode.Length != 0) { textBox1.AppendText(Barcode[0]); } else { MessageBox.Show("Nepavyko aptikti barkodo"); } } }
public MainF(BarcodeScanner xSc) { InitializeComponent(); xSc.BCInvoker = this; Point p; Size s; switch (xSc.nTermType) { case TERM_TYPE.HWELL6100: case TERM_TYPE.DL_SCORP: p = new Point(136, 140); s = new Size(72, 20); break; default: p = new Point(137, 141); s = new Size(70, 18); break; } InitializeDop(xSc, s, p); }
private async void buttonEnable_Click(object sender, RoutedEventArgs e) { scanner = await BarcodeScanner.GetDefaultAsync(); if (claimedScanner != null) claimedScanner.Dispose(); claimedScanner = await scanner.ClaimScannerAsync(); claimedScanner.DataReceived += ClamedScanner_DataReceived; await claimedScanner.EnableAsync(); claimedScanner.IsDecodeDataEnabled = true; await claimedScanner.SetActiveSymbologiesAsync(new uint[] { BarcodeSymbologies.Aztec, BarcodeSymbologies.AusPost, BarcodeSymbologies.CanPost, BarcodeSymbologies.Codabar, BarcodeSymbologies.Codablock128, BarcodeSymbologies.Code11, BarcodeSymbologies.Code128, BarcodeSymbologies.Code39, BarcodeSymbologies.Code39Ex, BarcodeSymbologies.DataMatrix, BarcodeSymbologies.Ean13, BarcodeSymbologies.Ean8, BarcodeSymbologies.Gs1128, BarcodeSymbologies.Gs1DatabarType1 , BarcodeSymbologies.Gs1DatabarType2, BarcodeSymbologies.Gs1DatabarType3, BarcodeSymbologies.Pdf417, BarcodeSymbologies.Qr, BarcodeSymbologies.OcrB, BarcodeSymbologies.UccEan128, BarcodeSymbologies.Upca, BarcodeSymbologies.Upce, BarcodeSymbologies.UsPostNet, }); changeButtonEnable(true); }
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); }
/// <summary> /// Reset the Scenario state /// </summary> private void ResetTheScenarioState() { if (claimedScanner != null) { // Detach the event handlers claimedScanner.DataReceived -= claimedScanner_DataReceived; claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested; // Release the Barcode Scanner and set to null claimedScanner.Dispose(); claimedScanner = null; } scanner = null; // Reset the strings in the UI UpdateOutput("Click the Start Scanning Button."); this.ScenarioOutputScanData.Text = "No data"; this.ScenarioOutputScanDataLabel.Text = "No data"; this.ScenarioOutputScanDataType.Text = "No data"; // reset the button state ScenarioEndScanButton.IsEnabled = false; ScenarioStartScanButton.IsEnabled = true; }
public IActionResult Scan(IFormFile imageFile) { var model = new ResultView(); var barcode = new BarcodeScanner(imageFile); if (barcode.ReadBarcode()) { model.ScanSuccessful = barcode.ScanSuccessful; model.Code = barcode.OutputCode; var product = ProductService.GetProduct(barcode.OutputCode); if (product == null) { var apiObj = new FoodFactsAPI(barcode.OutputCode); if (apiObj.CallAPI()) { model.LoadProductSuccessful = apiObj.LoadSuccessful; model.ProductView = ProductService.CreateAndGetProduct(apiObj.Product); } } else { model.LoadProductSuccessful = true; model.ProductView = product; } model.ItemStoreSelect = new ItemStoreSelect( model.ProductView.ProductID, WarehouseService.GetLocations(UserID) ); } return(PartialView("ScanResult", model)); }
static void Main(string[] args) { try { var usbDevices = new UsbRegDeviceList(); scanner = new BarcodeScanner("05FE", "1010", 0); } catch (Exception e) { Console.WriteLine($"Could not initialize barcode scanner:{e.Message}"); } if (scanner != null) { while (true) { try { var result = scanner.Read(); Console.WriteLine($"Bytes read:{result.Bytes.ToString()} Length:{result.Length}"); } catch (Exception e) { Console.WriteLine($"Exception:{e.Message}"); } } } }
/// <summary> /// This method returns the first available Barcode Scanner. To enumerate and find a particular device use the device enumeration code. /// </summary> /// <returns>a boolean value based on whether it found a compatible scanner connected</returns> private async Task<bool> CreateDefaultScannerObjectAsync(BarcodeScannerInstance instance) { BarcodeScanner scanner = null; scanner = await BarcodeScanner.GetDefaultAsync(); if (scanner == null) { UpdateOutput("Scanner not found. Please connect a Barcode Scanner."); return false; } switch (instance) { case BarcodeScannerInstance.Instance1: scannerInstance1 = scanner; UpdateOutput("Instance1 Default Barcode Scanner created."); break; case BarcodeScannerInstance.Instance2: scannerInstance2 = scanner; UpdateOutput("Instance2 Default Barcode Scanner created."); break; default: return false; } return true; }
private async void CodeScanner_Loaded(object sender, RoutedEventArgs e) { BarcodeList.ItemsSource = BarcodeHistory = new ObservableCollection <BarcodeItem>(); ExitLocker = new AutoResetEvent(false); string Selector = BarcodeScanner.GetDeviceSelector(PosConnectionTypes.Local); DeviceInformationCollection DeviceCollection = await DeviceInformation.FindAllAsync(Selector); if (DeviceCollection == null || DeviceCollection.Count == 0) { Pro.Visibility = Visibility.Collapsed; ProText.Text = "无摄像头可用"; return; } if (ApplicationData.Current.LocalSettings.Values["LastSelectedCameraSource"] is string StorageCameraSource) { foreach (var DeviceID in from Device in DeviceCollection where Device.Name.Contains(StorageCameraSource) select Device.Id) { using (BarcodeScanner Scanner = await BarcodeScanner.FromIdAsync(DeviceID)) { Capture = new MediaCapture(); var InitializeSettings = new MediaCaptureInitializationSettings { VideoDeviceId = Scanner.VideoDeviceId, StreamingCaptureMode = StreamingCaptureMode.Video, PhotoCaptureSource = PhotoCaptureSource.VideoPreview }; await Capture.InitializeAsync(InitializeSettings); var CameraFocusControl = Capture.VideoDeviceController.FocusControl; if (CameraFocusControl.Supported) { await CameraFocusControl.UnlockAsync(); CameraFocusControl.Configure(new FocusSettings { Mode = FocusMode.Continuous, AutoFocusRange = AutoFocusRange.FullRange }); await CameraFocusControl.FocusAsync(); } PreviewControl.Source = Capture; ClaimedScanner = await Scanner.ClaimScannerAsync(); ClaimedScanner.IsDisabledOnDataReceived = false; ClaimedScanner.IsDecodeDataEnabled = true; ClaimedScanner.DataReceived += ClaimedScanner_DataReceived; await ClaimedScanner.EnableAsync(); await ClaimedScanner.StartSoftwareTriggerAsync(); await Capture.StartPreviewAsync(); } break; } if (Capture == null) { ContentDialog dialog = new ContentDialog { Title = "提示", Content = " 设置所指定的摄像头无法应用于条码识别\r\r 已自动选择最合适的摄像头", CloseButtonText = "确定", Background = Application.Current.Resources["DialogAcrylicBrush"] as Brush }; _ = await dialog.ShowAsync(); using (BarcodeScanner Scanner = await BarcodeScanner.FromIdAsync(DeviceCollection.FirstOrDefault().Id)) { Capture = new MediaCapture(); var InitializeSettings = new MediaCaptureInitializationSettings { VideoDeviceId = Scanner.VideoDeviceId, StreamingCaptureMode = StreamingCaptureMode.Video, PhotoCaptureSource = PhotoCaptureSource.VideoPreview }; await Capture.InitializeAsync(InitializeSettings); var CameraFocusControl = Capture.VideoDeviceController.FocusControl; if (CameraFocusControl.Supported) { await CameraFocusControl.UnlockAsync(); CameraFocusControl.Configure(new FocusSettings { Mode = FocusMode.Continuous, AutoFocusRange = AutoFocusRange.FullRange }); await CameraFocusControl.FocusAsync(); } PreviewControl.Source = Capture; ClaimedScanner = await Scanner.ClaimScannerAsync(); ClaimedScanner.IsDisabledOnDataReceived = false; ClaimedScanner.IsDecodeDataEnabled = true; ClaimedScanner.DataReceived += ClaimedScanner_DataReceived; await ClaimedScanner.EnableAsync(); await ClaimedScanner.StartSoftwareTriggerAsync(); await Capture.StartPreviewAsync(); } } } else { using (BarcodeScanner Scanner = await BarcodeScanner.FromIdAsync(DeviceCollection.FirstOrDefault().Id)) { Capture = new MediaCapture(); var InitializeSettings = new MediaCaptureInitializationSettings { VideoDeviceId = Scanner.VideoDeviceId, StreamingCaptureMode = StreamingCaptureMode.Video, PhotoCaptureSource = PhotoCaptureSource.VideoPreview }; await Capture.InitializeAsync(InitializeSettings); var CameraFocusControl = Capture.VideoDeviceController.FocusControl; if (CameraFocusControl.Supported) { await CameraFocusControl.UnlockAsync(); CameraFocusControl.Configure(new FocusSettings { Mode = FocusMode.Continuous, AutoFocusRange = AutoFocusRange.FullRange }); await CameraFocusControl.FocusAsync(); } PreviewControl.Source = Capture; ClaimedScanner = await Scanner.ClaimScannerAsync(); ClaimedScanner.IsDisabledOnDataReceived = false; ClaimedScanner.IsDecodeDataEnabled = true; ClaimedScanner.DataReceived += ClaimedScanner_DataReceived; await ClaimedScanner.EnableAsync(); await ClaimedScanner.StartSoftwareTriggerAsync(); await Capture.StartPreviewAsync(); } } LoadingControl.IsLoading = false; ExitLocker.Set(); }
/// <summary> /// This is the click handler for the 'ScenarioStartScanningInstance1' button. It initiates creation of scanner instance 1. /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private async void ButtonStartScanningInstance1_Click(object sender, RoutedEventArgs e) { //Get the handle to the default scanner if (await CreateDefaultScannerObjectAsync(BarcodeScannerInstance.Instance1)) { //Claim the scanner if (await ClaimBarcodeScannerAsync(BarcodeScannerInstance.Instance1)) { //add the event handlers claimedBarcodeScannerInstance1.ReleaseDeviceRequested += claimedBarcodeScannerInstance1_ReleaseDeviceRequested; claimedBarcodeScannerInstance1.DataReceived += claimedBarcodeScannerInstance1_DataReceived; claimedBarcodeScannerInstance1.IsDecodeDataEnabled = true; //Enable the Scanner if (await EnableBarcodeScannerAsync(BarcodeScannerInstance.Instance1)) { //Set the UI state ResetUI(); SetUI(BarcodeScannerInstance.Instance1); } } else { scannerInstance1 = null; } } }
/// <summary> /// Reset the Scenario state /// </summary> private void ResetTheScenarioState() { if (claimedBarcodeScannerInstance1 != null) { claimedBarcodeScannerInstance1.Dispose(); claimedBarcodeScannerInstance1 = null; } scannerInstance1 = null; if (claimedBarcodeScannerInstance2 != null) { claimedBarcodeScannerInstance2.Dispose(); claimedBarcodeScannerInstance2 = null; } scannerInstance2 = null; ResetUI(); }
/// <summary> /// This method returns the first available Barcode Scanner. To enumerate and find a particular device use the device enumeration code. /// </summary> /// <returns>a boolean value based on whether it found a compatible scanner connected</returns> private async Task<bool> CreateDefaultScannerObjectAsync(BarcodeScannerInstance instance) { BarcodeScanner scanner = null; scanner = await BarcodeScanner.GetDefaultAsync(); if (scanner == null) { rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage); return false; } switch (instance) { case BarcodeScannerInstance.Instance1: scannerInstance1 = scanner; break; case BarcodeScannerInstance.Instance2: scannerInstance2 = scanner; break; default: return false; } return true; }
/// <summary> /// This is the click handler for the 'ScenarioEndScanningInstance2' button. /// Initiates the disposal fo scanner instance 2. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private void ButtonEndScanningInstance2_Click(object sender, RoutedEventArgs e) { //remove the event handlers claimedBarcodeScannerInstance2.DataReceived -= claimedBarcodeScannerInstance2_DataReceived; claimedBarcodeScannerInstance2.ReleaseDeviceRequested -= claimedBarcodeScannerInstance2_ReleaseDeviceRequested; //dispose the instance claimedBarcodeScannerInstance2.Dispose(); claimedBarcodeScannerInstance2 = null; scannerInstance2 = null; //reset the UI ResetUI(); rootPage.NotifyUser("Click a start scanning button to begin.", NotifyType.StatusMessage); }
public BarcodeScannerEvents(BarcodeScanner This) { this.This = This; }
public static async Task <BarcodeScanner> GetFirstBarcodeScannerAsync(PosConnectionTypes connectionTypes = PosConnectionTypes.All) { return(await DeviceHelpers.GetFirstDeviceAsync(BarcodeScanner.GetDeviceSelector(connectionTypes), async (id) => await BarcodeScanner.FromIdAsync(id))); }
/// <summary> /// This is the click handler for the 'ScenarioEndScanningInstance2' button. /// Initiates the disposal fo scanner instance 2. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private void ButtonEndScanningInstance2_Click(object sender, RoutedEventArgs e) { //remove the event handlers claimedBarcodeScannerInstance2.DataReceived -= claimedBarcodeScannerInstance2_DataReceived; claimedBarcodeScannerInstance2.ReleaseDeviceRequested -= claimedBarcodeScannerInstance2_ReleaseDeviceRequested; //dispose the instance claimedBarcodeScannerInstance2.Dispose(); claimedBarcodeScannerInstance2 = null; scannerInstance2 = null; //reset the UI ResetUI(); UpdateOutput("Scanner Instance 1 Destroyed\n"); }
/// <summary> /// Reset the Scenario state /// </summary> private void ResetTheScenarioState() { if (claimedScanner != null) { // Detach the event handlers claimedScanner.DataReceived -= claimedScanner_DataReceived; claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested; // Release the Barcode Scanner and set to null claimedScanner.Dispose(); claimedScanner = null; } scanner = null; // Reset the strings in the UI rootPage.NotifyUser("Click the start scanning button to begin.", NotifyType.StatusMessage); this.ScenarioOutputScanData.Text = "No data"; this.ScenarioOutputScanDataLabel.Text = "No data"; this.ScenarioOutputScanDataType.Text = "No data"; // reset the button state ScenarioEndScanButton.IsEnabled = false; ScenarioStartScanButton.IsEnabled = true; }