I am using Xamarin Android and EMDK and keep getting errors with the scanner service just dying or returning scanner disabled and am not using data wedge. This is a custom application for my company. WE needed a custom solution. I do get the EMDK status as success. However that does not translate into the scanner returning information.
I return the data to my application via an EventHandler. IN the end we are not trying to have special configurations. we want to set it once and just ignore the data in the UI if we do not need the scan we can throw it away.
I obviously may not know enough about all this. I am new to Android. My application is almost done but this scanner not coming up or just dying is plaguing us.
Thanks
-Pete
Xamarin Android and EMDK Failure |
2 Replies
Here is my code for the data and status events.
private void scanner_Data(object sender, Scanner.DataEventArgs e)
{
ScanDataCollection scanDataCollection = e.P0;
if ((scanDataCollection != null) && (scanDataCollection.Result == ScannerResults.Success))
{
var scanData = scanDataCollection.GetScanData();
foreach (var data in scanData)
{
displaydata(data.LabelType.ToString(), data.Data);
}
}
}
private void scanner_Status(object sender, Scanner.StatusEventArgs e)
{
String statusStr = "";
StatusData statusData = e.P0;
StatusData.ScannerStates state = e.P0.State;
try
{
if (state == StatusData.ScannerStates.Idle)
{
statusStr = "Scanner is idle and ready to submit read.";
try
{
if (scanner == null)
InitScanner();
if (scanner.IsEnabled && !scanner.IsReadPending)
{
Thread.Sleep(100);
scanner.Read();
}
}
catch (ScannerException e1)
{
statusStr = e1.Message;
string msg = "Exception - " + e1.Message;
if (ScannerStatusEvent != null)
ScannerStatusEvent(this, new ScannerDataEventArgs("", msg));
Log.Debug("BmService", msg);
}
}
if (state == StatusData.ScannerStates.Waiting)
{
statusStr = "Waiting for Trigger Press to scan";
}
if (state == StatusData.ScannerStates.Scanning)
{
statusStr = "Scanning in progress...";
}
if (state == StatusData.ScannerStates.Disabled)
{
statusStr = "Scanner disabled";
scanner.Enable();
}
if (state == StatusData.ScannerStates.Error)
{
statusStr = "Error occurred during scanning";
}
displayStatus(statusStr);
}
catch (Exception ex)
{
string msg = "Exception - " + ex.Message;
if (ScannerStatusEvent != null)
ScannerStatusEvent(this, new ScannerDataEventArgs("", msg));
Log.Debug("BmService", msg);
}
}
void InitScanner()
{
if (emdkManager != null)
{
if (barcodeManager == null)
{
try
{
//Get the feature object such as BarcodeManager object for accessing the feature.
barcodeManager = (BarcodeManager)emdkManager.GetInstance(EMDKManager.FEATURE_TYPE.Barcode);
if (barcodeManager != null)
{
// Add connection listener
barcodeManager.Connection += barcodeManager_Connection;
}
scanner = barcodeManager.GetDevice(BarcodeManager.DeviceIdentifier.Default);
if (scanner != null)
{
//Attahch the Data Event handler to get the data callbacks.
scanner.Data += scanner_Data;
//Attach Scanner Status Event to get the status callbacks.
scanner.Status += scanner_Status;
scanner.Enable();
//EMDK: Configure the scanner settings
ScannerConfig config = scanner.GetConfig();
config.SkipOnUnsupported = ScannerConfig.SkipOnUnSupported.None;
config.ScanParams.DecodeLEDFeedback = true;
config.ReaderParams.ReaderSpecific.ImagerSpecific.PickList = ScannerConfig.PickList.Enabled;
config.DecoderParams.Code39.Enabled = true;
config.DecoderParams.Code128.Enabled = false;
scanner.SetConfig(config);
}
else
{
displayStatus("Failed to enable scanner.\n");
}
}
catch (ScannerException e)
{
displayStatus("Error: " + e.Message);
}
catch (Exception ex)
{
displayStatus("Error: " + ex.Message);
}
}
}
}
Hi Peter,
It's difficult to say what could be causing your issue - I tried running your code but there isn't quite enough there to try and reproduce the issue.
What do you see in your adb log when the problem happens? And what device / OS are you using?
Also, it might be worth taking a look at the sample barcode app if you haven't seen it: Barcode APIs - Zebra Technologies Techdocs , that provides a known configuration for scanning through EMDK for Xamarin.