Sub Process_Globals
Dim bt As BluetoothAdmin
End Sub
Sub Globals
Dim btnigs As Button
Dim etrut As EditText
Dim pnlinicio As Panel
'bluetooth
Dim conectado As Boolean
Dim serial1 As Serial
Dim astreams As AsyncStreams
Dim lbltext As Label
Dim dato As String
Dim Label1 As Label
Dim Label2 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
serial1.Initialize("serial1")
End If
Activity.Title="Inicio"
'añadir opciones al menu
Activity.addmenuitem("Conectar BT","mnuconectar")
Activity.addmenuitem2("Informacion","info",LoadBitmap(File.DirAssets,"alertaa.png"))
'inicio creacion panel inicio mediante codigo
pnlinicio.Initialize("")
Activity.AddView(pnlinicio,0,0,100%x,100%y)
pnlinicio.Visible=True
'fin inicio panel inicio
Dim GD As GradientDrawable
GD.Initialize("TR_BL", Array As Int(Colors.Gray, Colors.LightGray))
Activity.Background = GD
Activity.LoadLayout("inicio")
Activity.Title="Inicio"
End Sub
Sub Activity_Resume
If serial1.IsEnabled=False Then
If Msgbox2("Activar BT","Mensaje","Si","","No",LoadBitmap(File.DirAssets,"alertaa.png"))=DialogResponse.POSITIVE Then
bt.Enable
Else
bt.Disable
End If
Else
serial1.Listen
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
astreams.Close
End If
End Sub
Sub mnuconectar_Click
Dim dispositivos As Map
dispositivos = serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To dispositivos.Size - 1
l.Add(dispositivos.GetKeyAt(i))
Next
Dim res As Int
res = InputList(l, "Dispositivos Pareados", -1)
If res <> DialogResponse.CANCEL Then
serial1.Connect(dispositivos.Get(l.get(res)))
End If
End Sub
Sub serial1_Connected (success As Boolean)
If success Then
ToastMessageShow("Coneccion Completa", False)
astreams.Initialize(serial1.InputStream,serial1.OutputStream,"astreams")
conectado=True
Else
conectado=False
Msgbox(LastException.Message, "Error de coneccion")
End If
End Sub
Sub btnigs_Click
If conectado=True Then
Dim buffer() As Byte
buffer=etrut.Text.GetBytes("UTF8")
astreams.Write(buffer)
Else
ToastMessageShow("Conectar bluetooth", False)
End If
End Sub
Sub astreams_NewData (buffer() As Byte)
dato = BytesToString(buffer,0,buffer.Length, "UTF8")
lbltext.Text=dato
If dato.Contains("T") Then
Label1.Text=dato.SubString(1)
Else If dato.Contains("V") Then
Label2.Text=dato.SubString(1)
Else If dato.Contains("P") Then
etrut.Text=dato.SubString(2)
End If
End Sub