Android Question String does not update in Sub astreams_NewData

Discussion in 'Android Questions' started by Jack Howard, Feb 8, 2018.

  1. Jack Howard

    Jack Howard Member Licensed User

    I am having trouble tracking errors in a class.

    One sub will update a string but Sub astreams_NewData does not.

    Any ideas!


    Code:
    'Class module

    Public Sub Change_String
           Main.Main_Error =
    "This changes string"
    End Sub

    Public Sub astreams_NewData (Buffer() As Byte)
           Main.Main_Error =
    "Never Changes string"
    End Sub




    'Main

    Sub Process_Globals
    Dim Main_Error As String="NothingYet"
    End Sub

    Sub AStream_NewData (RX_Buffer() As Byte)
        
    Msgbox (Main_Error,"")'doesent change Main_Error   
    UAstreams.Change_String
        
    Msgbox (Main_Error,"")'does change Main_Error
    End Sub
     
    Last edited: Feb 8, 2018
  2. DonManfred

    DonManfred Expert Licensed User

    Please use [CODE]code here...[/CODE] tags when posting code.

    [​IMG]
    [​IMG]
    [​IMG]
     
  3. OliverA

    OliverA Well-Known Member Licensed User

    How do you know that your astreams_NewData of your class module is even called? If it is not called, it will not change the string.
     
  4. Jack Howard

    Jack Howard Member Licensed User

    Hi Oliver,

    Thank you for looking at the issue for me.

    I know it is called because I can read data, also in AStream_NewData the message box pops up which can only be triggered from astreams_NewData. Its strange that I created Public Sub Change_String to test the issue and that does update.Oddly after I created my post, in similar threads above I see https://www.b4x.com/android/forum/t...eams-in-two-activity-modules.16575/#post96741 and maybe that could be the same issue with a workaround.

    I really want to get the latest error from Sub astreams_Error as this has the same issue, but its not so easy to test.
     
    Last edited: Feb 8, 2018
  5. OliverA

    OliverA Well-Known Member Licensed User

    Nowhere in your initial post do you mention nor show that the AStream_NewData sub that is located in you Main module is called from your astreams_NewData sub located in your class. From your initial post, I don't see nor are you showing us (via logs/pop ups, etc.) that astreams_NewData is actually called. Just from that little bit that you are posting, one would gather that you opened an AsyncStream in Main and initialized it with "AStream" as the prefix for the callback subs and you created another AsyncStream in you class that has "astreams" configured as the prefix for you callback subs. Nowhere though do you show us where / how you are initializing your AsyncStreams, so I'm even guessing that you named you prefixes such without accidentally misspelling them.
    What is not easy to test? You can always use log() to log anything and everything, especially if you are not sure if a certain code path even gets executed/called.
     
    KMatle likes this.
  6. Jack Howard

    Jack Howard Member Licensed User

    Hi Oliver,

    You are right, I have not explained the situation well. I am connecting to SDR Radio hardware using TCP which has a fast data rate up to 1Myte per second.

    I have started with a Erel TCP example. I can connect to the hardware, and I get data coming through that I can decode using...

    data via Sub AStream_NewData
    Termination via Sub astreams_Terminated
    Errors via Sub astreams_Error

    I tried to modify
    Code:
    Private Sub astreams_Error
     astreams.Close
     CallSubDelayed(mTarget, mEventName & 
    "_Error")
    End Sub
    to

    Code:
    Private Sub astreams_Error
     astreams.Close
     CallSubDelayed2(mTarget, mEventName & 
    "_Error",LastException.Message)
    End Sub
    For some reason that did not work, so I then tried just catching the error in a string

    That's when I noticed I could pass a string from "Class Module" to "main" using my own sub in the class module



    But not with

    Code:
    Sub AStream_NewData
    Sub astreams_Terminated
    Sub astreams_Error
    that were in the same module

    The reason I am using a sub rather than Logs is I want my code to take action based on what the error's are.

    Again I apologise for not explaining in detail from the outset, and I really appreciate your help.
     
  7. OliverA

    OliverA Well-Known Member Licensed User

    Link?
     
  8. Jack Howard

    Jack Howard Member Licensed User

    I used the
    https://www.b4x.com/android/forum/threads/b4x-asyncstreams-tutorial.7669/

    Then I modified it to
    be a client rather than a server
    Use normal mode instead of prefix (astream.Initialize(TCP_Socket.InputStream, TCP_Socket.OutputStream, "AStream"))

    Maybe I could remove all my irrelevant code and post the complete basic code showing the error!
     
    OliverA likes this.
  9. OliverA

    OliverA Well-Known Member Licensed User

    Yes!
     
  10. Jack Howard

    Jack Howard Member Licensed User

    Hi Oliver,

    I am a step closer.

    From what I can see, in class
    Code:
    Private Sub astreams_Error
     
    'Dim MyERR As String=LastException.Message
          'Log(LastException.Message)
       'Log("astreams_Error")
     astreams.Close
     CallSubDelayed(mTarget, mEventName & 
    "_Error")
    End Sub
    does not call the Log or set the variable

    But as it does call "Main" Sub astream_Error

    The last error still seems to be in LastException.Message when the routine is exited

    So I think I can use in main

    Code:
    Sub astream_Error
     Is_Client_Connected = 
    False

    If LastException.IsInitialized =True Then
           Connected_Label.Text =
    "astream_Error=" & LastException.Message
    Else
      Connected_Label.Text =
    "astream_Error=Unknown"
    End If
     Connected_Label.Color=
    Colors.red
    End Sub
    Thanks for helping.
     
  11. OliverA

    OliverA Well-Known Member Licensed User

    Huh? It should. Now you are declaring a local variable (local to the astreams_Error sub), but there should be no reason for the variable not to be set. As to logging, if you are using the B4A-Bridge, log output will only be displayed in debug mode.
     
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