Android Question why my application dont want to COnnect with arduino??

ChandraBUwa

New Member
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim serialandroid As Serial
    Dim datakeluarmasuk As AsyncStreams
    Dim bluetoothterpairing As Map

   
End Sub


Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private klakson As Button
    Private Kontak As Button
    Private stang As Button
    Private starter As Button
    Private diskonek As Button
    Private konek As Button
    Dim sttkontak As Int
    Dim sttstang As Int


End Sub
Sub AStreams_NewData (Buffer() As Byte)
    End Sub
   

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("smartlayout")
    serialandroid.Initialize("serialandroid")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub konek_Click
Dim    bluetoothterpairing As Map
    bluetoothterpairing=serialandroid.GetPairedDevices
    Dim daftarbluetooth As List
    daftarbluetooth.Initialize
    For i = 0 To bluetoothterpairing.Size -1
    daftarbluetooth.Add(bluetoothterpairing.GetKeyAt(i))
    Next
    Dim tampilkandevice As Int
    tampilkandevice = InputList(daftarbluetooth,"Silahkan Pilih Bluetooth",-1)
    If tampilkandevice <> DialogResponse.CANCEL Then
    serialandroid.Connect(bluetoothterpairing.Get(daftarbluetooth.get(tampilkandevice)))
    End If
End Sub
Sub diskonek_Click
    serialandroid.Disconnect
    ToastMessageShow("Koneksi Telah di Putus",False)
   
End Sub

Sub serialandroid_Connected (Success As Boolean)
If Success Then
datakeluarmasuk.Initialize(serialandroid.InputStream,serialandroid.OutputStream,"Datakeluarmasuk")
    ToastMessageShow ("Koneksi Berhasil", False)
    Else
    ToastMessageShow ("koneksi Gagal",False)
    End If
End Sub

Sub Kontak_Click
    'A=hidup,a=mati
    sttkontak = sttkontak+1
    If sttkontak=1 Then
    Kontak.SetBackgroundImage(LoadBitmap(File.DirAssets,"keyb.png"))
    Dim buffer()As Byte
    buffer= "A".GetBytes("UTF8")'UTF8 = Unicode Text Format 8 bit'
    datakeluarmasuk.Write(buffer)
    End If
    If sttkontak = 2 Then
    Kontak.SetBackgroundImage(LoadBitmap(File.DirAssets,"keym.png"))
    Dim buffer()As Byte
    buffer= "a".GetBytes("UTF8")'UTF8 = Unicode Text Format 8 bit'
    datakeluarmasuk.Write(buffer)
    sttkontak=0
    End If
End Sub
Sub stang_Click
    'D=hidup,d=mati
    sttstang = sttstang+1
    If sttstang=1 Then
    stang.SetBackgroundImage(LoadBitmap(File.DirAssets,"PADLOCKHTM.png"))
    Dim buffer()As Byte
    buffer= "D".GetBytes("UTF8")'UTF8 = Unicode Text Format 8 bit'
    datakeluarmasuk.Write(buffer)
    End If
    If sttstang = 2 Then
    stang.SetBackgroundImage(LoadBitmap(File.DirAssets,"PADLOCKMRH.png"))
    Dim buffer()As Byte
    buffer= "d".GetBytes("UTF8")'UTF8 = Unicode Text Format 8 bit'
    datakeluarmasuk.Write(buffer)
    sttstang=0
    End If
End Sub
Sub starter_LongClick
    starter.SetBackgroundImage(LoadBitmap(File.DirAssets,"STARTERMERAH.png"))
    Dim buffer()As Byte
    buffer= "B".GetBytes("UTF8")'UTF8 = Unicode Text Format 8 bit'
    datakeluarmasuk.Write(buffer)
End Sub
Sub starter_Up
    starter.SetBackgroundImage(LoadBitmap(File.DirAssets,"STARTERHITAM.png"))
    Dim buffer()As Byte
    buffer= "b".GetBytes("UTF8")'UTF8 = Unicode Text Format 8 bit'
    datakeluarmasuk.Write(buffer)
End Sub
Sub klakson_LongClick
    klakson.SetBackgroundImage(LoadBitmap(File.DirAssets,"KLAKSONMRH.png"))
    Dim buffer()As Byte
    Dim datatombol As String
    datatombol= "x"&Chr(10)
    buffer= datatombol.GetBytes("UTF8")'UTF8 = Unicode Text Format 8 bit'
    datakeluarmasuk.Write(buffer)
End Sub
Sub datakeluarmasuk_NewData (Buffer() As Byte)
    Dim datamasuk As String
    datamasuk= BytesToString(Buffer,0,Buffer.Length,"UTF8")
End Sub

Sub klakson_Up
    klakson.SetBackgroundImage(LoadBitmap(File.DirAssets,"KLAKSONHTM.png"))
    Dim buffer()As Byte
    buffer= "c".GetBytes("UTF8")'UTF8 = Unicode Text Format 8 bit'
    datakeluarmasuk.Write(buffer)
End Sub
Sub stangtutup_Click
   
End Sub

whats wrong with my code???need help dude
 
Last edited:
Top