示例#1
0
        /// <summary>
        /// Sets the AddBarcodeDeviceListener for device connection status.
        /// </summary>
        /// <param name="context">This parameter needs to be a type of Android.Content.Context.
        /// It can be an activity or application context.</param>
        private void SetBarcodeDeviceListener(object context)
        {
            if (sBarcodeDeviceEventHandler != null)
            {
                return;
            }

            Task.Run(() =>
            {
                lock (mProfileFixLock)
                {
                    lock (mOpenLock)
                    {
                        using var barcodeReaderManager = BarcodeReaderManager.Create((Context)context);

                        if (mAidcManager == null)
                        {
                            mAidcManager = barcodeReaderManager.Init();
                        }
                    }

                    sBarcodeDeviceEventHandler = new BarcodeDeviceEventHandler(this);
                    mAidcManager.AddBarcodeDeviceListener(sBarcodeDeviceEventHandler);
                }
            });
        }
        /// <summary>
        /// Returns an instance of the BarcodeReaderManager object.
        /// Note: The context parameter is only used the first time this method
        /// is called to create the BarcodeReaderManager object. The subsequent
        /// calls will simply return the existing BarcodeReaderManager object.
        /// It will get the application context from the context parameter.
        /// Even if this method is called from different Activity classes,
        /// their application context is the same.
        /// </summary>
        /// <param name="context">An activity or application context.</param>
        /// <returns></returns>
        internal static BarcodeReaderManager Create(Context context)
        {
            lock (oCreateLock)
            {
                if (sInstance == null)
                {
                    sInstance = new BarcodeReaderManager(context);
                }

                return(sInstance);
            }
        }
示例#3
0
        /// <summary>
        /// Gets a list of barcode readers that are currently connected.
        /// </summary>
        /// <param name="context">This is an optional parameter default to null.
        /// On Android platform, it will use Android.App.Application.Context if
        /// the parameter value is null. If the parameter is not null, then it
        /// needs to be a type of Android.Content.Context. It can
        /// be either an activity or application context.</param>
        /// <returns>A list of <see cref="T:DevFromDownUnder.Honeywell.DataCollection.BarcodeReaderInfo" /> objects representing
        /// barcode readers that are currently connected.</returns>
        public static async Task <IList <BarcodeReaderInfo> > GetConnectedBarcodeReaders(object context = null)
        {
            if (context == null)
            {
                context = Application.Context;
            }
            else if (!(context is Context))
            {
                throw new ArgumentException("Invalid context type, must be Android.Content.Context.", "context");
            }

            return(await Task.Run(() =>
            {
                lock (mOpenLock)
                {
                    using BarcodeReaderManager barcodeReaderManager = BarcodeReaderManager.Create((Context)context);

                    barcodeReaderManager.Init();

                    return barcodeReaderManager.ListConnectedBarcodeDevices();
                }
            }));
        }
示例#4
0
        private Result OpenReader(string scannerName, Context context)
        {
            var result = new Result(Result.Codes.SUCCESS, "Reader successfully claimed.");

            if (!mReaderOpened)
            {
                try
                {
                    if (mAidcBarcodeReader == null)
                    {
                        lock (mOpenLock)
                        {
                            var manager = BarcodeReaderManager.Create(context);

                            if (manager != null)
                            {
                                mAidcManager       = manager.Init();
                                mAidcBarcodeReader = mAidcManager.CreateBarcodeReader(scannerName);
                                try
                                {
                                    mAidcBarcodeReader.SetProperty("TRIG_CONTROL_MODE", "autoControl");
                                }
                                catch (Com.Honeywell.Aidc.UnsupportedPropertyException)
                                {
                                    result.Code    = Result.Codes.INTERNAL_ERROR;
                                    result.Message = "Failed to set trigger control mode.";
                                }

                                if (result.Code == Result.Codes.SUCCESS)
                                {
                                    mBarcodeEventHandler = new BarcodeEventHandler(this);
                                    mAidcBarcodeReader.AddBarcodeListener(mBarcodeEventHandler);
                                }
                            }
                            else
                            {
                                result.Code    = Result.Codes.INTERNAL_ERROR;
                                result.Message = "Manager has been disposed.";
                            }
                        }
                    }
                    if (result.Code == Result.Codes.SUCCESS)
                    {
                        try
                        {
                            mAidcBarcodeReader.Claim();
                            mReaderOpened = true;

                            BarcodeReaderProfileHandler.Instance.LoadProfileOccurred += LoadProfileOccurred;
                        }
                        catch (Com.Honeywell.Aidc.ScannerUnavailableException)
                        {
                            result.Code    = Result.Codes.INTERNAL_ERROR;
                            result.Message = "Reader is not available.";
                        }
                    }
                }
                catch (Java.Lang.Exception ex)
                {
                    result.Code    = Result.Codes.EXCEPTION;
                    result.Message = ex.Message;
                }
                catch (Exception ex)
                {
                    result.Code    = Result.Codes.EXCEPTION;
                    result.Message = ex.Message;
                }
            }
            else
            {
                result.Code    = Result.Codes.READER_ALREADY_OPENED;
                result.Message = "Reader was already opened.";
            }

            return(result);
        }