Author Topic: Simple Discover and Connect Sample?  (Read 17500 times)

pshaw

  • Guest
Simple Discover and Connect Sample?
« on: April 29, 2010, 07:48:10 AM »
Hi,
I am currently switching from Franson Bluetools to WCL because Franson does not support Windows 7.  My application simply needs to discover Bluetooth devices with a "Serial Service" service, and load those devices into a listbox.  Then I need to be able to connect to the device and read the data stream.  Ideally I want to be anbe to connect to several devices at the same time, I guess using separate threads, and read the data which will then be graphed.  Is there a sample that I can use as a good starting point?  Is this possible with WCL?  Thanks.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Simple Discover and Connect Sample?
« Reply #1 on: April 29, 2010, 09:03:51 AM »
Hello,
It is easy to do with WCL and you do not need any threads as WCL is asynchronouse library (of course you can use threads if you need it).
To discover devices and query its services take a look on BluetoothDiscovery demo.
To connect to remote device chd send/receive data - take a look on BluetoothClient demo.
To work with more than one device at time you have to use more than 1 wclClient component/class - one per remote device.
If you need threads - take a look on OPPThread to see how to use WCL in threads.

pshaw

  • Guest
Re: Simple Discover and Connect Sample?
« Reply #2 on: May 09, 2010, 12:45:54 PM »
Thanks, I looked at the suggested samples and modified them for my program.  I have 2 issues
1) How to define my service to be "Serial Interface"?  This is unique to my hardware.
2) I try to connect to the device then send a "WINK" command.  It errors out saying "device not connected".  This is my code:
        private void cmdWink1_Click(object sender, EventArgs e)
        {
            wcl.wclBluetoothRadio Radio = GetSelectedRadio();
            if (Radio != null)
            {
                if (cboDevice1.SelectedIndex == -1)
                    toolStripStatusLabelDiscovery.Text = "Please select a device";
                else
                {
                    if (wclClient1.State.ToString() == "csDisconnected")
                    {
                        string Address = cboDevice1.SelectedItem.ToString();
                        wclClient1.BluetoothParams.Address = Address;
                        wclClient1.BluetoothParams.Radio = Radio;

                        //My service
                        wclClient1.BluetoothParams.Service = "Serial Interface";
                        wclClient1.BluetoothParams.Service = wcl.wclUUIDs.SerialPortServiceClass_UUID;

                        wclClient1.Transport = wcl.wclClientTransport.ctBluetooth;
                        wcl.wclErrors.wclShowError(wclClient1.Connect());
                    }

                    string str = "WINK";
                    Encoding Coder = Encoding.ASCII;
                    byte[] Buf = Coder.GetBytes(str);
                    wcl.wclErrors.wclShowError(wclClient1.Write(Buf, (uint)str.Length));
                }
            }

        }

Thanks for your support.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Simple Discover and Connect Sample?
« Reply #3 on: May 09, 2010, 06:02:48 PM »
Hello,

WCL is ansyncronouse library. You must wait OnConnect event before write something. It already was discussed here.

pshaw

  • Guest
Re: Simple Discover and Connect Sample?
« Reply #4 on: May 10, 2010, 09:21:01 AM »
Thanks for the reply.  How do I set the service name?  My service name is "Serial Interface" which is the only service broadcasted my my hardware.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Simple Discover and Connect Sample?
« Reply #5 on: May 10, 2010, 09:53:26 AM »
Hello,

Service name means nothing. You must know your service's UUID. This is the thing is important for Bluetooth connection (actuly port number is important, but service's UUID is simple).
« Last Edit: May 10, 2010, 09:57:10 AM by Mike Petrichenko »

 

Sitemap 1 2 3 4 5 6 7