vediamo di capire se il service e il Timer dell'Activity lavorano in contemporanea.
Service
Activity
Service
B4X:
Sub AStream_NewData (Buffer() As Byte)
Dim Valore As String
Dim newDataStart As Int = sb.Length
sb.Append(BytesToString(Buffer, 0, Buffer.Length, charset))
Dim s As String = sb.ToString
Dim start As Int = 0
For i = newDataStart To s.Length - 1
Dim c As Char = s.CharAt(i)
If i = 0 And c = Chr(10) Then '\n...And
start = 1 'might be a broken end of line character
Continue
End If
If c = Chr(10) Then '\n
'CallSub2(Training,"ValoreGSR",s.SubString2(start, i))
'GSR=s.SubString2(start, i)
start = i + 1
Else If c = Chr(13) Then '\r
' CallSub2(Training,"GSROk",s.SubString2(start, i))
If start =0 And i=7 Then
Valore=s.SubString2(start, i)
File.WriteString(File.DirInternalCache,"lettura.txt",Valore)
Log("Conduttanza " & Valore & " - Time: " & DateTime.GetMinute(DateTime.Now) & ":" & DateTime.GetSecond(DateTime.Now))
End If
If i < s.Length - 1 And s.CharAt(i + 1) = Chr(10) Then '\r\n
i = i + 1
End If
start = i + 1
End If
Next
If start > 0 Then sb.Remove(0, start)
End Sub
Activity
B4X:
Sub Tim_Tick
Log("Lettura: " & File.ReadString(File.DirInternalCache,"lettura.txt") & " - Time: " & DateTime.GetMinute(DateTime.Now) & ":" & DateTime.GetSecond(DateTime.Now))
Select Secondi
Case 5
Secondi = 7
Tim.Interval=Secondi * DateTime.TicksPerSecond
Case 7
Secondi = 10
Tim.Interval=Secondi * DateTime.TicksPerSecond
Case 10
Secondi = 12
Tim.Interval=Secondi * DateTime.TicksPerSecond
Case 12
Secondi = 15
Tim.Interval=Secondi * DateTime.TicksPerSecond
Case 15
Tim.Enabled=False
End Select
End Sub