Android Question String does not update in Sub astreams_NewData

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!


B4X:
'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:

OliverA

Expert
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.
 

Jack Howard

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.
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:

OliverA

Expert
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.
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.
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.
 

Jack Howard

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.
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
B4X:
Private Sub astreams_Error
 astreams.Close
 CallSubDelayed(mTarget, mEventName & "_Error")
End Sub
to

B4X:
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

B4X:
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.
 

OliverA

Expert
Licensed User

OliverA

Expert
Licensed User

Jack Howard

Member
Licensed User
Hi Oliver,

I am a step closer.

From what I can see, in class
B4X:
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

B4X:
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.
 

OliverA

Expert
Licensed User
does not call the Log or set the variable
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.
 
Top