'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim serial1 As Serial
Dim admin As BluetoothAdmin
Dim AStream As AsyncStreams
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.
Dim TabHost1 As TabHost
Dim ListView1 As ListView
Dim PairedDevices As Map
Dim txtLog As EditText
Dim txtInput As EditText
Dim btnSend As Button
Dim received_data As String
Dim ListView2 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
If FirstTime Then
serial1.Initialize("Serial1")
admin.Initialize("admin")
End If
If admin.IsEnabled = False Then
If admin.Enable = False Then
ToastMessageShow("Error enabling Bluetooth adapter.", True)
Else
ToastMessageShow("Enabling Bluetooth adapter...", False)
'the StateChanged event will be soon raised
End If
Else
Admin_StateChanged(admin.STATE_ON, 0)
End If
If serial1.IsEnabled = False Then
Msgbox("Please enable Bluetooth.", "")
Else
serial1.Listen 'listen for incoming connections
End If
Activity.AddMenuItem("Beenden","exit")
Activity.LoadLayout("main")
TabHost1.AddTab("Init","tab1")
TabHost1.AddTab("Wert","tab2")
PairedDevices = serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i))
ListView1.AddSingleLine(PairedDevices.GetKeyAt(i))
ListView1.AddSingleLine(PairedDevices.GetValueAt(i))
Next
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
serial1.Connect(Value)
End Sub
Sub Admin_StateChanged (NewState As Int, OldState As Int)
NewState = admin.STATE_ON
End Sub
Sub Serial1_Connected (Success As Boolean)
If Success Then
ToastMessageShow("Connected successfully", False)
ListView1.AddSingleLine("verbunden")
'StartActivity(bluetooth)
If AStream.IsInitialized = False Then
AStream.Initialize(serial1.InputStream, serial1.OutputStream, "AStreams")
'AStream.InitializePrefix(serial1.InputStream, True, serial1.OutputStream, "AStreams")
End If
Else
Msgbox(LastException.Message, "Error connecting.")
End If
End Sub
Sub exit_click
serial1.Disconnect
Activity.Finish
ExitApplication
End Sub
Sub AStreams_NewData (Buffer() As Byte)
LogMessage("", BytesToString(Buffer, 0, Buffer.Length, "ASCII"))
End Sub
Sub LogMessage(From As String, Msg As String)
'txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF
'txtLog.SelectionStart = txtLog.Text.Length
txtLog.Text = txtLog.Text & Msg & CRLF
txtLog.SelectionStart = txtLog.Text.Length
received_data = Msg ' HERE IS THE PROBLEM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
End Sub
Sub AStream_Error
ToastMessageShow("Connection is broken.", True)
btnSend.Enabled = False
txtInput.Enabled = False
End Sub
Sub AStream_Terminated
AStream_Error
End Sub