B4J Question Reading GSM modem crashes app

Discussion in 'B4J Questions' started by Beja, May 13, 2016.

  1. Beja

    Beja Expert Licensed User

    Hi all,
    I am using a GSM modem and a friend of mine is helping me with the solution... but he doesn't have the modem
    so he couldn't test it.. in my side, when I click the Read GSM button the system crashes or hangs for a very
    long time before telling it's not responding!!
    Please see the code below and I would appreciate any explanation!

    Code:
    Sub btnRead_Action
             
    'Read string from GSM modem
              Dim iStream As InputStream
              iStream = sp.GetInputStream
             
    Dim buffer() As Byte
             
    Dim count As Int = iStream.ReadBytes(buffer,0,buffer.Length)
             TextArea1.text = 
    BytesToString(buffer,0,buffer.Length,"UTF-8")
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    This is exactly why you need to use AsyncStreams. It will never hang your app. Your current code will hang the main thread until there is at least one byte available.
     
    Beja likes this.
  3. Beja

    Beja Expert Licensed User

    I tried to follow your previous advice to use getinputstream and never use asyncstreams.. will check this again and see what did I miss.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Sorry for the confusion. You always need to use AsyncStreams.
     
    Beja likes this.
  5. Beja

    Beja Expert Licensed User

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