Visual Basic. PC2Android - Android2PC - Bluetooth. Run app.

282 views
Skip to first unread message

Juan Antonio

unread,
Nov 17, 2018, 5:41:52 PM11/17/18
to mitappinv...@googlegroups.com
Hello friends,

in other post I wrote about send/receive data PC <-> Android by Bluetooth with AutoIt.

- Now send/receive data PC <-> Android by Bluetooth with Visual Basic .Net
---------------------------------------------------------------------------------------------------------------------------------------------------
1.- We need a PC or laptop with Bluetooth (or a dongle Bluetooth.)

bt41.png

2.- I use Visual Basic 2010 Express (you can try a newer version).

bluetooth_VB7.png


3.- Open port in Visual Basic, then Click Button "Connect" in Android. Enable Timer in VB.


4.- We can send "Hola/Adios", "Hello/Goodbye" from Visual Basic to Android.

5.- We can send a random number or a text from Android to Visual Basic.

6.- Run "Calculator.exe", "Notepad.exe" in Windows.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

bluetooth_VB5.png

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Imports System.IO
Imports System.IO.Ports
Imports System.Threading

' Programa realizado por Juan Antonio Villalpando
' juana1991@yahoo.com
' Pulsamos botones en Visual Basic y enviamos información a AppInventor.
' Pulsamos botones en App Inventor y enviamos un mensaje al Visual Basic y se ejecuta un programa.

Public Class Form1

    Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs)
        SerialPort1.Close()
    End Sub

    Shared _continue As Boolean
    Shared _serialPort As SerialPort
    Dim cambio1, cambio2 As Boolean
    Dim recibido As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        SerialPort1.Close()
        SerialPort1.PortName = "com23" 'CAMBIA EL PUERTO COM
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default
        cambio1 = True
        cambio2 = True
    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SerialPort1.Open() ' Abrir puerto
        Button1.Enabled = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SerialPort1.Close() ' Cerrar puerto
        Button1.Enabled = True
    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' SALIDA DE DATOS
    ' Envia información a App Inventor.
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If cambio1 Then
            SerialPort1.Write("Hola" & vbCrLf)
        Else
            SerialPort1.Write("Adios" & vbCrLf)
        End If
        cambio1 = Not cambio1
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If cambio2 Then
            SerialPort1.Write("Hello" & vbCrLf)
        Else
            SerialPort1.Write("Goodbye" & vbCrLf)
        End If
        cambio2 = Not cambio2
    End Sub
    ' ENTRADA DE DATOS
    ' Activa el Temporizador y lee datos desde el App Inventor.
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Timer1.Enabled = True
    End Sub


    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

        Try
            recibido = SerialPort1.ReadExisting()
            If recibido <> "" Then
                Label1.Text = recibido & vbCrLf
                If recibido = "Notepad" Then System.Diagnostics.Process.Start("notepad.exe")
                If recibido = "Calculator" Then System.Diagnostics.Process.Start("calc.exe")
            End If
        Finally
            ' 
        End Try

    End Sub

End Class		  
''''''''''''''''''''''''''''''''''''''''''''''''''''
Regards, Juan Antonio Villalpando.
Here information in Spanish: http://kio4.com/appinventor/9R_ordenador_BT_AI2.htm


p9Ri_Bluetooth_VB.aia
Reply all
Reply to author
Forward
0 new messages