Beispiel #1
0
 public void OnConnectionCompleted(ReaderDevice p0, Throwable p1)
 {
     if (p1 != null)
     {
         MessagingCenter.Send <Page, Throwable>(App.Current.MainPage, "Exception", p1);
     }
 }
Beispiel #2
0
 private void GetAvailableReaders()
 {
     readerDevice = null;
     // SDK
     if (readers == null)
     {
         readers = new Readers(this, ENUM_TRANSPORT.ServiceSerial);
     }
     try
     {
         if (readers != null)
         {
             if (readers.AvailableRFIDReaderList != null)
             {
                 availableRFIDReaderList = readers.AvailableRFIDReaderList;
                 if (availableRFIDReaderList.Count != 0)
                 {
                     readerDevice = availableRFIDReaderList[0];
                     Reader       = readerDevice.RFIDReader;
                 }
             }
         }
     }
     catch (InvalidUsageException e)
     {
         e.PrintStackTrace();
     }
     catch (OperationFailureException e)
     {
         e.PrintStackTrace();
         Log.Debug(TAG, "OperationFailureException " + e.VendorMessage);
     }
 }
Beispiel #3
0
 public void OnSymbologyEnabled(ReaderDevice reader, ReaderDevice.Symbology symbology, Java.Lang.Boolean enabled, Throwable error)
 {
     if (Element != null)
     {
         Element.OnSymbologyEnabled(NativeToPortableSymbology(symbology), (bool)enabled, error?.LocalizedMessage);
     }
 }
Beispiel #4
0
 internal void Initialize(ContextWrapper wrapper)
 {
     _Activity = wrapper;
     this._SharedPreferences = PreferenceManager.GetDefaultSharedPreferences(wrapper);
     _ReaderDevice           = ReaderDevice.GetMXDevice(_Activity);
     this.TryConnect();
 }
Beispiel #5
0
        // ********************************************************************
        // RFID Connection Methods
        // ********************************************************************

        private void OpenRFIDConnection()
        {
            // Do this in MainActivity to test connection so we can notify user if they need to wake slep up

            if (readers == null)
            {
                readers = new Readers(this, ENUM_TRANSPORT.ServiceSerial);
            }
            ThreadPool.QueueUserWorkItem(o =>
            {
                try
                {
                    if (readers != null && readers.AvailableRFIDReaderList != null)
                    {
                        availableRFIDReaderList = readers.AvailableRFIDReaderList;
                        if (availableRFIDReaderList.Count > 0)
                        {
                            if (Reader == null)
                            {
                                // get first reader from list
                                readerDevice = availableRFIDReaderList[0];
                                Reader       = readerDevice.RFIDReader;
                                // Establish connection to the RFID Reader
                                Reader.Connect();
                                if (Reader.IsConnected)
                                {
                                    //Console.Out.WriteLine("Readers connected");
                                    serialRFD2000        = Reader.ReaderCapabilities.SerialNumber;
                                    rfidScannerConnected = true;
                                }
                            }
                            else
                            {
                                rfidScannerConnected = true;
                            }
                        }
                        else
                        {
                            rfidScannerConnected = false;
                        }
                    }
                    else
                    {
                        rfidScannerConnected = false;
                    }
                }
                catch (InvalidUsageException e)
                {
                    e.PrintStackTrace();
                }
                catch
                (OperationFailureException e)
                {
                    e.PrintStackTrace();
                    //Log.Debug(TAG, "OperationFailureException " + e.VendorMessage);
                }
            });
        }
Beispiel #6
0
        public void RegisterReadingDevice(string vendorName, string model, string version,
                                          string serialNumber, string description, IReaderModule module)
        {
            var device = new ReaderDevice(vendorName, model, version, serialNumber, description, module);

            AllJoynDsbServiceManager.Current.AddDevice(device);
            _readers.Add(device);
            module.ValueChanged += _conditionManager.ReaderModule_ValueChanged;
            Readers.Add(module);
        }
Beispiel #7
0
 public void OnAvailabilityChanged(ReaderDevice p0)
 {
     if (_ReaderDevice.GetAvailability() == Availability.Available)
     {
         this.TryConnect();
     }
     else
     {
         this.Disconnect();
     }
 }
Beispiel #8
0
 public void OnConnectionStateChanged(ReaderDevice p0)
 {
     if (p0.ConnectionState == ConnectionState.Connected)
     {
         this.TryConnect();
         //this.IsConnected = true;
     }
     else if (p0.ConnectionState == ConnectionState.Disconnected)
     {
         this.Disconnect();
         //this.IsConnected = false;
     }
 }
Beispiel #9
0
 // This is called when a MX-1xxx device has became available (USB cable was plugged, or MX device was turned on),
 // or when a MX-1xxx that was previously available has become unavailable (USB cable was unplugged, turned off due to inactivity or battery drained)
 public void OnAvailabilityChanged(ReaderDevice reader)
 {
     if (Element != null)
     {
         if (reader.GetAvailability() == Availability.Available)
         {
             Element.OnAvailabilityChanged(ScannerAvailability.Available);
         }
         else if (reader.GetAvailability() == Availability.Unavailable)
         {
             Element.OnAvailabilityChanged(ScannerAvailability.Unavailable);
         }
     }
 }
Beispiel #10
0
        protected override void Dispose(bool disposing)
        {
            if (readerDevice != null)
            {
                readerDevice.SetReaderDeviceListener(null);
                readerDevice.StopAvailabilityListening();
                availabilityListenerStarted = false;
                readerDevice.Disconnect();
                readerDevice.Dispose();
                readerDevice = null;
            }

            base.Dispose(disposing);
        }
Beispiel #11
0
 private void InitReader()
 {
     if (readers == null)
     {
         readers = new Readers(this, ENUM_TRANSPORT.ServiceSerial);
     }
     ThreadPool.QueueUserWorkItem(o =>
     {
         try
         {
             if (readers != null && readers.AvailableRFIDReaderList != null)
             {
                 availableRFIDReaderList = readers.AvailableRFIDReaderList;
                 if (availableRFIDReaderList.Count > 0)
                 {
                     if (Reader == null)
                     {
                         // get first reader from list
                         readerDevice = availableRFIDReaderList[0];
                         Reader       = readerDevice.RFIDReader;
                         // Establish connection to the RFID Reader
                         Reader.Connect();
                         if (Reader.IsConnected)
                         {
                             ConfigureReader();
                             //Console.Out.WriteLine("Readers connected");
                             rfidScannerFound = true;
                         }
                     }
                 }
             }
         }
         catch (InvalidUsageException e)
         {
             e.PrintStackTrace();
         }
         catch
         (OperationFailureException e)
         {
             e.PrintStackTrace();
             //Log.Debug(TAG, "OperationFailureException " + e.VendorMessage);
         }
     });
 }
Beispiel #12
0
        public void OnReadResultReceived(ReaderDevice p0, ReadResults p1)
        {
            try
            {
                if (p1.Count > 0)
                {
                    var result = p1.GetResultAt(0);

                    if (result.IsGoodRead)
                    {
                        MessagingCenter.Send <Page, string>(App.Current.MainPage, "GoodRead", result.ReadString);
                        MessagingCenter.Send <Page, MemoryStream>(App.Current.MainPage, "ImageReceived", this.ConvertBitmapToStream(result.Image));
                    }
                }
            }
            catch (Exception ex)
            {
                MessagingCenter.Send <Page, Throwable>(App.Current.MainPage, "Exception", ex);
            }
        }
Beispiel #13
0
        // This is called after scanning has completed, either by detecting a barcode, canceling the scan by using the on-screen button or a hardware trigger button, or if the scanning timed-out
        public void OnReadResultReceived(ReaderDevice reader, ReadResults results)
        {
            if (Element != null)
            {
                List <ScannedResult> resList = new List <ScannedResult>();

                if (results.SubResults != null && results.SubResults.Count > 0)
                {
                    foreach (ReadResult subResult in results.SubResults)
                    {
                        resList.Add(CreateResultItem(subResult));
                    }
                }
                else if (results.Count > 0)
                {
                    resList.Add(CreateResultItem(results.GetResultAt(0)));
                }

                Element.OnResultReceived(resList);
            }
        }
Beispiel #14
0
 // This is called when a connection with the readerDevice has been changed.
 // The readerDevice is usable only in the "ConnectionState.Connected" state
 public void OnConnectionStateChanged(ReaderDevice reader)
 {
     if (Element != null)
     {
         if (reader.ConnectionState == ConnectionState.Connected)
         {
             Element.OnConnectionStateChanged(ScannerConnectionStatus.Connected);
         }
         else if (reader.ConnectionState == ConnectionState.Connecting)
         {
             Element.OnConnectionStateChanged(ScannerConnectionStatus.Connecting);
         }
         else if (reader.ConnectionState == ConnectionState.Disconnected)
         {
             Element.OnConnectionStateChanged(ScannerConnectionStatus.Disconnected);
         }
         else if (reader.ConnectionState == ConnectionState.Disconnecting)
         {
             Element.OnConnectionStateChanged(ScannerConnectionStatus.Disconnecting);
         }
     }
 }
Beispiel #15
0
 // The connect method has completed, here you can see whether there was an error with establishing the connection or not
 public void OnConnectionCompleted(ReaderDevice reader, Throwable error)
 {
     if (Element != null)
     {
         // If we have valid connection error param will be null,
         // otherwise here is error that inform us about issue that we have while connecting to reader device
         if (error != null)
         {
             // ask for Camera Permission if necessary
             if (error is CameraPermissionException)
             {
                 Element.OnConnectionCompleted(ScannerExceptions.CameraPermissionException, error.LocalizedMessage);
             }
             else
             {
                 Element.OnConnectionCompleted(ScannerExceptions.Other, error.LocalizedMessage);
             }
         }
         else
         {
             Element.OnConnectionCompleted(ScannerExceptions.NoException, null);
         }
     }
 }
Beispiel #16
0
        private void OpenRFIDConnection2()
        {
            Message msg = new Message();

            cHandler = new ConnectionHandler(this);
            msg      = cHandler.ObtainMessage();

            // Display progress bar

            ProgressDialog progBar = new ProgressDialog(this);

            progBar.SetCancelable(false);
            progBar.SetTitle("Connecting to RFID reader");
            progBar.SetIcon(Resource.Drawable.iconChill64);
            progBar.SetMessage("One moment please...");
            progBar.SetProgressStyle(ProgressDialogStyle.Spinner);
            progBar.Show();

            if (readers == null)
            {
                readers = new Readers(this, ENUM_TRANSPORT.ServiceSerial);
            }

            var thread = new System.Threading.Thread(new ThreadStart(delegate
            {
                try
                {
                    if (readers != null && readers.AvailableRFIDReaderList != null)
                    {
                        availableRFIDReaderList = readers.AvailableRFIDReaderList;
                        if (availableRFIDReaderList.Count > 0)
                        {
                            if (Reader == null)
                            {
                                // get first reader from list
                                readerDevice = availableRFIDReaderList[0];
                                Reader       = readerDevice.RFIDReader;
                                // Establish connection to the RFID Reader
                                Reader.Connect();
                                if (Reader.IsConnected)
                                {
                                    ConfigureReader();
                                    //Console.Out.WriteLine("Readers connected");
                                    //serialRFD2000 = Reader.ReaderCapabilities.SerialNumber;
                                    rfidScannerConnected = true;
                                    msg.Arg1             = 0;
                                }
                            }
                            else
                            {
                                rfidScannerConnected = true;
                                msg.Arg1             = 0;
                            }
                        }
                        else
                        {
                            rfidScannerConnected = false;
                            msg.Arg1             = 1;
                        }
                    }
                    else
                    {
                        rfidScannerConnected = false;
                        msg.Arg1             = 1;
                    }
                }
                catch (InvalidUsageException e)
                {
                    e.PrintStackTrace();
                    msg.Arg1 = 1;
                }
                catch
                (OperationFailureException e)
                {
                    e.PrintStackTrace();
                    msg.Arg1 = 1;
                    //Log.Debug(TAG, "OperationFailureException " + e.VendorMessage);
                }
                RunOnUiThread(() =>
                {
                    progBar.Dismiss();
                });
                cHandler.SendMessage(msg);
            }));

            thread.Start();
        }
Beispiel #17
0
        protected override void OnElementChanged(ElementChangedEventArgs <ShoppingCart.ScannerControl> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            rlMainContainer = new RelativeLayout(Context)
            {
                LayoutParameters = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.MatchParent)
            };

            if (Control == null)
            {
                SetNativeControl(rlMainContainer);
            }

            //Implement element event handlers. We will invoke them from portable project
            Element.OnDisconnect += (object sender, EventArgs args) =>
            {
                // stop listening to device availability to avoid resource leaks
                if (readerDevice != null)
                {
                    if (availabilityListenerStarted)
                    {
                        readerDevice.StopAvailabilityListening();
                        availabilityListenerStarted = false;
                    }

                    readerDevice.Disconnect();
                }
            };
            Element.OnConnect += (object sender, EventArgs args) =>
            {
                if (readerDevice != null &&
                    readerDevice.ConnectionState != ConnectionState.Connecting &&
                    readerDevice.ConnectionState != ConnectionState.Connected)
                {
                    //Listen when a MX device has became available/unavailable
                    if (readerDevice.DeviceClass == DataManDeviceClass.Mx && !availabilityListenerStarted)
                    {
                        readerDevice.StartAvailabilityListening();
                        availabilityListenerStarted = true;
                    }

                    readerDevice.Connect(this);
                }
            };
            Element.OnStopScanning += (object sender, EventArgs args) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == ConnectionState.Connected)
                {
                    readerDevice.StopScanning();
                }
            };
            Element.OnStartScanning += (object sender, EventArgs args) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == ConnectionState.Connected)
                {
                    readerDevice.StartScanning();
                }
            };
            Element.OnGetPhoneCameraDevice += (object sender, object[] args) =>
            {
                if (readerDevice != null)
                {
                    readerDevice.SetReaderDeviceListener(null);

                    if (availabilityListenerStarted)
                    {
                        readerDevice.StopAvailabilityListening();

                        availabilityListenerStarted = false;
                    }

                    readerDevice.Disconnect();
                    readerDevice.Dispose();
                    readerDevice = null;
                }

                if (args.Length > 3)
                {
                    readerDevice = GetPhoneCameraDevice(Context, (int)args[0], (int)args[1], ((bool)args[2]) ? null : Control, args[3].ToString());
                }
                else
                {
                    readerDevice = GetPhoneCameraDevice(Context, (int)args[0], (int)args[1], ((bool)args[2]) ? null : Control);
                }

                // set listeners and connect to device
                readerDevice.SetReaderDeviceListener(this);
            };
            Element.OnGetMXDevice += (object sender, EventArgs args) =>
            {
                if (readerDevice != null)
                {
                    readerDevice.SetReaderDeviceListener(null);

                    if (availabilityListenerStarted)
                    {
                        readerDevice.StopAvailabilityListening();

                        availabilityListenerStarted = false;
                    }

                    readerDevice.Disconnect();
                    readerDevice.Dispose();
                    readerDevice = null;
                }

                readerDevice = GetMXDevice(Context);

                //Listen when a MX device has became available/unavailable
                if (!availabilityListenerStarted)
                {
                    readerDevice.StartAvailabilityListening();
                    availabilityListenerStarted = true;
                }

                // set listeners and connect to device
                readerDevice.SetReaderDeviceListener(this);
            };
            Element.OnSdkVersion += (object sender, EventArgs args) =>
            {
                if (Element != null)
                {
                    Element.OnGetSdkVersion(DataManSystem.Version);
                }
            };
            Element.OnSetSymbologyEnabled += (object sender, object[] args) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == ConnectionState.Connected)
                {
                    readerDevice.SetSymbologyEnabled(PortableToNativeSymbology((Symbology)args[0]), (bool)args[1], this);
                }
            };
            Element.OnEnableImage += (object sender, bool enable) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == ConnectionState.Connected)
                {
                    readerDevice.EnableImage(enable);
                }
            };
            Element.OnEnableImageGraphics += (object sender, bool enable) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == ConnectionState.Connected)
                {
                    readerDevice.EnableImageGraphics(enable);
                }
            };
            Element.OnSendCommand += (object sender, string dmcc) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == ConnectionState.Connected)
                {
                    readerDevice.DataManSystem.SendCommand(dmcc, this);
                }
            };
            Element.OnSetParser += (object sender, ScannerParser parserType) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == ConnectionState.Connected)
                {
                    readerDevice.Parser = PortableToNativeParser(parserType);
                }
            };
        }