Private Sub Manager_Connected (Services As List)
Log("Connected")
For Each S As String In Services
Log("Service: " & S)
Next
For i=0 To Services.Size-1
manager.ReadData(Services.Get(i))
Next
Log("Proprietà caratteristica 301 "&manager.GetCharacteristicProperties(ServiceId, C301_risposta))
' manager.SetNotify(ServiceId, ReadChar, True)
' manager.SetNotify(ServiceId, C301_risposta, True) THIS LINE IS COMMENTED
connected = True
CallSub2(Main, "SetState", connected)
messagesToSend.Clear
End Sub
Private Sub Manager_DataAvailable (SId As String, Characteristics As Map)
Log ("Manager_DataAvailable")
Log(SId)
For i = 0 To Characteristics.Size - 1
Log("Key: " & Characteristics.GetKeyAt(i))
Log("Val: " & Characteristics.GetValueAt(i))
Dim BC As ByteConverter
Log("Str: " & BC.StringFromBytes(Characteristics.GetValueAt(i),"utf-8"))
Log("Main.tipomessaggiobluetooth " & Main.tipomessaggiobluetooth)
Log("Characteristics.GetKeyAt(i) " & Characteristics.GetKeyAt(i))
If Main.tipomessaggiobluetooth="E" Then
If Characteristics.GetKeyAt(i)=C303_posizionebilancia Then
Dim BC As ByteConverter
MessaggioBluetooth= BC.StringFromBytes(Characteristics.GetValueAt(i),"utf-8")
LogColor("Main.tipomessaggiobluetooth " & Main.tipomessaggiobluetooth &" Characteristics.GetKeyAt(i) " & Characteristics.GetKeyAt(i) & " MessaggioBluetooth " & MessaggioBluetooth,Colors.blue)
End If
End If
Next
Log(" ")
' Dim b() As Byte = Characteristics.Get(C301_risposta)
' CallSub2(Main, "NewMessage", b)
' NewMessage(b)
End Sub
Public Sub SendCommand(msg() As Byte)
LogColor("Dentro SendCommand",Colors.red)
messagesToSend.Add(TrimMessage(msg))
If messagesToSend.Size = 1 Then
Do While messagesToSend.Size > 0
Try
manager.WriteData(ServiceId, C300_comando, messagesToSend.Get(0))
Catch
FailedToSend
Return
End Try
Wait For Manager_WriteComplete (Characteristic As String, Status As Int)
If Status <> 0 Then
FailedToSend
End If
If connected = False Or messagesToSend.Size = 0 Then Return
messagesToSend.RemoveAt(0)
Loop
End If
End Sub