private void bw_DoWork(object sender, DoWorkEventArgs e) { Byte[] result = new Byte[10000]; BackgroundWorker worker = sender as BackgroundWorker; ThreadArguments ta = e.Argument as ThreadArguments; int resLen = Scanner.MWBscanGrayscaleImage(ta.pixels, ta.width, ta.height, result); if (lastTime != null && lastTime.Ticks > 0) { long timePrev = lastTime.Ticks; long timeNow = DateTime.Now.Ticks; long timeDifference = (timeNow - timePrev) / 10000; System.Diagnostics.Debug.WriteLine("frame time: {0}", timeDifference); } lastTime = DateTime.Now; //ignore results shorter than 4 characters for barcodes with weak checksum if (resLen > 4 || ((resLen > 0 && Scanner.MWBgetLastType() != Scanner.FOUND_39 && Scanner.MWBgetLastType() != Scanner.FOUND_25_INTERLEAVED && Scanner.MWBgetLastType() != Scanner.FOUND_25_STANDARD))) { string resultString = System.Text.Encoding.UTF8.GetString(result, 0, resLen); int bcType = Scanner.MWBgetLastType(); String typeName = BarcodeHelper.getBarcodeName(bcType); Deployment.Current.Dispatcher.BeginInvoke(delegate() { BarcodeHelper.scannerResult = new ScannerResult(); BarcodeHelper.resultAvailable = true; BarcodeHelper.scannerResult.code = resultString; BarcodeHelper.scannerResult.type = typeName; Byte[] binArray = new Byte[resLen]; for (int i = 0; i < resLen; i++) { binArray[i] = result[i]; } BarcodeHelper.scannerResult.bytes = binArray; stopCamera(); NavigationService.GoBack(); }); } else { isProcessing = false; cameraDevice.PreviewFrameAvailable += previewFrameHandler; } }
private async void SaveScanResult(MWResult result) { try { if (result != null) { if (editItemIndex >= 0) { listItems[editItemIndex].BarcodeResult = result.text; listItems[editItemIndex].BarcodeType = BarcodeHelper.getBarcodeName(result.type); } else { ItemModel itemResult = new ItemModel(); itemResult.ID = 1; if (listItems.Count > 0) { itemResult.ID = ((int)listItems.Max(x => x.ID)) + 1; } itemResult.Name = ""; itemResult.BarcodeResult = result.text; itemResult.BarcodeType = BarcodeHelper.getBarcodeName(result.type); listItems.Insert(0, itemResult); } if (Xamarin.Forms.Application.Current.Properties.ContainsKey("AllLists")) { string jsonList = Xamarin.Forms.Application.Current.Properties["AllLists"].ToString(); ObservableCollection <ListsModel> tempList = JsonConvert.DeserializeObject <ObservableCollection <ListsModel> >(jsonList); tempList[editListIndex].Items = listItems; Xamarin.Forms.Application.Current.Properties["AllLists"] = JsonConvert.SerializeObject(tempList); } } //On Xamarin navigation should go here if (Element.Navigation.ModalStack.Count > 0) { await Element.Navigation.PopModalAsync(); } } catch (Exception ex) { } }
private void bw_DoWork(object sender, DoWorkEventArgs e) { Byte[] result = new Byte[10000]; BackgroundWorker worker = sender as BackgroundWorker; ThreadArguments ta = e.Argument as ThreadArguments; int resLen = Scanner.MWBscanGrayscaleImage(ta.pixels, ta.width, ta.height, result); //ignore positive result if closing is in progress if (isClosing) { resLen = -1; } if (resLen > 0 && resultDisplayed) { resLen = -1; } MWResult mwResult = null; if (resLen > 0 && Scanner.MWBgetResultType() == Scanner.MWB_RESULT_TYPE_MW) { MWResults results = new MWResults(result); if (results.count > 0) { mwResult = results.getResult(0); result = mwResult.bytes; } } if (lastTime != null && lastTime.Ticks > 0) { long timePrev = lastTime.Ticks; long timeNow = DateTime.Now.Ticks; long timeDifference = (timeNow - timePrev) / 10000; System.Diagnostics.Debug.WriteLine("frame time: {0}", timeDifference); } lastTime = DateTime.Now; //ignore results shorter than 4 characters for barcodes with weak checksum if (mwResult != null && mwResult.bytesLength > 4 || (mwResult != null && mwResult.bytesLength > 0 && mwResult.type != Scanner.FOUND_39 && mwResult.type != Scanner.FOUND_25_INTERLEAVED && mwResult.type != Scanner.FOUND_25_STANDARD)) { resultDisplayed = true; String typeName = BarcodeHelper.getBarcodeName(mwResult); Deployment.Current.Dispatcher.BeginInvoke(delegate() { isClosing = true; BarcodeHelper.scannerResult = new ScannerResult(); BarcodeHelper.resultAvailable = true; BarcodeHelper.scannerResult.code = mwResult.text; BarcodeHelper.scannerResult.type = BarcodeHelper.getBarcodeName(mwResult); BarcodeHelper.scannerResult.isGS1 = mwResult.isGS1; Byte[] binArray = new Byte[mwResult.bytesLength]; for (int i = 0; i < mwResult.bytesLength; i++) { binArray[i] = mwResult.bytes[i]; } BarcodeHelper.scannerResult.bytes = binArray; stopCamera(); NavigationService.GoBack(); isProcessing = false; resultDisplayed = false; }); } else { isProcessing = false; } activeThreads--; }
private static void bWorkerX_DoWork(object sender, DoWorkEventArgs e) { int width = ((conversionResult)e.Argument).width; int height = ((conversionResult)e.Argument).height; byte[] returnArray = ((conversionResult)e.Argument).returnArray; //resString = ""; int resLen = 0; if (returnArray != null) { MWResult mwResult = null; byte[] result = new byte[10000]; try { // Debug.WriteLine("ReturnArat size: " + returnArray.Length); resLen = MWBarcodeScanner.scanGrayscaleImage(returnArray, width, height, result); // Debug.WriteLine("result size: " + result.Length + "ResLen = " + resLen); mwResult = null; } catch (Exception ee) { Debug.WriteLine(ee.Message); } if (resultDisplayed) { resLen = -1; } if (resLen > 0) { MWResults results = new MWResults(result); string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); if (results.count > 0) { mwResult = results.getResult(0); result = mwResult.bytes; } if ((resultDisplayed == false) && (mwResult != null)) { resultDisplayed = true; string typeName = BarcodeHelper.getBarcodeName(mwResult.type); // mwResult.typeText = typeName; byte[] parsedResult = new byte[6000]; string displayString = ""; if (USE_MWPARSER == true) { double parserRes = -1; //ignore results shorter than 4 characters for barcodes with weak checksum if (mwResult != null && mwResult.bytesLength > 4 || (mwResult != null && mwResult.bytesLength > 0 && mwResult.type != Scanner.FOUND_39 && mwResult.type != Scanner.FOUND_25_INTERLEAVED && mwResult.type != Scanner.FOUND_25_STANDARD)) { //Scanner.MWBsetDuplicate(mwResult.bytes, mwResult.bytesLength); //so praa? if (MWPARSER_MASK != Scanner.MWP_PARSER_MASK_NONE && !(MWPARSER_MASK == Scanner.MWP_PARSER_MASK_GS1 && !mwResult.isGS1)) { parserRes = BarcodeLib.Scanner.MWPgetFormattedText(MWPARSER_MASK, System.Text.Encoding.UTF8.GetBytes(mwResult.encryptedResult), parsedResult); if (parserRes >= 0) { mwResult.text = Encoding.UTF8.GetString(parsedResult, 0, parsedResult.Length); int index = mwResult.text.IndexOf('\0'); if (index >= 0) { mwResult.text = mwResult.text.Remove(index); } if (MWPARSER_MASK == Scanner.MWP_PARSER_MASK_AAMVA) { typeName = typeName + " (AAMVA)"; } else if (MWPARSER_MASK == Scanner.MWP_PARSER_MASK_IUID) { typeName = typeName + " (IUID)"; } else if (MWPARSER_MASK == Scanner.MWP_PARSER_MASK_ISBT) { typeName = typeName + " (ISBT)"; } else if (MWPARSER_MASK == Scanner.MWP_PARSER_MASK_HIBC) { typeName = typeName + " (HIBC)"; } else if (MWPARSER_MASK == Scanner.MWP_PARSER_MASK_SCM) { typeName = typeName + " (SCM)"; } } } } if (parserRes == -1) { displayString = mwResult.text; } else { displayString = System.Text.Encoding.UTF8.GetString(parsedResult); } } else { displayString = mwResult.text; } // if (USE_ANALYTICS) { // sendReport(mwResult); } try { // Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => //{ //successCallback.barcodeDetected(mwResult); // displayResultAsync_old(mwResult); // }); // displayResultAsync(mwResult); } catch (Exception ee) { Debug.WriteLine(ee.Message); } } resultDisplayed = false; law_n_order.WaitOne(); decodedQueue.Enqueue(mwResult); law_n_order.ReleaseMutex(); } } //decodedQueue.Enqueue(null); //no need as it's null by default //throw new NotImplementedException(); }
private void bw_DoWork(object sender, DoWorkEventArgs e) { Byte[] result = new Byte[10000]; BackgroundWorker worker = sender as BackgroundWorker; ThreadArguments ta = e.Argument as ThreadArguments; int resLen = Scanner.MWBscanGrayscaleImage(ta.pixels, ta.width, ta.height, result); //ignore positive result if closing is in progress if (isClosing) { resLen = -1; } if (resLen > 0 && resultDisplayed) { resLen = -1; } MWResult mwResult = null; if (resLen > 0 && Scanner.MWBgetResultType() == Scanner.MWB_RESULT_TYPE_MW) { MWResults results = new MWResults(result); if (results.count > 0) { mwResult = results.getResult(0); result = mwResult.bytes; } } if (lastTime != null && lastTime.Ticks > 0) { long timePrev = lastTime.Ticks; long timeNow = DateTime.Now.Ticks; long timeDifference = (timeNow - timePrev) / 10000; //System.Diagnostics.Debug.WriteLine("frame time: {0}", timeDifference); } lastTime = DateTime.Now; //ignore results shorter than 4 characters for barcodes with weak checksum if (mwResult != null && mwResult.bytesLength > 4 || (mwResult != null && mwResult.bytesLength > 0 && mwResult.type != Scanner.FOUND_39 && mwResult.type != Scanner.FOUND_25_INTERLEAVED && mwResult.type != Scanner.FOUND_25_STANDARD)) { Scanner.MWBsetDuplicate(mwResult.bytes, mwResult.bytesLength); resultDisplayed = true; String typeName = BarcodeHelper.getBarcodeName(mwResult); Deployment.Current.Dispatcher.BeginInvoke(delegate() { BarcodeHelper.scannerResult = new ScannerResult(); BarcodeHelper.resultAvailable = true; BarcodeHelper.scannerResult.code = mwResult.text; BarcodeHelper.scannerResult.type = BarcodeHelper.getBarcodeName(mwResult); BarcodeHelper.scannerResult.isGS1 = mwResult.isGS1; if (mwResult.locationPoints != null) { BarcodeHelper.scannerResult.location = "{\"p1\":{\"x\":" + floatToStrDot(mwResult.locationPoints.p1.x) + ", \"y\":" + floatToStrDot(mwResult.locationPoints.p1.y) + "}," + "\"p2\":{\"x\":" + floatToStrDot(mwResult.locationPoints.p2.x) + ", \"y\":" + floatToStrDot(mwResult.locationPoints.p2.y) + "}," + "\"p3\":{\"x\":" + floatToStrDot(mwResult.locationPoints.p3.x) + ", \"y\":" + floatToStrDot(mwResult.locationPoints.p3.y) + "}," + "\"p4\":{\"x\":" + floatToStrDot(mwResult.locationPoints.p4.x) + ", \"y\":" + floatToStrDot(mwResult.locationPoints.p4.y) + "}}"; } else { BarcodeHelper.scannerResult.location = "false"; } BarcodeHelper.scannerResult.imageWidth = mwResult.imageWidth; BarcodeHelper.scannerResult.imageHeight = mwResult.imageHeight; Byte[] binArray = new Byte[mwResult.bytesLength]; for (int i = 0; i < mwResult.bytesLength; i++) { binArray[i] = mwResult.bytes[i]; } BarcodeHelper.scannerResult.bytes = binArray; stopCamera(); string resultString = "{\"code\":" + JsonHelper.Serialize(BarcodeHelper.scannerResult.code) + "," + "\"type\":" + JsonHelper.Serialize(BarcodeHelper.scannerResult.type) + "," + "\"bytes\":" + JsonHelper.Serialize(BarcodeHelper.scannerResult.bytes) + "," + "\"isGS1\":" + JsonHelper.Serialize(BarcodeHelper.scannerResult.isGS1) + "," + "\"location\":" + BarcodeHelper.scannerResult.location + "," + "\"imageWidth\":" + BarcodeHelper.scannerResult.imageWidth + "," + "\"imageHeight\":" + BarcodeHelper.scannerResult.imageHeight + "}"; PluginResult pResult = new PluginResult(PluginResult.Status.OK, resultString); pResult.KeepCallback = true; MWBarcodeScanner.mwbScanner.DispatchCommandResult(pResult, MWBarcodeScanner.kallbackID); if (param_CloseScannerOnDecode) { isClosing = true; if (isPage) { NavigationService.GoBack(); } else { MWBarcodeScanner.mwbScanner.stopScanner(""); } resultDisplayed = false; } isProcessing = false; }); } else { isProcessing = false; } activeThreads--; }