Example #1
0
            /// <summary>
            /// Opens a peripheral.
            /// </summary>
            /// <param name="peripheralName">Name of the peripheral.</param>
            /// <param name="peripheralConfig">Configuration parameters of the peripheral.</param>
            public void Open(string peripheralName, PeripheralConfiguration peripheralConfig)
            {
                if (this.oposPinpad == null)
                {
                    this.oposPinpad = new OPOSPINPadClass();

                    this.oposPinpad.DataEvent  += this.OnPinPadDataEvent;  // _IOPOSPINPadEvents_DataEventEventHandler
                    this.oposPinpad.ErrorEvent += this.OnPinPadErrorEvent; // _IOPOSPINPadEvents_ErrorEventEventHandler

                    try
                    {
                        // Open
                        Task.Run(() => this.oposPinpad.Open(peripheralName)).Wait(OposHelper.ClaimTimeOut);
                        OposHelper.CheckResultCode(this, this.oposPinpad.ResultCode);

                        // Claim
                        this.oposPinpad.ClaimDevice(OposHelper.ClaimTimeOut);
                        OposHelper.CheckResultCode(this, this.oposPinpad.ResultCode);
                    }
                    catch
                    {
                        this.Close();
                        throw;
                    }
                }
            }
Example #2
0
            /// <summary>
            /// Closes the peripheral.
            /// </summary>
            public void Close()
            {
                if (this.oposPinpad != null)
                {
                    try
                    {
                        this.oposPinpad.DataEvent  -= this.OnPinPadDataEvent;
                        this.oposPinpad.ErrorEvent -= this.OnPinPadErrorEvent;

                        this.AbortTransaction(); // Abort any pending operation.
                        this.oposPinpad.Close(); // Releases the device and its resources
                    }
                    finally
                    {
                        this.oposPinpad = null;
                    }
                }
            }