Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Application crashes after some time and stop scanning bar code. Everytime i have to restart my device to continue scanning.

I am using Honeywell device and windows phone 8.1.


Can you please help me on this?

What I have tried:

<pre lang="c#">private BarcodeScanner scanner;
        private ClaimedBarcodeScanner claimedScanner;
        StorageFile myFile = null;
        private const string ProfileFileName = "HoneywellDecoderSettingsV2.exm";
		private async void UpdateUI_scandata(string symCode, string data)
        {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
             {
                 textBox.Text = data;
                 Audio_Player.Play();
             });
                System.Diagnostics.Debug.WriteLine(data);
        }

		private async void ClaimBarcodeScanner()
        {

                string x = string.Empty;
                if (scanner == null)
                {
                    scanner = await BarcodeScanner.GetDefaultAsync(); 
                    i = 1;
                    if (claimedScanner == null && scanner != null)
                    {
                        claimedScanner = await scanner.ClaimScannerAsync(); 
                    }
                }
                if (claimedScanner != null && scanner != null)
                {
                    claimedScanner.DataReceived += claimedScanner_DataReceived;                                              
                    await claimedScanner.EnableAsync();
                    claimedScanner.IsDecodeDataEnabled = true;
                    j = scanner.GetSupportedProfiles().Count();
                    foreach (string ProfileName in scanner.GetSupportedProfiles())
                    {
                        x = ProfileName;
                        i++;
                        if (ProfileName == "Retail Demo Profile")
                        {
                            await claimedScanner.SetActiveProfileAsync(ProfileName);
                        }
                    }
                }
		}
		
		
		
		
		async void claimedScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {

                string label;
                UInt32 symCode = args.Report.ScanDataType;
                using (var datareader = Windows.Storage.Streams.DataReader.FromBuffer(args.Report.ScanDataLabel))
                {
                    label = datareader.ReadString(args.Report.ScanDataLabel.Length);
                }
                UpdateUI_scandata(BarcodeSymbologies.GetName(symCode), label);
        }
		
		private async void WriteProfieFiletoDevice()
        {
            myFile = null;

                StorageFolder _folder = await KnownFolders.DocumentsLibrary.CreateFolderAsync("Profile", CreationCollisionOption.OpenIfExists);
                var uri = new System.Uri("ms-appx:///Assets/" + ProfileFileName);
                StorageFile profileFile = await StorageFile.GetFileFromApplicationUriAsync(uri);
                String profileContent = await FileIO.ReadTextAsync(profileFile);
                myFile = await _folder.CreateFileAsync(ProfileFileName, CreationCollisionOption.OpenIfExists);
                await FileIO.WriteTextAsync(myFile, profileContent);
        }
C#

Posted
Comments
Richard MacCutchan 4-Dec-17 5:19am    
Help you how?
Harish Kumar Bansal 4-Dec-17 5:23am    
What i am doing wrong as my application crashes after two or three scanning successfully. After crashes when i open again then not able to scan single time and then i have to restart my application.
Richard MacCutchan 4-Dec-17 5:28am    
Then you need to do some debugging to find out where it crashes and what lines(s) of code and variables are the cause. We cannot guess what is happening when your code runs.
Harish Kumar Bansal 4-Dec-17 5:58am    
Not able to debug on Phone as scanning only works on hand held device.
Ralf Meier 4-Dec-17 6:11am    
Then let your code run on a system where you can debug it. I don't believe that your error only depends on your phone.
(... or buy a good glass-bowl ...)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900