Hello,
I have three components, Asyncstream, timer and SD.stream, asyncstream reads data from RFID module, timer prevents repeated readings within 5 seconds then I open file that is equivalent to RFID card to read data.
The problem is, before writing SD.stream part, everything was going very good, then it seems that the timer is useless (repeated reading occurs) but I get success reading from SD card. The question is, how to make these three components work together without conflict.
Thanks
if I remove this part every thing goes fine
I have three components, Asyncstream, timer and SD.stream, asyncstream reads data from RFID module, timer prevents repeated readings within 5 seconds then I open file that is equivalent to RFID card to read data.
The problem is, before writing SD.stream part, everything was going very good, then it seems that the timer is useless (repeated reading occurs) but I get success reading from SD card. The question is, how to make these three components work together without conflict.
Thanks
B4X:
RunNative("SerialNative1", Null)
RunNative("SerialNative2", Null)
RFIDstream.Initialize(SerialNative2,"ReadRFID","RFIDerr")
NoReadingTimer.Initialize ("NoReadingTimer_Tick",1000)
NoReadingTimer.Enabled =True
B4X:
private Sub ReadRFID(Buffer() As Byte)
Dim tmpBuffer () As Byte
Dim Str_HexNumber As String
'Dim Int_Number As ULong
'Log(BC.HexFromBytes (Buffer))
If BC.ArrayCompare(Buffer,BufferLast) = 0 Then Return'compare last read card to recent one
BC.ArrayCopy(Buffer,BufferLast) 'copy last read to recent one, for next comparison
NoReadingTimerTicks = 0
NoReadingTimer.Enabled = True
Log("hex buffer:",BC.HexFromBytes (Buffer))
tmpBuffer= BC.SubString2(Buffer,3,11) 'get card bytes only, get ride of checksum and start byte
Str_HexNumber = BC.StringFromBytes(tmpBuffer)
'Int_Number = Bit.ParseInt(Str_HexNumber, 16) 'convert hex to decimal string
Dim cb (70) As Byte
Dim filename As String
filename = JoinStrings (Array As String("vehicles/",Str_HexNumber, ".vrd"))
Log(filename)
If Sd.OpenRead(filename) Then
Sd.Stream.ReadBytes(cb, 0 ,70)
Sd.close
Log("buffer:", cb)
End If
End Sub
B4X:
private Sub NoReadingTimer_Tick()
NoReadingTimerTicks = NoReadingTimerTicks + 1 'avoid reading same card withing 5 seconds
If NoReadingTimerTicks >= 5 Then
Dim m As Byte
For m = 0 To 13
BufferLast(m) = 0 'reset comparison array
Next
NoReadingTimer.Enabled =False
End If
End Sub
if I remove this part every thing goes fine
B4X:
Dim cb (70) As Byte
Dim filename As String
filename = JoinStrings (Array As String("vehicles/",Str_HexNumber, ".vrd"))
Log(filename)
If Sd.OpenRead(filename) Then
Sd.Stream.ReadBytes(cb, 0 ,70)
Sd.close
Log("buffer:", cb)
End If
B4X:
#IF C
void SerialNative1(B4R::Object* unused) {
::Serial1.begin(115200); //<--You can change the baud rate
b4r_main::_serialnative1->wrappedStream = &::Serial1;
}
void SerialNative2(B4R::Object* unused) {
::Serial2.begin(9600); //<--You can change the baud rate
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#END IF