Android Question Astream_NewData

Discussion in 'Android Questions' started by secilcemal, May 16, 2016.

  1. secilcemal

    secilcemal Member Licensed User

    Hi,
    I am working with B4a and with this library for some times, they are perfect tools for me to create a cnc marking machine.
    What i can not figure out is;
    For my application i send more than 1500 bytes to a micro controller.
    What i want to impliment is the reading process into a for loop that sends the data to micro controller.
    So after sending 500 byte it will wait the signal from microcontroller to go on.
    When i add the line "ReceivedByte = BytesToString(Buffer, 0, Buffer.Length, "UTF8")" into the for loop
    it gives me the error that "undeclared variable buffer is used before assigned any value".
    Would you please tell me the proper way to use it.
    Thanks.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You need to first send the 500 bytes and then send the next data from NewData event:
    Code:
    Sub Send500Bytes
       astream.Write(dataToSend)
    End Sub

    Sub AStream_NewData (Buffer() As Byte)
       
    'read buffer
       Send500Bytes
    End Sub
     
  3. secilcemal

    secilcemal Member Licensed User

    Hi,
    So i can't read the coming data while i am in a sub?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    No. Because you cannot read the data from the main thread.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice