void IScanSuccessCallback.barcodeDetected(MWResult result) { if (result != null) { Console.WriteLine("Finished with result"); if (scanner.closeScannerOnDecode) { new Handler().PostDelayed(() => RunOnUiThread(() => { var dialog = new AlertDialog.Builder(this); dialog.SetTitle(result.typeText); dialog.SetMessage(result.text); dialog.Show(); }), 500); } else { Toast.MakeText(ApplicationContext, result.typeText + "\n" + result.text, ToastLength.Short).Show(); new Handler().PostDelayed(() => RunOnUiThread(scanner.resumeScanning), 2000); } } else { //handle back pressed } }
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) { } }
public void barcodeDetected(MWResult result) { if (result != null) { try { if (editItemIndex >= 0) { listItems[editItemIndex].BarcodeResult = result.text; listItems[editItemIndex].BarcodeType = result.typeName; } 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 = result.typeName; 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); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } if (Element != null) { Element.Navigation.PopAsync(); } }
public void barcodeDetected(MWResult result) { if (result != null) { if (scanner.closeScannerOnDecode) { new UIAlertView(result.typeName, result.text, null, "Close", null).Show(); } else { new System.Threading.Timer(obj => scanner.resumeScanning(), null, 2000, System.Threading.Timeout.Infinite); } } else { // handle close button } }
public void barcodeDetected(MWResult result) { if ((result == null) || ((_CodeFound == null) && (_DataFound == null))) { return; } if (_CodeFound != null) { List <ScanItem> list = DecodeScan(result.text.ToString()); if ((list != null) && (list.Count > 0)) { _CodeFound(list); } } else { _DataFound(result.bytes); } }
void IScanSuccessCallback.barcodeDetected(MWResult result){ if (result != null) { Console.WriteLine ("Finished with result"); if (scanner.closeScannerOnDecode) { new Handler ().PostDelayed (() => RunOnUiThread (() => { var dialog = new AlertDialog.Builder (this); dialog.SetTitle (result.typeText); dialog.SetMessage (result.text); dialog.Show (); }), 500); } else { Toast.MakeText (ApplicationContext, result.typeText + "\n" + result.text, ToastLength.Short).Show (); new Handler ().PostDelayed (() => RunOnUiThread (scanner.resumeScanning), 2000); } } else { //handle back pressed } }
public static MWResult decodeFrame([ReadOnlyArray()] byte[] returnArray, int width, int height)//, out MWResult mwResult) { MWResult mwResult = null; if (returnArray == null) { return(mwResult); } //Debug.WriteLine("In DecodeFrame: " + ("\n\taThreads: ") + aThreads + "\tconv_count: " + convertedQueue.Count); //tconv_count always 0, thats why law_n_order.WaitOne(); if (aThreads < maxThreads) //rm && convertedQueue.Count > 0 thaaank you { aThreads++; conversionResult cData = new conversionResult(); cData.width = width; cData.height = height; cData.returnArray = returnArray; //spawn a new thread BackgroundWorker bWorkerX = new BackgroundWorker(); bWorkerX.WorkerReportsProgress = false; bWorkerX.WorkerSupportsCancellation = false; bWorkerX.DoWork += new DoWorkEventHandler(bWorkerX_DoWork); bWorkerX.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bWorkerX_RunWorkerCompleted); bWorkerX.RunWorkerAsync(cData); } if (decodedQueue.Count > 0) { mwResult = decodedQueue.Dequeue(); //reset/clear up iniClear(); //Debug.WriteLine("found it!"); } law_n_order.ReleaseMutex(); return(mwResult); }
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--; }
// scanImage implementation public static MWResult scanImage([ReadOnlyArray()] byte[] rawImage, int width, int height) { MWResult mwResult = null; int size = width * height; byte[] gray = new byte[size]; int colorChannels = 4; int colorChannelOffset = 1; for (int y = 0; y < height; y++) { int dstOffset = y * width; int srcOffset = ((y * width) * colorChannels) + colorChannelOffset; for (int x = 0; x < width; x++) { gray[dstOffset + x] = rawImage[srcOffset]; srcOffset += colorChannels; } } string s = null; Scanner.MWBsetResultType(Scanner.MWB_RESULT_TYPE_MW); byte[] p_data = new byte[10000]; int len = Scanner.MWBscanGrayscaleImage(gray, width, height, p_data); if (len > 0) { MWResults mwres = new MWResults(p_data); mwResult = null; if (mwres != null && mwres.count > 0) { mwResult = mwres.getResult(0); // with parser if (MWPARSER_MASK != Scanner.MWP_PARSER_MASK_NONE && !(MWPARSER_MASK == Scanner.MWP_PARSER_MASK_GS1 && !mwResult.isGS1)) { double parserRes = -1; byte[] pp_data = new byte[10000]; 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)) { parserRes = BarcodeLib.Scanner.MWPgetJSON(MWPARSER_MASK, System.Text.Encoding.UTF8.GetBytes(mwResult.encryptedResult), pp_data); if (parserRes >= 0) { mwResult.text = Encoding.UTF8.GetString(pp_data, 0, pp_data.Length); int index = mwResult.text.IndexOf('\0'); if (index >= 0) { mwResult.text = mwResult.text.Remove(index); } } } } } } return(mwResult); }
public void barcodeDetected(MWResult result) { if ((result == null) || ((_CodeFound == null) && (_DataFound == null))) return; if (_CodeFound != null) { List<ScanItem> list = DecodeScan(result.text.ToString()); if ((list != null) && (list.Count > 0)) _CodeFound(list); } else { _DataFound(result.bytes); } }
public void barcodeDetected (MWResult result) { if (result != null) { if (scanner.closeScannerOnDecode) { new UIAlertView (result.typeName, result.text, null, "Close", null).Show (); } else { new System.Threading.Timer (obj => scanner.resumeScanning (), null, 2000, System.Threading.Timeout.Infinite); } } else { // handle close button } }
private async void FindCodes(byte[] data, int width, int height) { byte[] bytes = new byte[data.Length / 4]; System.Diagnostics.Debug.WriteLine("Refining Data ({0}. {1}, {2})", data.Length, width, height); for (int i = 0; i < bytes.Length; i++) { bytes[i] = data[i * 4]; } System.Diagnostics.Debug.WriteLine("Finding Codes {0}", _Threads); byte[] resultData = new byte[10000]; int result = BarcodeLib.Scanner.MWBscanGrayscaleImage(bytes, Convert.ToInt32(width), Convert.ToInt32(height), resultData); if ((result < 0) || _Done) { System.Diagnostics.Debug.WriteLine("Scan Result: {0} - Fail", result); resultData = null; _Threads--; return; } string resultText = string.Empty; var type = BarcodeLib.Scanner.MWBgetResultType(); System.Diagnostics.Debug.WriteLine("Scan Result type: {0}", type); if (BarcodeLib.Scanner.MWBgetResultType() < 0) { System.Diagnostics.Debug.WriteLine("Scan Result - Fail: {0}", type); resultData = null; _Threads--; return; } if (type == 2) { MWResults results = new MWResults(resultData); if (results.count == 0) { var s = System.Text.Encoding.UTF8.GetString(resultData, 0, resultData.Length); System.Diagnostics.Debug.WriteLine("No Data."); System.Diagnostics.Debug.WriteLine(s); resultData = null; _Threads--; return; } MWResult scanResult = results.getResult(0); resultText = scanResult.text; scanResult = null; } else { resultText = System.Text.Encoding.UTF8.GetString(resultData, 0, resultData.Length); } // return the result if (!string.IsNullOrEmpty(resultText)) { _Done = true; if (_CodesFound != null) { Utilities.Dispatch(() => { ScanResults = DecodeScan(resultText); _CodesFound(ScanResults); }); } else if (_DataFound != null) { Utilities.Dispatch(() => { _DataFound(resultData); }); } } resultData = null; _Threads--; }