Android Question Receive data with BLE 2 connection from Rfid reader

Christian García S.

Active Member
Licensed User
Hello everyone,

I have a Bluetooth Rfid reader, the conexion with it I have made with BLE 2, I can read and write characteristics to reader.

Now I need to receive the data from the readings TAGS, I read this post https://www.b4x.com/android/forum/threads/rfid-reader-connection.73322/#post-465827 and it says "Make sure to initialize AsyncStreams in non-prefix mode"

I am trying the way to connect AsyncStreams, but I only found examples with Bluetooth Admin and serial.

Anyway I tried serial but I do not have good results, I do not know if I'm doing it right.

B4X:
Sub Process_Globals

Public manager As BleManager2
Dim BTConnection As Serial
Dim Astream As AsyncStreams

End Sub

Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
    Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
manager.StopScan
        manager.Connect2(Id, False) 'disabling auto connect can make the connection quicker
        BTConnection.Initialize("RFIDreader")
        BTConnection.Connect(Id)
End Sub

Sub RFIDreader_Connected (Success As Boolean)
    If Success Then
        Log("RFID conectado")
        Astream.Initialize(BTConnection.InputStream,Null,"RFIDreaderAs")
    Else
        ToastMessageShow("RFID no encontrado...",False)
    End If
End Sub

Can you help me with how I can receive the data with AsyncStreams or by other way ???

Thanks in advance.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Christian García S.

Active Member
Licensed User
Hello, thanks for your answers.

Classic bluetooth is BluetoothAdmin ????

Because in my first post https://www.b4x.com/android/forum/threads/translate-sdk-rfid-bluetooth-reader-to-b4a.89833 five days ago, I tried to connect with Bluetooth admin, but it generated an error and after trying many times I managed to connect with BLE, with BLE I can read and write characteristics, but not receive the data.

Now I am at the same point as 5 days ago and back and I do not know how to make the connection. :(

Thanks for your help.

Christian
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
https://www.b4x.com/android/help/ble2.html#blemanager2_setnotify
Also check the docu. Especially setnotify... Here you can add (or remove) a listener for Value-changes to a Service and a specific characteristic.

SetNotify (Service As String, Characteristic As String, Notify As Boolean)
Adds or removes a notification listener that monitor value changes.
The DataAvailable event will be raised when the value of the characteristic changes.
Service - The service id (as returned in the Connected event).
Characteristic - The characteristic id.
Notify - True to add a listener, false to remove it.
 
Upvote 0

Christian García S.

Active Member
Licensed User
Thanks.

Yes, I read that example and I have connection with reader with BLE2, I can read and write characteristics, why I maked connection with BLE because I get error with bluetooth admin.

In a previous post (https://www.b4x.com/android/forum/t...id-bluetooth-reader-to-b4a.89833/#post-568551) I asked how I get data with BLE 2, and maked this new thread for this question.

The rigth question is where I can get the rfid tags from reader ??? from serviceID and characteristcs ??? I am confused I dont know where.

Why I ask where, because when I read all characteristics again, I only receive few data and not the rfid tags.

B4X:
Sub Process_Globals
    Public manager As BleManager2
    Public currentStateText As String = "UNKNOWN"
    Public currentState As Int
    Public connected As Boolean = False
    Public ConnectedName As String
    Private ConnectedServices As List
    Public rp As RuntimePermissions
   
    Public SetCommand As Int = 0
    Public ServiceId_G As String              = "0000ffe0-0000-1000-8000-00805f9b34fb"
    Public Characteristic_G As String          = "0000ffe1-0000-1000-8000-00805f9b34fb"
    Public ComAddr As Byte
   
    Dim BTConnection As Serial
    Dim Astream As AsyncStreams
   
End Sub

Sub Command_Inventory_G2
   
    Dim Msg() As Byte

    Log("Write data: ")

    Msg = Array As Byte (6,ComAddr & 255,1,0,0)
   
    manager.WriteData(ServiceId_G,Characteristic_G,Msg)   
    manager.SetNotify(ServiceId_G,Characteristic_G, True)
'    manager.SetIndication(ServiceId_G, Characteristic_G,True)
    SetCommand = 2
    ReadData
End Sub

Public Sub ReadData
    For Each s As String In ConnectedServices
        manager.ReadData(s)               
    Next
End Sub

These are output from code before

B4X:
Serviceid: 00001801-0000-1000-8000-00805f9b34fb Char: (MyMap) {00002a05-0000-1000-8000-00805f9b34fb=[B@8a4ce31}
***********************************
Key: 00002a05-0000-1000-8000-00805f9b34fb -> Value: 
Serviceid: 00001800-0000-1000-8000-00805f9b34fb Char: (MyMap) {00002a00-0000-1000-8000-00805f9b34fb=[B@802297, 00002a01-0000-1000-8000-00805f9b34fb=[B@8e2ec84, 00002a02-0000-1000-8000-00805f9b34fb=[B@ec71c6d, 00002a04-0000-1000-8000-00805f9b34fb=[B@ebe80a2, 00002a03-0000-1000-8000-00805f9b34fb=[B@19a5133}
***********************************
Key: 00002a00-0000-1000-8000-00805f9b34fb -> Value: 554254313735323939313742
***********************************
Key: 00002a01-0000-1000-8000-00805f9b34fb -> Value: 0000
***********************************
Key: 00002a02-0000-1000-8000-00805f9b34fb -> Value: 00
***********************************
Key: 00002a04-0000-1000-8000-00805f9b34fb -> Value: 5000A0000000E803
***********************************
Key: 00002a03-0000-1000-8000-00805f9b34fb -> Value: 
Serviceid: 0000180a-0000-1000-8000-00805f9b34fb Char: (MyMap) {00002a23-0000-1000-8000-00805f9b34fb=[B@3e44cf0, 00002a24-0000-1000-8000-00805f9b34fb=[B@9461269, 00002a25-0000-1000-8000-00805f9b34fb=[B@2a804ee, 00002a26-0000-1000-8000-00805f9b34fb=[B@11ecd8f, 00002a27-0000-1000-8000-00805f9b34fb=[B@859481c, 00002a28-0000-1000-8000-00805f9b34fb=[B@3a46c25, 00002a29-0000-1000-8000-00805f9b34fb=[B@f9381fa, 00002a2a-0000-1000-8000-00805f9b34fb=[B@4c4b3ab, 00002a50-0000-1000-8000-00805f9b34fb=[B@7c0ca08}
***********************************
Key: 00002a23-0000-1000-8000-00805f9b34fb -> Value: 3F05110000831500
***********************************
Key: 00002a24-0000-1000-8000-00805f9b34fb -> Value: 4D6F64656C204E756D62657200
***********************************
Key: 00002a25-0000-1000-8000-00805f9b34fb -> Value: 53657269616C204E756D62657200
***********************************
Key: 00002a26-0000-1000-8000-00805f9b34fb -> Value: 4669726D77617265205265766973696F6E00
***********************************
Key: 00002a27-0000-1000-8000-00805f9b34fb -> Value: 4861726477617265205265766973696F6E00
***********************************
Key: 00002a28-0000-1000-8000-00805f9b34fb -> Value: 536F667477617265205265766973696F6E00
***********************************
Key: 00002a29-0000-1000-8000-00805f9b34fb -> Value: 4D616E756661637475726572204E616D6500
***********************************
Key: 00002a2a-0000-1000-8000-00805f9b34fb -> Value: FE006578706572696D656E74616C
***********************************
Key: 00002a50-0000-1000-8000-00805f9b34fb -> Value: 010D0000001001
Serviceid: 0000ffe0-0000-1000-8000-00805f9b34fb Char: (MyMap) {0000ffe1-0000-1000-8000-00805f9b34fb=[B@4d4a5a1}
***********************************
Key: 0000ffe1-0000-1000-8000-00805f9b34fb -> Value: 06
 
Upvote 0
Top