Salut Baloub
le bluetooth c'est comme un port com.
Dans ton programme, tu dois donc
inclure un serial port dans la userform qui va gérer ça
un timer (pour éviter d'attendre un temps infini une non réponse)
puis si tu veux gérer plusieurs bluetooth, il faut rechercher les com associés puis se connecter dessus et enfin envoyer et recevoir les commandes
j'ai fait une telle application pour commander mon robot.
je te copie un peu du code que j'ai fait
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| 'cherche les port com actifs
Private Sub B_findCOM_Click(sender As System.Object, e As System.EventArgs) Handles B_findCOM.Click
Dim portCOMname As String
Dim n As Integer
n = 0
ListePortCOM.Controls.Clear()
For Each portCOMname In My.Computer.Ports.SerialPortNames
Dim rdo As New RadioButton
rdo.Name = portCOMname
rdo.Text = portCOMname
n = n + 1
rdo.Location = New Point(5, 20 * n)
ListePortCOM.Controls.Add(rdo)
Next
End Sub |
la sélection du port com à ouvrir se fait par radio bouton
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Private Sub B_Connexion_Click(sender As System.Object, e As System.EventArgs) Handles B_Connexion.Click
'récupère le nom du port COM sélectionné et ouvre la communication
Dim rButton As RadioButton
rButton = ListePortCOM.Controls.OfType(Of RadioButton)().FirstOrDefault(Function(r) r.Checked = True)
SerialPort_arduino.PortName = rButton.Name
SerialPort_arduino.BaudRate = 9600
SerialPort_arduino.DataBits = 8
SerialPort_arduino.Parity = Parity.None
SerialPort_arduino.StopBits = StopBits.One
SerialPort_arduino.Handshake = Handshake.None
SerialPort_arduino.Encoding = System.Text.Encoding.Default 'very important!
'établi la connexion
Try
SerialPort_arduino.Open()
SerialPort_arduino.ReadTimeout = 100000
SerialPort_arduino.WriteTimeout = 100000
If SerialPort_arduino.IsOpen Then
MsgBox("Connection successful")
End If
Label_port_valeur.Text = SerialPort_arduino.PortName.ToString
Timer1.Enabled = True
Label_timer.Text = "Timer: ON"
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub |
et tu utilises la commande
SerialPort_arduino.Write(ordre)
pour envoyer tes messages.
pour te déconnecter :
1 2 3 4 5 6
| Private Sub B_deconnexion_Click(sender As System.Object, e As System.EventArgs) Handles B_deconnexion.Click
SerialPort_arduino.Close()
Timer1.Enabled = False
Label_timer.Text = "Timer: OFF"
Label_port_valeur.Text = "#"
End Sub |
voilà ce que cela donne visuellement

voilà pour un début. Par contre il te faudra connaitre les commandes à envoyer à tes interfaces connectés. Dernier point : ne pas oublier d'allumer le bluetooth de l'ordi sinon tu ne verra pas les port com... 
(PS : en tapant VB.net et bluetooth sur google tu dois pouvoir trouver des tutos plus complets)
Partager