H HARRY Active Member Licensed User Longtime User Mar 8, 2017 #1 I have a project with several activities. The main activity, called Main takes care of a.o. asyncstreamtext. Sending is done as follows Code: Copy Public Sub Send (Mess As String) If Stream1.IsInitialized = False Then Stream1.Initialize(Me,"Stream1",Client1.InputStream,Client1.OutputStream) 'to Raspberry Stream1.Write(Mess&CRLF) End Sub Another activity also has to send some data.I tried to do so, based on sampl code which I do not completely understand, as follows: Code: Copy Sub sendrequest(text As String) Dim request As Object= text Dim jo As JavaObject =request CallSub2(Main,"send",jo) End Sub
I have a project with several activities. The main activity, called Main takes care of a.o. asyncstreamtext. Sending is done as follows Code: Copy Public Sub Send (Mess As String) If Stream1.IsInitialized = False Then Stream1.Initialize(Me,"Stream1",Client1.InputStream,Client1.OutputStream) 'to Raspberry Stream1.Write(Mess&CRLF) End Sub Another activity also has to send some data.I tried to do so, based on sampl code which I do not completely understand, as follows: Code: Copy Sub sendrequest(text As String) Dim request As Object= text Dim jo As JavaObject =request CallSub2(Main,"send",jo) End Sub
DonManfred Expert Licensed User Longtime User Mar 8, 2017 #2 If you are in activityX then you cannot start a sub in main activity (it is paused!) Use CallSubDelayed to start main activity and the sub. Better use a service to do all the asyncstream-things... Call the sub in the service then. Upvote 0
If you are in activityX then you cannot start a sub in main activity (it is paused!) Use CallSubDelayed to start main activity and the sub. Better use a service to do all the asyncstream-things... Call the sub in the service then.
Erel B4X founder Staff member Licensed User Longtime User Mar 9, 2017 #3 DonManfred said: Better use a service to do all the asyncstream-things... Call the sub in the service then. Click to expand... +1 Upvote 0
DonManfred said: Better use a service to do all the asyncstream-things... Call the sub in the service then. Click to expand... +1
H HARRY Active Member Licensed User Longtime User Mar 9, 2017 #4 Thanks Erel and DonManfred! I moved everything about asyncstreams to a Service module. But I still have problems to get the information I want to send correctly sent to the other side. In the main module eg. I write: Code: Copy mcode=15 Dim request As Object= mcode & s 'two variables, s="|" Dim jo As JavaObject =request CallSub2(StreamService,"send",jo) This gives java errors. I tried several other formats; some really send information, but the receiving side then get the text "String 15|" The service module has the code: Code: Copy Public Sub Send (Mess As String) If Stream1.IsInitialized = False Then Stream1.Initialize(Me,"Stream1",Client1.InputStream,Client1.OutputStream) 'to Raspberry Stream1.Write(Mess&CRLF) End Sub Could somebody correct these small pieces of code! Please. Harry Upvote 0
Thanks Erel and DonManfred! I moved everything about asyncstreams to a Service module. But I still have problems to get the information I want to send correctly sent to the other side. In the main module eg. I write: Code: Copy mcode=15 Dim request As Object= mcode & s 'two variables, s="|" Dim jo As JavaObject =request CallSub2(StreamService,"send",jo) This gives java errors. I tried several other formats; some really send information, but the receiving side then get the text "String 15|" The service module has the code: Code: Copy Public Sub Send (Mess As String) If Stream1.IsInitialized = False Then Stream1.Initialize(Me,"Stream1",Client1.InputStream,Client1.OutputStream) 'to Raspberry Stream1.Write(Mess&CRLF) End Sub Could somebody correct these small pieces of code! Please. Harry
Erel B4X founder Staff member Licensed User Longtime User Mar 10, 2017 #5 Are you using B4J to program the RPi? If so then you should initialize it in prefix mode and use B4XSerializator to create the messages. Upvote 0
Are you using B4J to program the RPi? If so then you should initialize it in prefix mode and use B4XSerializator to create the messages.