Author Topic: Device discovered, paired and services enumerated. What next?  (Read 229 times)

Offline TrevorDrawbridge

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Hi Mike
I have successfully discovered my device and paired with it. I then enumerate its services. I have not figured out where to go beyond this. I assume I need to connect to the device somehow and create an event handler to receive data from it. I have looked at the examples, but they seem to stop once they get to the same place as me.

I would appreciate some help to get past this hurdle please.

Thanks
Trevor

Online Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3389
  • Karma: 1000
    • Wireless Communication Libraries
Re: Device discovered, paired and services enumerated. What next?
« Reply #1 on: March 18, 2019, 01:18:11 AM »
Hi,

Yes, you are absolutely correct. Once you discovered (found) your device you have to connect to it to be able to communicate with your device. Please, note that you do not need to execute pairing. Bluetooth Framework provides something known as Auto-Pairing (it is legacy term used in legacy Wireless Communication Library, because WCL provided 2 differen ways to pair with device: manual and auto). In fact Bluetooth Framework uses identical mechanism for both pairing methods.

So let me explaing it first: in terms of Bluetooth Framework manual pairing means that your application calls Pair method to pair with device. Auto pairing means that your application does not call Pair method. Instead of that an application simple tries to connect to device. If device requires pairing (not all devices require pairing) then Bluetooth Framework fires pairing events (the same events used in case you call Pair method) and your application may provide pairing details (PIN, user confimration or other).

So better to leave it with auto pairing without call Pair directly. however, it depends on your application requirements so that was just description of process and recomendation of usage.

Now connection. So once you found your device (or use previously found MAC, because if you know your device's MAC you do not need to rediscvoer it each time it the MAC is fixed) you can connect.

To connect to your device you have to use wclRfCommClient (we are talking about Classic Bluetooth Devices, in case of Bluetooth Low Energy GATT devices plrease refer to this article: https://www.btframework.com/ble.htm). The rfCommClient has few properties that is used to connect to your device:

Address - a remote device MAC;
Service - a Bluetooth Service's UUID you want to connect to. By default (if service not specified) rfCommClient uses Serial Port Profile (SPP) service's UUID.
Channel - RFCOMM channel number (you usualy do not need to set it).

Once all properties are set call Connect method. The method simpel startsconnection. If it returns WCL_E_SUCCESS that doe snot mean that connection has already been established. That just means that connection procedure has been started.

Once connection procedure completed (with or without success) the OnConnect event fires (with real connection result).

After that you can use Write() method to send data to a connected remote device. When data received from a connected device the OnData event fires.

For more information about RfComm communication please take a look on RfCommClient demo application.

Please note that the demo app sends and receives data as text (it was made so to be able to run RfCommClient on one PC and RfCommServer on other and test them by sending simple text messages).

Should yo uhave any question please do not hesitate to conect us: https://www.btframework.com/contacts.htm

By the way: If you are developing console app or Windows service please also take a look on this post: https://forum.btframework.com/index.php/topic,3520.msg9021.html#msg9021

Also take a look on Console demo application from Bluetooth Framework package.

 

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14