Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private SQL1 As SQL
Private SenderFilter As Object
Private UID As String
'
Private sp As Serial
Private astream As AsyncStreams
'
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
'
xui.SetDataFolder("TestB4J")
'
astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")
sp.Initialize("")
sp.Open("COM3")
Dim BaudRate As Int = 115200
Dim DataBits As Int = 8
Dim StopBits As Int = 1
Dim Parity As Int = 0
sp.SetParams (BaudRate , DataBits , StopBits , Parity )
Log("Awaiting Selection")
'
Config_Object
End Sub
Private Sub B4XPage_Appear
ConnectToDatabase
End Sub
Sub AStream_NewData (Buffer() As Byte)
UID = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Sleep(1000)
Cek_Data
End Sub
Sub ConnectToDatabase
Dim SafeDirectory0 As String = xui.DefaultFolder
Dim strFile0 As String = "mydata.db"
'
If File.Exists(SafeDirectory0, strFile0) = False Then
File.Copy(File.DirAssets, strFile0, SafeDirectory0, strFile0)
SQL1.InitializeSQLite(SafeDirectory0, strFile0, False)
Else
SQL1.InitializeSQLite(SafeDirectory0, strFile0, False)
End If
End Sub
Sub Cek_Data
Try
SenderFilter = SQL1.ExecQueryAsync("SQL", $"SELECT * FROM userdata
WHERE rfid = '${UID}'"$, Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, RS As ResultSet)
If Success Then
Do While RS.NextRow
Dim cd As User
cd.iduser = RS.GetString2(0)
cd.rfid = RS.GetString2(1)
cd.name = RS.GetString2(2)
Loop
'
log(cd.iduser & " -" & cd.name)
'
RS.Close
End If
Catch
Log(LastException)
End Try
End Sub