Yayou49 Active Member Licensed User Dec 27, 2018 #1 Hi, I have a problem to read a string sent via HC05 to my B4A project. On HC05 side, I'm trying this: Code: HC05.println("toto"); On B4A side, BlueToothManager raised the event Code: Private Sub AStream_NewData (Buffer() As Byte) CallSub2(Clefs, "Receive", BytesToString(Buffer, 0, Buffer.Length, "UTF8")) End Sub For my tests, I've updated this sub as follow: Code: Private Sub AStream_NewData (Buffer() As Byte) j = j+1 Log(j) Log(BytesToString(Buffer, 0, Buffer.Length, "UTF8")) End Sub Where j (simple counter) starts from 0. In my example, logs are: 1 t 2 oto Click to expand... Even with a HC05.write or HC05.print, same result. AStream_NewData is raised 2 times. Astream is initialized as following: Code: AStream.Initialize(serial.InputStream, serial.OutputStream, "astream") Is there a particular setting or command to avoid this "cutting" ? Thanks in advance.
Hi, I have a problem to read a string sent via HC05 to my B4A project. On HC05 side, I'm trying this: Code: HC05.println("toto"); On B4A side, BlueToothManager raised the event Code: Private Sub AStream_NewData (Buffer() As Byte) CallSub2(Clefs, "Receive", BytesToString(Buffer, 0, Buffer.Length, "UTF8")) End Sub For my tests, I've updated this sub as follow: Code: Private Sub AStream_NewData (Buffer() As Byte) j = j+1 Log(j) Log(BytesToString(Buffer, 0, Buffer.Length, "UTF8")) End Sub Where j (simple counter) starts from 0. In my example, logs are: 1 t 2 oto Click to expand... Even with a HC05.write or HC05.print, same result. AStream_NewData is raised 2 times. Astream is initialized as following: Code: AStream.Initialize(serial.InputStream, serial.OutputStream, "astream") Is there a particular setting or command to avoid this "cutting" ? Thanks in advance.
tigrot Well-Known Member Licensed User Longtime User Dec 27, 2018 #2 Use a terminator char, since there is no way to void "cutting" strings via RS232. You have to reformat in a buffer till you get the char. Or use prefix modehttps://www.b4x.com/android/forum/threads/asyncstreams-prefix-mode.76645/ the hard work to reconstruct the string is done by the library Last edited: Dec 27, 2018 Upvote 0
Use a terminator char, since there is no way to void "cutting" strings via RS232. You have to reformat in a buffer till you get the char. Or use prefix modehttps://www.b4x.com/android/forum/threads/asyncstreams-prefix-mode.76645/ the hard work to reconstruct the string is done by the library