Пример #1
0
        void testConnect2(BluetoothDevice btdev)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Application.DoEvents();
                if (button1.Text == "print")
                {
                    btstream = new BluetoothStream(btdev);
                    btstream.recvThreadEvent += new BluetoothStream.recvThreadEventHandler(btstream_recvThreadEvent);
                    int iTry = 3;
                    while (iTry > 0 && btstream._connected == false)
                    {
                        System.Threading.Thread.Sleep(1000);
                        iTry--;
                    }
                    if (btstream._connected)
                    {
                        if (radioFP.Checked)
                        {
                            btstream.write(Intermec.Printer.Language.Fingerprint.Demo.FP_2_WalmartLabel());
                        }
                        else if (radioIPL.Checked)
                        {
                            btstream.write(Intermec.Printer.Language.Fingerprint.Demo.IPL_2_WalmartLabel());
                        }
                        else if (radioESCP.Checked)
                        {
                            btstream.write(Intermec.Printer.Language.Fingerprint.Demo.ESCP_PRODLIST2);
                        }

                        button1.Text = "disconnect";
                    }
                    else
                    {
                        btstream.Dispose();
                    }
                }
                else if (button1.Text == "disconnect")
                {
                    btstream.recvThreadEvent -= btstream_recvThreadEvent;
                    btstream.Dispose();
                    button1.Text = "print";
                }
            }
            catch (Exception ex)
            {
                ddump("testConnect2 Exception " + ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                Application.DoEvents();
            }
        }
        [InlineData("Galaxy A70")] // Test mobile phone
        public void TestSelectDevice(string phone)
        {
            // Arrange
            var btMicro = new BluetoothStream();

            // Act
            btMicro.SelectDevice(phone);

            // Assert
            Assert.True(btMicro.GetSelectedDevice() == phone);
        }
        [InlineData("Galaxy A70")]  // Test mobile phone
        public void TestNearbyDevicesPhone(string phone)
        {
            // Arrange
            var btMicro = new BluetoothStream();

            // Act
            btMicro.UpdateNearbyDevices();
            string[] nearbyDevices = btMicro.GetNearbyDevicesNames();

            // Assert
            Assert.True(nearbyDevices.Any(x => x == phone));
        }
Пример #4
0
        public override void Update()
        {
            lock (this)
            {
                /// If a disconnection is detected for the bluetooth stream, update the status of the
                /// receiver and flush the send buffer and delete references to the bluetooth stream
                if ((this.bluetoothStream != null) && (this.bluetoothStream._Status == BluetoothStatus.Disconnected))
                {
                    this.bluetoothStream = null;
                    this.status          = ReceiverStatus.Disconnected;
                    this._SBuffer._Head  = 0;
                    this.ndisc++;
                    this.disconnectionTime = WocketsTimer.GetUnixTime();
                }

                // If the bluetooth stream is null or the receiver is not reconnecting
                // then instantiate a thread to reconnect
                if ((this.bluetoothStream == null) && (this.status != ReceiverStatus.Reconnecting))
                {
                    this.status        = ReceiverStatus.Reconnecting;
                    reconnectionThread = new Thread(new ThreadStart(this.Reconnect));
                    reconnectionThread.Start();
                    //if (CurrentWockets._Configuration._SoftwareMode == SoftwareConfiguration.DEBUG)
                    //  Logger.Debug("RFCOMMReceiver: Update: Spawning a reconnection thread for "+ this._Address);
                }

                if ((this.status != ReceiverStatus.Connected) && (this.bluetoothStream != null) && (this.bluetoothStream._Status == BluetoothStatus.Connected))
                {
                    if (this.status == ReceiverStatus.Reconnecting)
                    {
                        reconnectionThread.Join();
                        reconnectionThread.Abort();
                        reconnectionThread = null;
                    }
                    //if (CurrentWockets._Configuration._SoftwareMode == SoftwareConfiguration.DEBUG)
                    //  Logger.Debug("RFCOMMReceiver: Update: Reconnection successful for "+ this._Address);
                    this.status = ReceiverStatus.Connected;
                    if (this.disconnectionTime != 0)
                    {
                        this.disconTime += (int)((WocketsTimer.GetUnixTime() - this.disconnectionTime) / 1000);
                    }
                }
            }
        }
Пример #5
0
        public override bool Initialize()
        {
            try
            {
                this._Buffer  = new CircularBuffer(this._Buffer._Bytes.Length);
                this.head     = 0;
                this._SBuffer = new CircularBuffer(SEND_BUFFER_SIZE);

                //Always set the transmission mode on connection

                for (int i = 0; (i < this._OnConnectionCommands.Count); i++)
                {
                    Write(((Command)this._OnConnectionCommands[i])._Bytes);
                }
                this._OnConnectionCommands.Clear();

                Write(new SET_VTM(this._TMode)._Bytes);

                //if (CurrentWockets._Configuration._SoftwareMode == Wockets.Data.Configuration.SoftwareConfiguration.DEBUG)
                //  Logger.Debug("RFCOMMReceiver: Initialize: Attempting reconnection for receiver " + this._Address);
                this.bluetoothStream = NetworkStacks._BluetoothStack.Connect(this._Buffer, this._SBuffer, this.address_bytes, this.pin);
                if (this.bluetoothStream == null)
                {
                    return(false);
                }

                if (this._TMode == TransmissionMode.Bursty60)
                {
                    this.bluetoothStream._Timeout = 2;
                }
                this.bluetoothStream._TimeoutEnabled = this._TimeoutEnabled;
                this._ConnectionTime            = this.bluetoothStream._ConnectionTime;
                this._CurrentConnectionUnixTime = this.bluetoothStream._CurrentConnectionUnixTime;
                this._SuccessfulConnections++;
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #6
0
        public override bool Dispose()
        {
            try
            {
                if (this.reconnectionThread != null)
                {
                    this.reconnectionThread.Abort();
                }
            }
            catch
            {
            }
            finally
            {
                this.reconnectionThread = null;
            }

            try
            {
                if (this.bluetoothStream != null)
                {
                    this.bluetoothStream._Status = BluetoothStatus.Disconnected;
                }
            }
            catch { }
            finally
            {
                this.bluetoothStream = null;
            }
            try{
                this._Status                = ReceiverStatus.Disconnected;
                this._Reconnections         = 0;
                this._SuccessfulConnections = 0;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }