#Region Project Attributes
#AutoFlushLogs: true
#StackBufferSize: 2000
#CheckArrayBounds: true
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private SerialNative2 As Stream
Private sd As SD
Private astream As AsyncStreams
Private bc As ByteConverter
End Sub
Private Sub AppStart
Log("AppStart")
RunNative("SerialNative2", Null)
astream.Initialize(SerialNative2, "astream_NewData", Null)
sd.Initialize(4)
End Sub
Sub astream_newdata (buffer1() As Byte)
Log("Recived Data : ",bc.HexFromBytes(buffer1))
Dim hh As String = bc.HexFromBytes(buffer1)
send_to_serial (hh)
End Sub
Sub send_to_serial (hh As String)
Dim file As String = get_file_name(hh)
If sd.OpenRead (file) = True Then
For y = 0 To 2061 Step 512
If y <> 2048 Then
Dim cb (512) As Byte
sd.Position =y
sd.Stream.ReadBytes(cb, 0, 512)
astream.Write(cb)
Else
Dim cb (13) As Byte
sd.Position =y
sd.Stream.ReadBytes(cb, 0, 13)
astream.Write(cb)
End If
Delay(100)
Next
End If
sd.close
End Sub
Sub get_file_name(block As String ) As String
If bc.SubString2(block,0,5)="0F370" And block.Length =16 Then
Dim adadesh As String = bc.StringFromBytes(bc.SubString2(block,5,8)) ' 050
Dim i As Int = Bit.ParseInt(bc.StringFromBytes(adadesh), 16) + 3
Dim str_adad As String = i
Dim file_name As String = JoinStrings(Array As String(str_adad, ".dat"))
Return file_name
End If
Return "error"
End Sub
Sub AStream_Error
Log("Error In serial Port")
End Sub
#if C
void SerialNative2(B4R::Object* unused) {
::Serial2.begin(38400);
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#end if