1

I am currently trying use 32feet.net to connect to a bluetooth speaker that once shutdown (the computer or the speaker) they stay paired but they dont auto reconnect. Therefore I want to make an windows service that tries to reconnect to it every so often if its not connected and if it can find it.

I have tried

C# 32feet.Net: Handling two bluetooth connections in seperate threads, gives SocketException

Code but for some reason there is a few things that light up red.

I am also trying to figure out and make this code work at the same time for the same purpose

public void btconnect()
    {
        List<Device> devices = new List<Device>();
        InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient();
        InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices();
        int count = array.Length;
        for (int i = 0; i<count; i++)
        {
            Device device = new Device(array[i]);
            devices.Add(device);
        }

        foreach(Device d in devices)
        {
            if (d.DeviceInfo.ToString().Equals("myphonesdevicenumber"))
            {
            Guid MyServiceUuid
            = new Guid("{00112233-4455-6677-8899-aabbccddeeff}"); // found this somewhere not sure what the string represents.

                byte[] guidbytearray = d.DeviceInfo.ToByteArray(); // guid as a byte array.
                string guidstring = d.DeviceInfo.ToString(); //guid as a string.
                Int64 guid64 = d.DeviceInfo.ToInt64(); // guid as an int64.

                Guid g = new Guid(guidbytearray);




                bc.Connect(d.DeviceInfo,MyServiceUuid);
            // turnoff = false;
            }
        }
    }

List devices = new List();

in the orignal code this wasnt there and I dont know if he was using (Device) it from a external reference or not.

Community
  • 1
  • 1
Karles
  • 50
  • 7

1 Answers1

0

In the article of 32feet, they list an inner-class named Device. You should use it in your program. The Guid is the identifier for the socket used to connect to your BT device. The format is a 32 digit long of hex numbers divided into group of 8, 4 ,4 ,4 and 12. Between the groups there is a '-'.

Janyk
  • 571
  • 3
  • 18