app4you_group_new
Member
hi
i want to send 346 file ( each file is 2016 byte ) to serial ( for update a device firmware )
i send first file and revice device request from serial for next file , then i send second file and ...
when i set baudrate to 38400 , my program work perfect , but its too slow ( about 4 min ) ..
when i change baudrate to 115200 , and set device baudrate to 115200 , all files not send to device perfect and after sending 200 files , the files send curropted .. and because device not recive correct data , not send request to next file... and its stop..
my arduino is 2560
my code is :
i want to send 346 file ( each file is 2016 byte ) to serial ( for update a device firmware )
i send first file and revice device request from serial for next file , then i send second file and ...
when i set baudrate to 38400 , my program work perfect , but its too slow ( about 4 min ) ..
when i change baudrate to 115200 , and set device baudrate to 115200 , all files not send to device perfect and after sending 200 files , the files send curropted .. and because device not recive correct data , not send request to next file... and its stop..
my arduino is 2560
my code is :
B4X:
#Region Project Attributes
#AutoFlushLogs: true
#StackBufferSize: 2000
#CheckArrayBounds: true
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private sd As SD
Private softserial As SoftwareSerial
Private astream As AsyncStreams
Private bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
softserial.Initialize(38400,11, 16)
astream.Initialize(softserial.Stream , "astream_newdata", "AStream_Error")
sd.Initialize(53)
End Sub
Sub astream_newdata (buffer1() As Byte)
Log("Recived Data : ",bc.HexFromBytes(buffer1))
Dim hh As String = bc.HexFromBytes(buffer1)
If hh.Length > 3 Then
send_to_serial (hh)
End If
End Sub
Sub send_to_serial (hh As String)
Dim file As String = get_file_name(hh)
If sd.OpenRead (file) = True Then
Dim cb (2061) As Byte
sd.Position =0
sd.Stream.ReadBytes(cb, 0, 2061)
astream.Write(cb)
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