Beispiel #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (btnConnect.Text == "Connect")
            {
                if (txtMacAddress.Text == "")
                {
                    MessageBox.Show("Select Mac Address of Pen!!");
                    return;
                }

                btnConnect.Enabled = false;

                Thread thread = new Thread(unused =>
                {
                    // Binds a socket created by connecting with pen through Bluetooth interface according to Device Class
                    bool result = mBtAdt.Connect(txtMacAddress.Text, delegate(uint deviceClass)
                    {
                        // Binding when Device Class is F110
                        if (deviceClass == mPenCommV1.DeviceClass)
                        {
                            mBtAdt.Bind(mPenCommV1);
                        }
                        // Binding if Device Class is not F110
                        else if (deviceClass == mPenCommV2.DeviceClass)
                        {
                            mBtAdt.Bind(mPenCommV2);
                        }
                    });

                    if (!result)
                    {
                        MessageBox.Show("Fail to connect");

                        this.BeginInvoke(new MethodInvoker(delegate()
                        {
                            btnConnect.Enabled = true;
                        }));
                    }
                });

                thread.IsBackground = true;
                thread.Start();
            }
            else
            {
                if (!mBtAdt.Disconnect())
                {
                    btnConnect.Text    = "Connect";
                    btnConnect.Enabled = true;
                }
            }
        }
Beispiel #2
0
 public bool ConnectAndBind()
 {
     return(_btAdt.Connect(MAC, delegate(uint deviceClass)
     {
         _btAdt.Bind(_penComm);
     }));
 }
        public void SetUp()
        {
            _btAdt = new BluetoothAdapter();

            _callbackObj = new PenCommV1CallbacksImpl();

            _callbackObj.Authenticated = delegate(object sender, object[] args)
            {
                _autoResetEvent.Set();
            };

            _callbackObj.PasswordRequest = delegate(object sender, object[] args)
            {
                _penComm.ReqInputPassword(PASSWORD);
            };

            _penComm = new PenCommV1(_callbackObj);

            bool result = _btAdt.Connect(MAC, delegate(uint deviceClass)
            {
                _btAdt.Bind(_penComm);
            });

            if (!result)
            {
                Assert.Fail("connection failed");
                return;
            }

            _autoResetEvent.WaitOne();
        }
Beispiel #4
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 #5
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (txtMacAddress.Text == "")
            {
                MessageBox.Show("Select Mac Address of Pen!!");
                return;
            }

            btnConnect.Enabled = false;

            Thread thread = new Thread(unused =>
            {
                // 블루투스 인터페이스로 펜과 연결하여 생성한 소켓을 Device class에 따라 바인딩
                bool result = mBtAdt.Connect(txtMacAddress.Text, delegate(uint deviceClass)
                {
                    // device class가 f110 일 경우에 바인딩
                    if (deviceClass == mPenCommV1.DeviceClass)
                    {
                        mBtAdt.Bind(mPenCommV1);
                    }
                    // device class가 f50 일 경우에 바인딩
                    else if (deviceClass == mPenCommV2.DeviceClass)
                    {
                        mBtAdt.Bind(mPenCommV2);
                    }
                });

                if (!result)
                {
                    MessageBox.Show("Fail to connect");

                    this.BeginInvoke(new MethodInvoker(delegate()
                    {
                        btnConnect.Enabled = true;
                    }));
                }
            });

            thread.IsBackground = true;
            thread.Start();

            lbHistory.Items.Add(txtMacAddress.Text);
        }
Beispiel #6
0
        /// <summary>
        /// Attempt to connect to a pen device.
        /// This method will block until a connection is made or the connection fails.
        /// If you do not want block UI thread, you have to invoke method in another thread.
        /// </summary>
        /// <param name="btAddr">MAC address of pen</param>
        /// <returns>true if connection is made, otherwise false.</returns>
        public bool Connect(string btAddr)
        {
            return(mBtAdapter.Connect(btAddr, delegate(uint deviceClass)
            {
                mCommV1 = new PenCommV1(mCallbackV1);
                mCommV2 = new PenCommV2(mCallbackV2);

                if (deviceClass == 0x0500)
                {
                    IsV1Comm = true;
                    System.Console.WriteLine("bind socket with v1 {0}", deviceClass);
                    mBtAdapter.Bind(mCommV1);
                }
                else if (deviceClass == 0x2510)
                {
                    IsV1Comm = false;
                    System.Console.WriteLine("bind socket with v2 {0}", deviceClass);
                    mBtAdapter.Bind(mCommV2);
                }
            }));
        }
        public void TestInputPassword()
        {
            bool result = false;

            _callbackObj.PasswordChanged = delegate(object sender, object[] args)
            {
                _btAdt.Disconnect();
                _autoResetEvent.Set();
            };

            _callbackObj.Authenticated = delegate(object sender, object[] args)
            {
                result = true;
                _autoResetEvent.Set();
            };

            _callbackObj.PasswordRequest = delegate(object sender, object[] args)
            {
                _penComm.ReqInputPassword(PASSWORD);
            };

            Task.Factory.StartNew(() =>
            {
                //1234로 비밀번호 변경
                _penComm.ReqSetUpPassword("", PASSWORD);
            });

            _autoResetEvent.WaitOne();

            bool connResult = _btAdt.Connect(MAC, delegate(uint deviceClass)
            {
                _btAdt.Bind(_penComm);
            });

            _autoResetEvent.WaitOne();

            Assert.IsTrue(result && connResult);
        }