something with AsyncStreams

icefairy333

Active Member
Licensed User
Longtime User
B4X:
@BA.ShortName("RandomAccessFile")
@BA.Version(1.3F)
there is something wrong with the function "AsyncStreams.write2":(
yesterday I have wrote a bluetooth communication app when I call write2 the other device can not receivedany message,But when I call write it works fine!Then I had to wrote a simply function to spilt the bytes
B4X:
Sub bytebuild(buf() As Byte,start As Int,length As Int) As Byte()
   Dim strTmp As String
   Dim bytes(0) As Byte
   If buf.length<length Then Return bytes
   strTmp=BytesToString(buf,start,length,"UTF-8")
   bytes=strTmp.GetBytes("UTF8")
   Return bytes
End Sub
and I have check the code of the AsyncStreams java
B4X:
public boolean Write(byte[] Buffer)
  {
    return Write2(Buffer, 0, Buffer.length);
  }

  public boolean Write2(byte[] Buffer, int Start, int Length)
  {
    return aout.put(Buffer, Start, Length);
  }
I found that the codes are the same ~:(:sign0161:
what's wrong with me? serial connect and listen by "connect and listen" the other code haven't be modify:(
 

icefairy333

Active Member
Licensed User
Longtime User
sadly!today I use the astream object like
B4X:
AStream.InitializePrefix(Main.serial1.InputStream,true, Main.serial1.OutputStream, "AStream")
when I pass the small file(example :1kb) it works fine ,but when i send a big file (for example 20kb),there are some probabilitys the file will be muddled.maybe I should use
AStream.InitializePrefix(Main.serial1.InputStream,false, Main.serial1.OutputStream, "AStream")
???:sign0085:
 
Top