I use softserial pin connect to rs232 device, when receive the buffer show not correct, but i write small B4J program to test, i receive all correct buffer. Which part of B4R got a problem?
B4J:
i receive correct buffer:
here is B4R code:
buffer not correct:
few month ago B4R didn't have this problem.
B4J:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Private serial1 As Serial
Private astream As AsyncStreams
Private t1 As Timer
Private bc As ByteConverter
End Sub
Sub AppStart (Args() As String)
serial1.Initialize("")
serial1.Open("com2")
serial1.SetParams(57600,8,1,0)
astream.Initialize(serial1.GetInputStream,serial1.GetOutputStream,"Astream")
t1.Initialize("t1",2000)
t1.Enabled=True
StartMessageLoop
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub t1_Tick
Dim b(16) As Byte
b(0)=0x02
b(1)=0x30
b(2)=0x33
b(3)=0x34
b(4)=0x36
b(5)=0x30
b(6)=0x37
b(7)=0x44
b(8)=0x45
b(9)=0x30
b(10)=0x30
b(11)=0x36
b(12)=0x34
b(13)=0x38
b(14)=0x39
b(15)=0x03
astream.Write(b)
End Sub
Sub Astream_NewData (Buffer() As Byte)
Log("Buffer Length: " & Buffer.Length & " Buffer: " & bc.HexFromBytes(Buffer))
End Sub
i receive correct buffer:
B4X:
Buffer Length: 65 Buffer: 0230333436303030303132373132303531323043303031413230303232353032313231363030303431303030303132353030303131363330303730303030454103
Buffer Length: 65 Buffer: 02303334363030303031323731343035313230433030314332303032B2353032313231363030303030303030303132353030303131363330303730303030454503
Buffer Length: 65 Buffer: 0230333436303030303932373136303531323043303031453230303232353032313231363030303030303030303132353030303131363330303730303030463203
Buffer Length: 65 Buffer: 0230333436303030303132373138303531323043303032303230303232353032313231363030303030303030303132353038323131363331303730303030453003
Buffer Length: 65 Buffer: 0230333436303030303132373141303531323043303032323230303232353032313231363030303030303030303132353030303131363330303730303830454203
Buffer Length: 65 Buffer: 023833343630B030303132373143303531323043303032343230303232B53032313231363030303030303030303132353030303131363330303730303030454603
Buffer Length: 65 Buffer: 0230333436303030303132373145303531323043303032363230303232353032313231363030303030303030303132353030303131363330303730303030463303
Buffer Length: 65 Buffer: 0230333436303030303132373230303531323043303032383230303232353032313231363030303030303030303132353030303131363330303730303030553103
Buffer Length: 65 Buffer: 023033343632303030313237323230353132304330303241323030323235303231323136303030303030303030313A353030303131363330303730303038454303
here is B4R code:
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 10000
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Public bc As ByteConverter
Private SoftSerial As SoftwareSerial
Private astream As AsyncStreams
Private m_t1 As Timer
End Sub
Private Sub AppStart
m_t1.Initialize("m_t1_Tick",2000) 'collect io data
m_t1.Enabled=False
Serial1.Initialize(57600)
SoftSerial.Initialize(57600,12,13) '6=rx 7=tx
astream.Initialize(SoftSerial.Stream, "astream_NewData", Null)
astream.MaxBufferSize=265
Log("AppStart")
m_t1.Enabled=True
End Sub
Sub m_t1_Tick
test
Delay(5)
End Sub
Sub test
'02 30 33 34 36 30 37 44 45 30 30 36 34 38 39 03
Dim b(16) As Byte
b(0)=0x02
b(1)=0x30
b(2)=0x33
b(3)=0x34
b(4)=0x36
b(5)=0x30
b(6)=0x37
b(7)=0x44
b(8)=0x45
b(9)=0x30
b(10)=0x30
b(11)=0x36
b(12)=0x34
b(13)=0x38
b(14)=0x39
b(15)=0x03
astream.Write(b)
Delay(9)
End Sub
Sub astream_NewData (buffer() As Byte)
Log("Buffer Length: ",buffer.Length," Buffer: ",bc.HexFromBytes(buffer))
End Sub
buffer not correct:
B4X:
Buffer Length: 41 Buffer: 200806D8D8104040402810B818C04028151020188500000C1A0144C00800D41010081008B020204020
Buffer Length: 42 Buffer: 40C40CB080402240200810B81808202885102018858006010D804430020035C400841088B04020004000
Buffer Length: 42 Buffer: 20C40CB080404040408810B818004543A80E000250026288B810880A06008003804007800C0C31C41020
Buffer Length: 41 Buffer: 40C40CB080402040200810B840084038150020182120400800084483004003004006800C0C0204C020
Buffer Length: 41 Buffer: 400806D0C0200020400800B820184000150020188500000C5400806004006A1000C410088040202000
Buffer Length: 41 Buffer: 2011186080204040200800B840A82000151020188500000C430011010000A840100810088020402000
Buffer Length: 41 Buffer: 400806D8D8202040200810B820B8000015002018850000802880A26000006A100884100880404020C0
few month ago B4R didn't have this problem.