i just tried arduino uno project with rfid module
for the project at B4R it has been going well, the ID data from the card has also been read.
then there was a problem when I created a project in B4J and SQLite, where I had a sql query to match the data from the card earlier
but the result obtained from the query earlier is :
but if the query that I wrote earlier, I manually paste the data found
Is there anything missing in the process of sending data from Arduino to B4J?
for the project at B4R it has been going well, the ID data from the card has also been read.
My B4R:
Sub Process_Globals
Public Serial1 As Serial
Private rfid As MFRC522
Private bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
rfid.Initialize(10, 9, "rfid_CardPresent")
End Sub
Sub rfid_CardPresent (UID() As Byte, CardType As Byte)
Log(bc.HexFromBytes(UID))
End Sub
then there was a problem when I created a project in B4J and SQLite, where I had a sql query to match the data from the card earlier
My B4J Code:
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
but the result obtained from the query earlier is :
Result:
(NullPointerException) java.lang.NullPointerException
but if the query that I wrote earlier, I manually paste the data found
Is there anything missing in the process of sending data from Arduino to B4J?