Beispiel #1
0
 void OnScanEnded(LinkedList <BluetoothDevice> devices)
 {
     if (bluetoothHelper.isDevicePaired()) //we did found our device (with BLE) or we already paired the device (for Bluetooth Classic)
     {
         bluetoothHelper.Connect();
     }
     else
     {
         bluetoothHelper.ScanNearbyDevices(); //we didn't
     }
 }
Beispiel #2
0
    private void OnScanEnded(BluetoothHelper helper, LinkedList <BluetoothDevice> devices)
    {
        Debug.Log("FOund " + devices.Count);
        if (devices.Count == 0)
        {
            bluetoothHelper.ScanNearbyDevices();
            return;
        }

        foreach (var d in devices)
        {
            Debug.Log(d.DeviceName);
        }

        try
        {
            bluetoothHelper.setDeviceName("HC-08");
            bluetoothHelper.Connect();
            Debug.Log("Connecting");
        }catch (Exception ex)
        {
            bluetoothHelper.ScanNearbyDevices();
            Debug.Log(ex.Message);
        }
    }
Beispiel #3
0
    void OnGUI()
    {
        if (BTHelper == null)
        {
            return;
        }


        BTHelper.DrawGUI();

        if (!BTHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect"))
            {
                if (BTHelper.isDevicePaired())
                {
                    BTHelper.Connect();              // tries to connect
                }
            }
        }

        if (BTHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect"))
            {
                BTHelper.Disconnect();
            }
        }
    }
 public void Connect()
 {
     if (m_Helper != null)
     {
         m_Helper.Connect();
     }
 }
Beispiel #5
0
    private void draw()
    {
        LinkedListNode <BluetoothDevice> node = devices.First;

        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                string bluetoothName = node.Value.DeviceName;
                if (GUI.Button(new Rect((j + 1) * Screen.width / 5 + 5, (i + 2) * Screen.height / 10 + 5, Screen.width / 5 - 10, Screen.height / 10 - 10), bluetoothName))
                {
                    helper.setDeviceName(bluetoothName);
                    try
                    {
                        helper.Connect();
                        isConnecting = true;
                    }
                    catch (Exception)
                    {
                        isConnecting = false;
                    }
                }
                node = node.Next;
                if (node == null)
                {
                    return;
                }
            }
        }
    }
Beispiel #6
0
    // Start is called before the first frame update
    void Start()
    {
        deviceName = "BikeSpeed";

        try
        {
            BTHelper                     = BluetoothHelper.GetInstance(deviceName);
            BTHelper.OnConnected        += OnConnected;
            BTHelper.OnConnectionFailed += OnConnFailed;

            BTHelper.setTerminatorBasedStream("\n");
            //BTHelper.setLengthBasedStream();

            //if we have already paired with the device
            if (BTHelper.isDevicePaired())
            {
                BTHelper.Connect(); //we manage to connect successfully
            }
        }
        catch (BluetoothHelper.BlueToothNotEnabledException ex)
        {
        }
        catch (BluetoothHelper.BlueToothNotReadyException ex)
        {
        }
        catch (BluetoothHelper.BlueToothNotSupportedException ex)
        {
        }
    }
Beispiel #7
0
    void Start()
    {
        deviceName = "HC-05"; //bluetooth should be turned ON;
        try
        {
            BluetoothHelper.BLE                 = false;
            bluetoothHelper                     = BluetoothHelper.GetInstance(deviceName);
            bluetoothHelper.OnConnected        += OnConnected;
            bluetoothHelper.OnConnectionFailed += OnConnectionFailed;
            bluetoothHelper.OnDataReceived     += OnMessageReceived; //read the data
            bluetoothHelper.OnScanEnded        += OnScanEnded;

            bluetoothHelper.setTerminatorBasedStream("\n");

            if (!bluetoothHelper.ScanNearbyDevices())
            {
                //scan didnt start (on windows desktop (not UWP))
                //try to connect
                bluetoothHelper.Connect();//this will work only for bluetooth classic.
                //scanning is mandatory before connecting for BLE.
            }
        }
        catch (Exception ex)
        {
            Debug.Log(ex.Message);
            write(ex.Message);
        }
    }
Beispiel #8
0
    void OnScanEnded(LinkedList <BluetoothDevice> nearbyDevices)
    {
        Debug.Log("1 ended");

        if (nearbyDevices.Count == 0)
        {
            bluetoothHelper.ScanNearbyDevices();
            return;
        }


        foreach (BluetoothDevice device in nearbyDevices)
        {
            if (device.DeviceName == "HC-08")
            {
                Debug.Log("FOUND!!");
            }
        }

        text.text = "HC-08";
        bluetoothHelper.setDeviceName("HC-08");
        // bluetoothHelper.setDeviceAddress("00:21:13:02:16:B1");
        bluetoothHelper.Connect();
        bluetoothHelper.isDevicePaired();
    }
Beispiel #9
0
    /// <summary>
    /// //////////////////////Start ////////////////////////////////////
    /// </summary>

    void Start()
    {
        deviceName = "Park"; //블루투스 모듈이 깜박이는 상태일 것
        try
        {
            BluetoothHelper.BLE                 = true;
            bluetoothHelper                     = BluetoothHelper.GetInstance(deviceName);
            bluetoothHelper.OnConnected        += OnConnected;
            bluetoothHelper.OnConnectionFailed += OnConnectionFailed;
            bluetoothHelper.OnDataReceived     += OnMessageReceived; //read the data
            bluetoothHelper.OnScanEnded        += OnScanEnded;

            bluetoothHelper.setTerminatorBasedStream("\n");

            if (!bluetoothHelper.ScanNearbyDevices())
            {
                //scan didnt start (on windows desktop (not UWP))
                //try to connect
                bluetoothHelper.Connect();//this will work only for bluetooth classic.
                //scanning is mandatory before connecting for BLE.
            }
        }
        catch (Exception ex)
        {
            Debug.Log(ex.Message);
            LogWrite(ex.Message);
        }

        LogWrite("자동 연결중...");
    }
Beispiel #10
0
    //Call this function to emulate message receiving from bluetooth while debugging on your PC.
    void OnGUI()
    {
        if (bluetoothHelper != null)
        {
            bluetoothHelper.DrawGUI();
        }
        else
        {
            return;
        }

        if (!bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(0, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect"))
            {
                if (bluetoothHelper.isDevicePaired())
                {
                    bluetoothHelper.Connect(); // tries to connect
                }
            }
        }

        //if (bluetoothHelper.isConnected())
        //    if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "SetActive"))
        //    {
        //        Camera.SetActive(true);
        //    }
    }
Beispiel #11
0
 public void button()
 {
     if (!bluetoothHelper.isConnected())
     {
         if (bluetoothHelper.isDevicePaired())
         {
             bluetoothHelper.Connect(); // tries to connect
         }
     }
 }
Beispiel #12
0
 public void connectButtonClick()
 {
     if (bluetoothHelper.isDevicePaired())
     {
         bluetoothHelper.Connect(); // tries to connect
     }
     else
     {
         LogWrite("Cannot connect, device is not found, for bluetooth classic, pair the device\n\tFor BLE scan for nearby devices");
     }
 }
Beispiel #13
0
 void ConnectBT()
 {
     if (!bluetoothHelper.isConnected())
     {
         Middletext.text = "Disconnected";
         if (bluetoothHelper.isDevicePaired())
         {
             bluetoothHelper.Connect(); // tries to connect
         }
     }
 }
 void OnScanEnded(LinkedList <BluetoothDevice> nearbyDevices)
 {
     text.text = "Found " + nearbyDevices.Count + " devices";
     if (nearbyDevices.Count == 0)
     {
         return;
     }
     text.text = nearbyDevices.First.Value.DeviceName;
     bluetoothHelper.setDeviceName(nearbyDevices.First.Value.DeviceName);
     // bluetoothHelper.setDeviceAddress("00:21:13:02:16:B1");
     bluetoothHelper.Connect();
 }
Beispiel #15
0
    private void TryToConnect()
    {
        // Get saved changes, or the default value
        deviceName = PlayerPrefs.GetString("DeviceName", deviceName);

        debbugerMsg.text  = "Device name: " + deviceName + "; ";
        debbugerMsg.text += "Looking for a connection: " + connectBT + "; ";

        if (connectBT == true)
        {
            try
            {
                helper = BluetoothHelper.GetInstance(deviceName);

                helper.OnConnected        += OnConnected;
                helper.OnConnectionFailed += OnConnFailed;

                helper.setTerminatorBasedStream("\n");

                if (helper.isDevicePaired()) // old isDeviceFound
                {
                    helper.Connect();
                }

                debbugerMsg.text += "Bluetooth connected: yes!";
            }
            catch (BluetoothHelper.BlueToothNotEnabledException ex)
            {
                Debug.LogError("Excetion founded in Btmagaer: " + ex);
                exT.text         += " " + ex;
                debbugerMsg.text += "Bluetooth connected: No!";
            }
            catch (BluetoothHelper.BlueToothNotReadyException ex)
            {
                Debug.LogError("Excetion founded in Btmagaer: " + ex);
                exT.text         += " " + ex;
                debbugerMsg.text += "Bluetooth connected: No!";
            }
            catch (BluetoothHelper.BlueToothNotSupportedException ex)
            {
                Debug.LogError("Excetion founded in Btmagaer: " + ex);
                exT.text         += " " + ex;
                debbugerMsg.text += "Bluetooth connected: No!";
            }
            catch (BluetoothHelper.BlueToothPermissionNotGrantedException ex)
            {
                Debug.LogError("Excetion founded in Btmagaer: " + ex);
                exT.text         += " " + ex;
                debbugerMsg.text += "Bluetooth connected: No!";
            }
        }
    }
Beispiel #16
0
    //Call this function to emulate message receiving from bluetooth while debugging on your PC.
    void OnGUI()
    {
        tmp = GUI.TextField(new Rect(Screen.width / 4, Screen.height / 10, Screen.width / 2, Screen.height / 10 - 10), tmp);

        if (bluetoothHelper != null)
        {
            bluetoothHelper.DrawGUI();
        }
        else
        {
            return;
        }

        if (!bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect"))
            {
                if (bluetoothHelper.isDevicePaired())
                {
                    bluetoothHelper.Connect(); // tries to connect
                }
                else
                {
                    write("Cannot connect, device is not found, for bluetooth classic, pair the device\n\tFor BLE scan for nearby devices");
                }
            }
        }

        if (bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect"))
            {
                bluetoothHelper.Disconnect();
                write("Disconnected");
            }

            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Turn On"))
            {
                bluetoothHelper.SendData("O");
                write("Sending O");
            }

            if (GUI.Button(new Rect(Screen.width / 2 + Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Turn Off"))
            {
                bluetoothHelper.SendData("F");
                write("Sending F");
            }
        }
    }
Beispiel #17
0
    void Start()
    {
        try
        {
            BluetoothHelper.BLE                 = true; //use Bluetooth Low Energy Technology
            bluetoothHelper                     = BluetoothHelper.GetInstance();
            bluetoothHelper.OnConnected        += OnConnected;
            bluetoothHelper.OnConnectionFailed += OnConnectionFailed;
            bluetoothHelper.OnDataReceived     += OnMessageReceived; //read the data
            bluetoothHelper.OnScanEnded        += OnScanEnded;

            //FOR CUSTOM UUID with BLE
            //BluetoothHelperCharacteristic characteristic = new BluetoothHelperCharacteristic("beb5483e-36e1-4688-b7f5-ea07361b26a8");
            //characteristic.setService("4fafc201-1fb5-459e-8fcc-c5c9c331914b");
            //bluetoothHelper.setTxCharacteristic(characteristic);
            //bluetoothHelper.setRxCharacteristic(characteristic);

            bluetoothHelper.setTerminatorBasedStream("\n");
            //bluetoothHelper.setLengthBasedStream();
            //bluetoothHelper.setFixedLengthBasedStream(10);

            // if(bluetoothHelper.isDevicePaired())
            //  sphere.GetComponent<Renderer>().material.color = Color.blue;
            // else
            //  sphere.GetComponent<Renderer>().material.color = Color.grey;
            // bluetoothHelper.ScanNearbyDevices();
            if (!bluetoothHelper.ScanNearbyDevices())
            {
                //text.text = "cannot start scan";
                sphere.GetComponent <Renderer>().material.color = Color.black;

                // bluetoothHelper.setDeviceAddress("00:21:13:02:16:B1");
                bluetoothHelper.setDeviceName(deviceName);
                bluetoothHelper.Connect();
            }
            else
            {
                text.text = "start scan";
                // sphere.GetComponent<Renderer>().material.color = Color.green;
            }
        }
        catch (BluetoothHelper.BlueToothNotEnabledException ex)
        {
            sphere.GetComponent <Renderer>().material.color = Color.yellow;
            Debug.Log(ex.ToString());
            text.text = ex.Message;
        }
    }
 private void OnScanEnded(LinkedList <BluetoothDevice> devices)
 {
     Debug.Log("FOund " + devices.Count);
     if (devices.Count == 0)
     {
         return;
     }
     try
     {
         bluetoothHelper.setDeviceName("HC-08");
         bluetoothHelper.Connect();
         Debug.Log("Connecting");
     }catch (Exception ex)
     {
         Debug.Log(ex.Message);
     }
 }
    void Start()
    {
        Btn_Connect.onClick.AddListener(() => {
            if (bluetoothHelper.isDevicePaired())
            {
                Debug.Log("try to connect");
                bluetoothHelper.Connect();                  // tries to connect
            }
            else
            {
                Debug.Log("not DevicePaired");
            }
        });
        Btn_Disconnect.onClick.AddListener(() => {
            //bluetoothHelper.Disconnect ();
            Score.score++;
            Debug.Log("try to Disconnect");
        });
        //=============================================================================================
        //=============================================================================================

        deviceName = "cgproj1234";         //bluetooth should be turned ON; // 페어링되는 아두이노 블루투스 이름과 같아야 합니다.

        //=============================================================================================
        //=============================================================================================
        try {
            bluetoothHelper                     = BluetoothHelper.GetInstance(deviceName);
            bluetoothHelper.OnConnected        += OnConnected;
            bluetoothHelper.OnConnectionFailed += OnConnectionFailed;
            bluetoothHelper.OnDataReceived     += OnMessageReceived;         //read the data

            bluetoothHelper.setTerminatorBasedStream("\n");

            if (bluetoothHelper.isDevicePaired())
            {
                Toggle_isDevicePaired.isOn = true;
            }
            else
            {
                Toggle_isDevicePaired.isOn = false;
            }
        } catch (Exception ex) {
            Toggle_isDevicePaired.isOn = false;
            Debug.Log(ex.Message);
        }
    }
Beispiel #20
0
    //Call this function to emulate message receiving from bluetooth while debugging on your PC.
    void OnGUI()
    {
        if (bluetoothHelper != null)
        {
            bluetoothHelper.DrawGUI();
        }
        else
        {
            return;
        }

        if (!bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect"))
            {
                if (bluetoothHelper.isDevicePaired())
                {
                    bluetoothHelper.Connect();              // tries to connect
                }
                else
                {
                    sphere.GetComponent <Renderer>().material.color = Color.magenta;
                }
            }
        }

        if (bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect"))
            {
                bluetoothHelper.Disconnect();
                sphere.GetComponent <Renderer>().material.color = Color.blue;
            }
        }

        if (bluetoothHelper.isConnected())
        {
            if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Send text"))
            {
                bluetoothHelper.SendData(new Byte[] { 0, 0, 85, 0, 85 });
                // bluetoothHelper.SendData("This is a very long long long long text");
            }
        }
    }
Beispiel #21
0
    void Start()
    {
        try
        {
            // Debug.Log(getNumber());
            Debug.Log(Application.unityVersion);
            BluetoothHelper.BLE                 = true; //use Bluetooth Low Energy Technology
            bluetoothHelper                     = BluetoothHelper.GetInstance();
            bluetoothHelper.OnConnected        += OnConnected;
            bluetoothHelper.OnConnectionFailed += OnConnectionFailed;
            bluetoothHelper.OnDataReceived     += OnMessageReceived; //read the data
            bluetoothHelper.OnScanEnded        += OnScanEnded;

            //bluetoothHelper.setTerminatorBasedStream("\n");
            //bluetoothHelper.setLengthBasedStream();
            bluetoothHelper.setFixedLengthBasedStream(10);

            // if(bluetoothHelper.isDevicePaired())
            //  sphere.GetComponent<Renderer>().material.color = Color.blue;
            // else
            //  sphere.GetComponent<Renderer>().material.color = Color.grey;
            // bluetoothHelper.ScanNearbyDevices();
            if (!bluetoothHelper.ScanNearbyDevices())
            {
                //text.text = "cannot start scan";
                sphere.GetComponent <Renderer>().material.color = Color.black;

                // bluetoothHelper.setDeviceAddress("00:21:13:02:16:B1");
                bluetoothHelper.setDeviceName("HC-08");
                bluetoothHelper.Connect();
            }
            else
            {
                text.text = "start scan";
                // sphere.GetComponent<Renderer>().material.color = Color.green;
            }
        }
        catch (BluetoothHelper.BlueToothNotEnabledException ex)
        {
            sphere.GetComponent <Renderer>().material.color = Color.yellow;
            Debug.Log(ex.ToString());
            text.text = ex.Message;
        }
    }
Beispiel #22
0
    /// <summary>
    /// This method creates a connection between the HC-055 module and the current device.
    /// </summary>
    public void Connect()
    {
        try
        {
            bt                     = BluetoothHelper.GetInstance("Regenfallrohr");
            bt.OnConnected        += OnConnected;
            bt.OnConnectionFailed += OnConnectionFailed;
            bt.setTerminatorBasedStream("\n");

            if (bt.isDevicePaired())
            {
                bt.Connect();
            }
        }
        catch (System.Exception)
        {
            print("Could not connect!");
        }
    }
Beispiel #23
0
    // Start is called before the first frame update
    void Start()
    {
        msg        = "";
        deviceName = "BabyDozer";
        try
        {
            helper                     = BluetoothHelper.GetInstance(deviceName);
            helper.OnConnected        += OnConnected;
            helper.OnConnectionFailed += OnConnectionFailed;
            helper.setTerminatorBasedStream("\n"); //every messages ends with new line character

            //Debug.Log(helper.isDevicePaired());
            if (helper.isDevicePaired())
            {
                helper.Connect();
            }
        }
        catch (Exception) {}
    }
Beispiel #24
0
    void Start()
    {
        deviceName = "ARcon_1";
        try
        {
            helper                     = BluetoothHelper.GetInstance(deviceName);
            helper.OnConnected        += OnConnected;
            helper.OnConnectionFailed += OnConnFailed;

            helper.setTerminatorBasedStream("\n");
            //or
            //helper.setLengthBasedStream();

            if (helper.isDevicePaired())
            {
                helper.Connect();
            }
        }catch (BluetoothHelper.BlueToothNotEnabledException ex) { }
        catch (BluetoothHelper.BlueToothNotReadyException ex) { }
        catch (BluetoothHelper.BlueToothPermissionNotGrantedException ex) { }
    }
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            switch (requestCode)
            {
            case 0:
                if (resultCode == Result.Ok)
                {
                }
                break;

            case DeviceManager.REQUEST_CONNECT_DEVICE:
                // When DeviceListActivity returns with a device to connect
                if (resultCode == Result.Ok)
                {
                    // Get the device MAC address
                    var address = data.Extras.GetString(DeviceManager.EXTRA_DEVICE_ADDRESS);
                    // Get the BLuetoothDevice object
                    //// Attempt to connect to the device
                    blueH.Connect(address);
                }
                break;

            case DeviceManager.REQUEST_ENABLE_BT:
                // When the request to enable Bluetooth returns
                if (resultCode == Result.Ok)
                {
                    // Bluetooth is now enabled, so set up a chat session
                    // SetupChat();
                }
                else
                {
                    // User did not enable Bluetooth or an error occured
                    //Log.Debug(TAG, "BT not enabled");
                    //Toast.MakeText(this, Resource.String.bt_not_enabled_leaving, ToastLength.Short).Show();
                    //Finish();
                }
                break;
            }
        }
Beispiel #26
0
    private void OnScanEnded(LinkedList <BluetoothDevice> devices)
    {
        msg.text += "Found " + devices.Count + " ";

        if (devices.Count == 0)
        {
            bluetoothHelper.ScanNearbyDevices();
            return;
        }

        try
        {
            bluetoothHelper.setDeviceName("ASTRA_K_LED_BLE");
            bluetoothHelper.Connect();

            msg.text += "Connecting ";
        }
        catch (Exception ex)
        {
            exception.text += ex + " ";
        }
    }
Beispiel #27
0
    void OnScanEnded2(LinkedList <BluetoothDevice> nearbyDevices)
    {
        Debug.Log("2 ended " + nearbyDevices.Count);
        if (nearbyDevices.Count == 0)
        {
            bluetoothHelper2.ScanNearbyDevices();
            return;
        }


        foreach (BluetoothDevice device in nearbyDevices)
        {
            Debug.Log(device.DeviceName);
            if (device.DeviceName == "HUAWEI Y7 Prime 2018")
            {
                Debug.Log("FOUND!!");
            }
        }


        bluetoothHelper2.setDeviceName("HUAWEI Y7 Prime 2018");
        bluetoothHelper2.Connect();
    }
Beispiel #28
0
 // Start is called before the first frame update
 void Start()
 {
     deviceName                          = "VenusIMU";
     bluetoothHelper                     = BluetoothHelper.GetInstance(deviceName);
     bluetoothHelper.OnConnected        += OnConnected;
     bluetoothHelper.OnConnectionFailed += OnConnectionFailed;
     bluetoothHelper.OnDataReceived     += OnMessageReceived;
     bluetoothHelper.setTerminatorBasedStream("\n");
     bluetoothHelper.Connect();
     startPos  = new Vector3(-0.15f, 60f, -10f);
     endPos    = new Vector3(-0.15f, 60f, -10f);
     startPos2 = new Vector3(-80.9f, 90.5f, -118.24f);
     endPos2   = new Vector3(-80.9f, 90.5f, -118.24f);
     HallPos1  = new Vector3(-0.15f, 60f, -10f);
     HallPos2  = new Vector3(-0.15f, 60f, -7f);
     HallPos3  = new Vector3(-0.15f, 60f, -4f);
     HallPos4  = new Vector3(-0.15f, 60f, -1f);
     US1       = new Vector3(-80.9f, 90.5f, -118.24f);
     US2       = new Vector3(-81.57f, 91.05f, -117.14f);
     US3       = new Vector3(-82.24f, 91.68f, -115.87f);
     US4       = new Vector3(-83.12f, 92.5f, -114.21f);
     //Linea de codigo de prueba para referencia
     CateterGuia.transform.rotation = Quaternion.Euler(roll * factor, 0, pitch * factor);
 }
    void OnScanEnded(BluetoothHelper helper, LinkedList <BluetoothDevice> nearbyDevices)
    {
        text.text = "Found " + nearbyDevices.Count + " devices";
        if (nearbyDevices.Count == 0)
        {
            helper.ScanNearbyDevices();
            return;
        }


        foreach (BluetoothDevice device in nearbyDevices)
        {
            if (device.DeviceName == deviceName)
            {
                Debug.Log("FOUND!!");
            }
        }

        text.text = deviceName;
        bluetoothHelper.setDeviceName(deviceName);
        // bluetoothHelper.setDeviceAddress("00:21:13:02:16:B1");
        bluetoothHelper.Connect();
        bluetoothHelper.isDevicePaired();
    }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            DisplayMetrics metric = new DisplayMetrics();

            this.Window.WindowManager.DefaultDisplay.GetMetrics(metric);
            float density = metric.Density;  // 屏幕密度(0.75 / 1.0 / 1.5)

            //Rate = (float)metric.WidthPixels / (float)1280;

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            blueH = new BluetoothHelper();
            int err = 0;
            Action <string, string> ConnectedAction = new Action <string, string>((name, address) =>
            {
            });
            Action <string> ConnectingAction = new Action <string>((t) =>
            {
            });
            Action <string> ConnFailedAction = new Action <string>((t) =>
            {
            });



            if (blueH.Init(ConnectedAction, ConnectingAction, ConnFailedAction) == 1)
            {
                //蓝牙已打开
            }
            else
            {
                if (blueH.IsOpen() == 1)
                {
                    //打开蓝牙
                    blueH.Open(this);
                }
            }



            Button btnScan = FindViewById <Button>(Resource.Id.MyButton);

            btnScan.Click += (o, e) =>
            {
                var serverIntent = new Intent(this, typeof(DeviceManager));
                StartActivityForResult(serverIntent, DeviceManager.REQUEST_CONNECT_DEVICE);
            };
            Button Print = FindViewById <Button>(Resource.Id.Print);

            Print.Click += (o, e) =>
            {
                Java.Lang.String str = new Java.Lang.String("hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111hello111111111111111111111111111111111111111111111111111111111111111111111111111111111111");

                if (blueH.IsConnected() != 1)
                {
                    if (blueH.Connect(address) == 1)
                    {
                        blueH.SendMessage(str);
                    }
                }
                else
                {
                    //blueH.SendMessage(str);
                    Bitmap bm = BitmapFactory.DecodeStream(Resources.Assets.Open("android.png"));
                    blueH.SendImg(bm, 576, 0);
                    blueH.WalkPaper(2);
                    blueH.CutPage();
                }
            };
        }