protected override void OnDestroy() { try { if (mobileComputer != null) { mobileComputer.Scan -= MobileComputer_Scan; mobileComputer.Scanner.EnableDefaultBarcodeTypes(); Toast.MakeText(this, "Mobile Computer EnableDefaulBarcodeTypes OK", ToastLength.Short).Show(); mobileComputer.Dispose(); mobileComputer = null; Toast.MakeText(this, "Mobile Computer Dispose OK", ToastLength.Short).Show(); } } catch (Exception ex) { Toast.MakeText(this, "MobileComputer Dispose error - " + ex.ToString(), ToastLength.Long).Show(); } base.OnDestroy(); }
private static void WaitUntilPluginScannerConnected(PluginBarcodeMobileComputer comp) { if (comp != null) { while (true) { if (comp.IsConnected) { break; } Thread.Sleep(100); } } }
private void ButtonCreate_Click(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem((x) => { try { mobileComputer = PluginBarcodeMobileComputer.ConnectPluginMobileComputer("cleverence.com.plugin.magdennewlandnls_nquire1000", this);// new CustomMobileComputer(this); WaitUntilPluginScannerConnected(mobileComputer); RunOnUiThread(() => { Toast.MakeText(this, "Mobile Computer Constructor OK", ToastLength.Short).Show(); }); mobileComputer.Scan += MobileComputer_Scan; mobileComputer.TurnOnScanner(); RunOnUiThread(() => { Toast.MakeText(this, "Mobile Computer TurnOnScanner OK", ToastLength.Short).Show(); }); } catch (Exception ex) { //RunOnUIThread(() => { Toast.MakeText(this, "MobileComputer Constructor error - " + ex.ToString(), ToastLength.Long).Show(); }); return; } RunOnUiThread(() => { var buttonCreate = FindViewById <Button>(Resource.Id.buttonCreate); buttonCreate.Enabled = false; var buttonStart = FindViewById <Button>(Resource.Id.buttonStartScan); buttonStart.Enabled = false; var buttonStop = FindViewById <Button>(Resource.Id.buttonStopScan); buttonStop.Enabled = true; var buttonDispose = FindViewById <Button>(Resource.Id.buttonDispose); buttonDispose.Enabled = true; var buttonEan = FindViewById <Button>(Resource.Id.buttonEan13); var buttonPdf417 = FindViewById <Button>(Resource.Id.buttonPdf417); var buttonDataMatrix = FindViewById <Button>(Resource.Id.buttonDataMatrix); if (mobileComputer.Scanner != null) { var supported = mobileComputer.Scanner.GetSupportedSymbologies(); if (supported != null) { if (supported.Length > 0) { buttonDataMatrix.Enabled = true; buttonEan.Enabled = true; buttonPdf417.Enabled = true; buttonEan.Text = "Push to Ean13 Only"; buttonPdf417.Text = "Push to Pdf417 Only"; buttonDataMatrix.Text = "Push to DataMatrix Only"; } } } var textActive = FindViewById <TextView>(Resource.Id.textScannerStatus); var buttonSettings = FindViewById <Button>(Resource.Id.buttonSettings); if (mobileComputer.Scanner != null) { if (mobileComputer.Scanner.IsSettingsAvailable) { buttonSettings.Enabled = true; buttonSettings.Text = "Settings avalable"; } else { buttonSettings.Enabled = false; buttonSettings.Text = "Settings not avalable"; } var status = mobileComputer.Scanner.IsTurnedOn ? "Enabled" : "Disabled"; textActive.Text = "Scanner Status: " + status; } var textId = FindViewById <TextView>(Resource.Id.textDeviceId); textId.Text = "Device Id: " + mobileComputer.GetDeviceId(); var textKeyboard = FindViewById <TextView>(Resource.Id.textHasKeyboard); textKeyboard.Text = "Has Keyboard: " + (mobileComputer.HasKeyboard ? "Yes" : "No"); Toast.MakeText(this, "Mobile Computer HasKeyboard OK", ToastLength.Short); }); }); }
private void ButtonDispose_Click(object sender, EventArgs e) { try { if (mobileComputer != null) { try { mobileComputer.Scan -= MobileComputer_Scan; mobileComputer.Dispose(); mobileComputer = null; Toast.MakeText(this, "Mobile Computer Dispose OK", ToastLength.Short).Show(); } catch (Exception ex) { Toast.MakeText(this, "MobileComputer Dispose error - " + ex.ToString(), ToastLength.Long).Show(); } mobileComputer = null; var buttonCreate = FindViewById <Button>(Resource.Id.buttonCreate); buttonCreate.Enabled = true; var buttonDispose = FindViewById <Button>(Resource.Id.buttonDispose); buttonDispose.Enabled = false; var buttonStart = FindViewById <Button>(Resource.Id.buttonStartScan); buttonStart.Enabled = false; var buttonStop = FindViewById <Button>(Resource.Id.buttonStopScan); buttonStop.Enabled = false; var buttonEan = FindViewById <Button>(Resource.Id.buttonEan13); buttonEan.Text = "Ean13"; buttonEan.Enabled = false; var buttonPdf417 = FindViewById <Button>(Resource.Id.buttonPdf417); buttonPdf417.Text = "PDF417"; buttonPdf417.Enabled = false; var buttonDataMatrix = FindViewById <Button>(Resource.Id.buttonDataMatrix); buttonDataMatrix.Text = "DataMatrix"; buttonDataMatrix.Enabled = false; var buttonSettings = FindViewById <Button>(Resource.Id.buttonSettings); buttonSettings.Text = "Settings"; buttonSettings.Enabled = false; var textId = FindViewById <TextView>(Resource.Id.textDeviceId); textId.Text = "Device Id:"; var textKeyboard = FindViewById <TextView>(Resource.Id.textHasKeyboard); textKeyboard.Text = "Has Keyboard:"; } } catch (Exception ex) { Toast.MakeText(this, "MobileComputer Dispose error - " + ex.ToString(), ToastLength.Long).Show(); } }