I just posted Bluetooth driver on Codeshare. Feel free to discuss and make suggestions here.
Thank you for the contribution.
Can you please give a short example how the driver/module is initialized in the Program.Started method and how it works in host mode.
Kind regards.
Roland
@ VB-Daniel:
I was able to get your code mostly working, but I could not get the Bluetooth.DataReceived event to fire, although the Bluetooth.BlueToothStateChanged event fired as expected.
Private Sub bluetooth_BluetoothStateChanged(sender As Gadgeteer.Modules.GHIElectronics.VAI_Bluetooth, btState As Gadgeteer.Modules.GHIElectronics.VAI_Bluetooth.BluetoothState) Handles bluetooth.BluetoothStateChanged
Dim stat As String = ""
Select Case btState
Case VAI_Bluetooth.BluetoothState.Connecting
stat = ("Bluetooth connecting...")
Case VAI_Bluetooth.BluetoothState.Connected
stat = ("Bluetooth connected!")
BlueTimer.Start()
Case VAI_Bluetooth.BluetoothState.Disconnected
bluetoothClient.EnterPairingMode()
stat = ("Bluetooth disconnected!")
' never fires
Case VAI_Bluetooth.BluetoothState.Initializing
stat = ("Bluetooth initializing!")
Case VAI_Bluetooth.BluetoothState.Inquiring ' in pariing mode
stat = ("Bluetooth inquiring!")
Case VAI_Bluetooth.BluetoothState.Ready
stat = ("Bluetooth Ready!")
bluetoothClient.EnterPairingMode()
'BlueTimer.Start()
End Select
_btstate = btState
Debug.Print("Bluetooth State Changed to :" & btState.ToString())
Display(1, stat, Gadgeteer.Color.Yellow)
End Sub
Private _btstate As VAI_Bluetooth.BluetoothState
Dim _received As Integer = 0
Dim _matched As Integer = 0
Private Sub bluetooth_DataReceived(sender As VAI_Bluetooth, data As String) Handles bluetooth.DataReceived
data = data.Trim
If data = "" Then Return
Dim s As String = "Bluetooth data recieved:"
If sender.IsConnected Then
s = s & data
Else
s = "Bluetooth status " & data
End If
Display(3, s, Gadgeteer.Color.White)
End Sub
@ rockybooth - oh i see…
The DataReceived event is a left part of the original driver. I want to delete this event. I’m not sure if everyone needs string data to receive. But reading the data to string means not binary data are allowed. So I decide everyone build his own data reader using the functions BytesToRead() an read().
thanx Daniel
@ RoSchmi - i will prepare a usage example next days…
Daniel
@ VB-Daniel:
If you can pattern the Bluetooth driver after the VB serial port driver in regular VB.NET, then users may find it easier to implement. Having a DataReceived event I would put at the top of the list. After the event fires, then a ReadExisting, ReadLine, and the other methods (or some subset) of the SerialPort Class, could be used.
Just a suggestion…