Private w3Raf As RandomAccessFile
Private BStreams As AsyncStreams
Private w3Init As Boolean
Private Serial1 As Serial
Public btdevice1 as string
Sub Service_Create
Serial1.Disconnect
Serial1.Initialize("Serial1")
End Sub
Sub Service_Start (StartingIntent As Intent)
Dim pairedDevices As Map = Serial1.GetPairedDevices
' Searching Bluetooth Device
'...
Serial1.Connect(btdevice1)
End Sub
Sub Serial1_Connected (Success As Boolean)
If Not(Success) Then Return
If BStreams.IsInitialized Then BStreams.Close
BStreams.Initialize(Serial1.InputStream, Serial1.OutputStream, "BStreams")
End Sub
Sub BStreams_NewData (Buffer() As Byte)
If writeLog Then
' Saving Buffer directly
If Not(w3Init) Then
w3Raf.Initialize(RawPath, "BtRAW.txt", False)
w3Init = True
End If
w3Raf.WriteBytes(Buffer, 0, Buffer.Length, w3Raf.CurrentPosition)
End If
' Processing Buffer
Dim bs As ByteConverter
Dim cominput As String
cominput = bs.StringFromBytes(Buffer, "UTF-8")
'...
End Sub
Sub Service_Destroy
If BStreams.IsInitialized Then BStreams.Close
If Serial1.IsInitialized Then Serial1.Disconnect
If w3Init Then
w3Raf.Close
w3Init = False
End If
End Sub