Beispiel #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            btnSearch.Enabled = false;

            Thread thread = new Thread(unused =>
            {
                PenDevice[] devices = mBtAdt.FindAllDevices();

                this.BeginInvoke(new MethodInvoker(delegate()
                {
                    lbDevices.Items.Clear();

                    if (devices == null || devices.Length <= 0)
                    {
                        MessageBox.Show("device is not exists");
                    }
                    else
                    {
                        lbDevices.Items.AddRange(devices);
                    }

                    btnSearch.Enabled = true;
                }));
            });

            thread.IsBackground = true;
            thread.Start();
        }
Beispiel #2
0
        public void connectPen()
        {
            //mSig = new Signature();
            mBtAdt = new BluetoothAdapter();
            Thread thread = new Thread(unused =>
            {
                PenDevice[] devices = mBtAdt.FindAllDevices();
                Debug.WriteLine("Pens discovered " + devices.Length);

                if (devices.Length > 0)
                {
                    int deviceNumber = 0;
                    foreach (PenDevice p in devices)
                    {
                        Debug.WriteLine("[" + deviceNumber + "]"
                                        + "\t Name:" + p.Name
                                        + "\t Address:" + p.Address
                                        + "\t Authenticated:" + p.Authenticated
                                        + "\t ClassOfDevice:" + p.ClassOfDevice
                                        + "\t LastSeen:" + p.LastSeen
                                        + "\t LastUsed:" + p.LastUsed
                                        + "\t Remembered:" + p.Remembered
                                        + "\t Rssi:" + p.Rssi
                                        );
                    }

                    Debug.WriteLine("Connecting to pen...");
                    //mPenCommV1 = new PenCommV1(new PenConnector(_hostingEnvironment));
                    mPenCommV1 = new PenCommV1(this);


                    bool result = mBtAdt.Connect(devices.ElementAt(0).Address, delegate(uint deviceClass)
                    {
                        if (deviceClass == mPenCommV1.DeviceClass)
                        {
                            mBtAdt.Bind(mPenCommV1);

                            // You can set the name of PenComm object in the following ways
                            // If you don't set the name of the PenComm, it is automatically set to the address of a connected pen.

                            //mBtAdt.Bind(mPenCommV1, "name of PenComm");

                            // You can get or set a name of PenComm
                            // mBtAdt.Name = "name of PenComm";
                        }
                    });
                }
                else
                {
                    Debug.WriteLine("Pen Not Found...");
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }
Beispiel #3
0
 public PenDevice[] FindAllDevices()
 {
     return(mBtAdapter.FindAllDevices());
 }
Beispiel #4
0
        public void TestFindAllDevices()
        {
            var results = _btAdt.FindAllDevices();

            Assert.IsTrue(results != null && results.Length > 0);
        }