Exemplo n.º 1
0
 public void AvailabilityDidChangeOfReader(CMBReaderDevice reader)
 {
     if (Element != null)
     {
         if (reader.Availability == CMBReaderAvailibility.Available)
         {
             Element.OnAvailabilityChanged(ScannerAvailability.Available);
         }
         else if (reader.Availability == CMBReaderAvailibility.Unavailable)
         {
             Element.OnAvailabilityChanged(ScannerAvailability.Unavailable);
         }
     }
 }
Exemplo n.º 2
0
        protected override void Dispose(bool disposing)
        {
            if (didBecomeActiveObserver != null)
            {
                NSNotificationCenter.DefaultCenter.RemoveObserver(didBecomeActiveObserver);
                didBecomeActiveObserver.Dispose();
                didBecomeActiveObserver = null;
            }

            if (readerDevice != null)
            {
                readerDevice.WeakDelegate = null;
                readerDevice.Disconnect();
                readerDevice.Dispose();
                readerDevice = null;
            }

            base.Dispose(disposing);
        }
Exemplo n.º 3
0
        public void DidReceiveReadResultFromReader(CMBReaderDevice reader, CMBReadResults readResults)
        {
            if (Element != null)
            {
                List <ScannedResult> resList = new List <ScannedResult>();

                if (readResults.SubReadResults != null && readResults.SubReadResults.Length > 0)
                {
                    foreach (CMBReadResult subResult in readResults.SubReadResults)
                    {
                        resList.Add(CreateResultItem(subResult));
                    }
                }
                else if (readResults.ReadResults.Length > 0)
                {
                    resList.Add(CreateResultItem((CMBReadResult)readResults.ReadResults[0]));
                }

                Element.OnResultReceived(resList);
            }
        }
Exemplo n.º 4
0
        public void ConnectionStateDidChangeOfReader(CMBReaderDevice reader)
        {
            if (Element != null)
            {
                if (reader.ConnectionState == CMBConnectionState.Connected)
                {
                    if (connectingAlert != null)
                    {
                        connectingAlert.DismissViewController(true, () =>
                        {
                            connectingAlert = null;
                        });
                    }

                    Element.OnConnectionStateChanged(ScannerConnectionStatus.Connected);
                }
                else if (reader.ConnectionState == CMBConnectionState.Connecting)
                {
                    Element.OnConnectionStateChanged(ScannerConnectionStatus.Connecting);
                }
                else if (reader.ConnectionState == CMBConnectionState.Disconnected)
                {
                    if (connectingAlert != null)
                    {
                        connectingAlert.DismissViewController(true, () =>
                        {
                            connectingAlert = null;
                        });
                    }

                    Element.OnConnectionStateChanged(ScannerConnectionStatus.Disconnected);
                }
                else if (reader.ConnectionState == CMBConnectionState.Disconnecting)
                {
                    Element.OnConnectionStateChanged(ScannerConnectionStatus.Disconnecting);
                }
            }
        }
Exemplo n.º 5
0
        protected override void OnElementChanged(ElementChangedEventArgs <ShoppingCart.ScannerControl> e)
        {
            base.OnElementChanged(e);

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

            container = new UIView();

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

            //Implement element event handlers. We will invoke them from portable project
            Element.OnDisconnect += (object sender, EventArgs args) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == CMBConnectionState.Connected)
                {
                    readerDevice.Disconnect();
                }
            };
            Element.OnConnect += (object sender, EventArgs args) =>
            {
                ConnectToReaderDevice();
            };
            Element.OnStopScanning += (object sender, EventArgs args) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == CMBConnectionState.Connected)
                {
                    readerDevice.StopScanning();
                }
            };
            Element.OnStartScanning += (object sender, EventArgs args) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == CMBConnectionState.Connected)
                {
                    readerDevice.StartScanning();
                }
            };
            Element.OnGetPhoneCameraDevice += (object sender, object[] args) =>
            {
                if (readerDevice != null)
                {
                    readerDevice.WeakDelegate = null;
                    readerDevice.Disconnect();
                    readerDevice.Dispose();
                    readerDevice = null;
                }

                cameraMode = (CDMCameraMode)(int)args[0];

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

                readerDevice.WeakDelegate = this;
            };
            Element.OnGetMXDevice += (object sender, EventArgs args) =>
            {
                if (readerDevice != null)
                {
                    readerDevice.WeakDelegate = null;
                    readerDevice.Disconnect();
                    readerDevice.Dispose();
                    readerDevice = null;
                }

                readerDevice = CMBReaderDevice.ReaderOfMXDevice();

                readerDevice.WeakDelegate = this;
            };
            Element.OnSdkVersion += (object sender, EventArgs args) =>
            {
                if (Element != null)
                {
                    Element.OnGetSdkVersion(CDMDataManSystem.Version);
                }
            };
            Element.OnSetSymbologyEnabled += (object sender, object[] args) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == CMBConnectionState.Connected)
                {
                    readerDevice.SetSymbology(PortableToNativeSymbology((Symbology)args[0]), (bool)args[1], (error) =>
                    {
                        if (Element != null)
                        {
                            Element.OnSymbologyEnabled((Symbology)args[0], (bool)args[1], error?.LocalizedDescription);
                        }
                    });
                }
            };
            Element.OnEnableImage += (object sender, bool enable) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == CMBConnectionState.Connected)
                {
                    readerDevice.ImageResultEnabled = enable;
                }
            };
            Element.OnEnableImageGraphics += (object sender, bool enable) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == CMBConnectionState.Connected)
                {
                    readerDevice.SVGResultEnabled = enable;
                }
            };
            Element.OnSendCommand += (object sender, string dmcc) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == CMBConnectionState.Connected)
                {
                    readerDevice.DataManSystem.SendCommand(dmcc, (response) =>
                    {
                        if (Element != null)
                        {
                            Element.OnResponseReceived(response.Payload, (response.Status != CDMResponseStatus.DMCC_STATUS_NO_ERROR ? response.Status.ToString() : null));
                        }
                    });
                }
            };
            Element.OnSetParser += (object sender, ScannerParser parserType) =>
            {
                if (readerDevice != null && readerDevice.ConnectionState == CMBConnectionState.Connected)
                {
                    readerDevice.Parser = (CMBResultParser)(int)parserType;
                }
            };

            didBecomeActiveObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidBecomeActiveNotification, (ntf) =>
            {
                ConnectToReaderDevice();
            });
        }